【问题标题】:Unable to use CancelAllDialogsAsync method in Onturnasync method无法在 Onturnasync 方法中使用 CancelAllDialogsAsync 方法
【发布时间】:2020-01-27 07:50:21
【问题描述】:

我使用 c# 使用框架 v4 制作了机器人。我在其中集成了 luis 以实现退出功能,在我的机器人中,当用户键入 exit 时,它会将您从对话中带出,整个机器人将从存在开始。我的案例机器人能够退出但无法从存在开始。我以为我可以使用 CancelallDialogAsync 方法,但我无法在我为退出功能编写代码的 onturnasync 方法中访问它。

public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
    {
        var activity = turnContext.Activity;
       // var activity = turnContext.Activity;
        var recognizerResult = await _botServices.Dispatch.RecognizeAsync(turnContext, cancellationToken);

        // Top intent tell us which cognitive service to use.
        var topIntent = recognizerResult.GetTopScoringIntent();

        var attachments = new List<Attachment>();
        var reply = MessageFactory.Attachment(attachments);
        reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;


        // First, we use the dispatch model to determine which cognitive service (LUIS or QnA) to use.

        if (string.IsNullOrWhiteSpace(activity.Text) && activity.Value != null)
        {
            activity.Text = JsonConvert.SerializeObject(activity.Value);
        }
        if (turnContext.Activity.Text == "Yes")
        {

            await turnContext.SendActivityAsync($"Good bye. I will be here if you need me. ", cancellationToken: cancellationToken);
            await turnContext.SendActivityAsync($"Say Hi to wake me up.", cancellationToken: cancellationToken);
        }
        else  if (topIntent.intent == "OrderStatusintent")
            {
                reply.Attachments.Add(Cards.GetHeroCard6().ToAttachment());
                await turnContext.SendActivityAsync(reply, cancellationToken);
            }
        else if (topIntent.intent == "Exitintent")
        {
            await turnContext.SendActivityAsync($"Good bye. Say Hi if you need more help.", cancellationToken: cancellationToken);

        }

        else if (activity.ChannelId != "webchat")
        {
            await base.OnTurnAsync(turnContext, cancellationToken);
        }
        await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
        await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
    }

【问题讨论】:

  • 我没有这样做,但听起来你可以使用主动消息传递和基于计时器的功能来实现这一点。有人可能有他们为此使用的模板,但如果您可以尝试解决方案,然后让我们知道您在实施该解决方案时遇到了什么困难,那么您将更有幸获得回复。

标签: c# asp.net botframework azure-language-understanding qnamaker


【解决方案1】:

我有点难以理解您的机器人功能,但我相信您需要一个 dialog 上下文。我的机器人结构与你的不同,但我有一个 onMessage 函数,它调用我的意图调度程序并传递 turnContext。我正在使用 DialogSet(来自 botbuilder-dialogs)通过(nodejs)创建对话上下文

this.dialogs = new DialogSet(this.dialogState) // in constructor

const dc = await this.dialogs.createContext(turnContext) // in function called from onMessage

await dc.cancelAllDialogs(); // from wherever I want to cancel

我没有看到您创建对话上下文的任何地方,因此这可能是您无法从 onTurn 处理程序调用此方法的原因。这可能是可能的,但是无论我在哪里调用cancelAllDialogs(),它都来自此对话框上下文,或者来自瀑布对话框中,我正在使用步骤上下文并通过stepContext.parent.cancelAllDialogs() 在父级别取消。

【讨论】:

  • 嗨,我无法在 onturnasync 方法上使用它……他们有什么办法吗? @billoverton
  • 我不确定,我只是从 onMessage 获得了成功
猜你喜欢
  • 2021-11-03
  • 2019-03-17
  • 2020-04-29
  • 2020-02-10
  • 1970-01-01
  • 1970-01-01
  • 2018-02-10
  • 2016-08-05
  • 1970-01-01
相关资源
最近更新 更多