【问题标题】:Handling multiple dialogs in Microsoft bot framework在 Microsoft bot 框架中处理多个对话框
【发布时间】:2016-05-11 17:20:28
【问题描述】:

我正在使用 Microsoft bot 框架创建一个机器人,该机器人将接收餐厅的订单,我想知道如何处理多个对话,例如客户下了第一个订单,然后我希望机器人问你还想要别的吗?然后客户说是/否,如果是,则再次重复相同的对话并保持第一个对话的状态,我现在在文档中看到的只是一个对话和一个对话。

非常感谢

【问题讨论】:

    标签: botframework


    【解决方案1】:

    要管理多个对话框,您需要使用Dialog Chains。您可以显式管理对话框堆栈 (using Call/Done),也可以使用 Chain fluent 方法隐式管理。 Here 是如何使用它的示例。

    如果用户可以选择的一组内容已经预定义,那么我建议使用FormFlowPizzaSandwich 示例很好地说明了如何使用一组预定义的选项来处理订单。

    【讨论】:

    【解决方案2】:

    在 Microsoft Bot Framework V4 版本中,FormFlow 需要替换为 Waterfall Dialog。在这里,我们可以使用 stepContext.Values(字典)来跨瀑布步骤维护状态,并向用户显示是或否响应的选择提示,然后在是响应的情况下重复瀑布对话框,否则在最后一个瀑布步骤中结束对话框。

    在基础Component dialog 的构造函数中添加瀑布下方,并根据用户选择重复瀑布。

    WaterfallStep[] myWaterfallDialog = new WaterfallStep[]
    { 
        this.waterfallStepToGetUserOrder,
        .......
        this.promptUserForChoiceStep,
        this.EndDialogStep
    }
    AddDialog(new WaterfallDialog("mydialog", myWaterfallDialog);
    

    【讨论】:

      【解决方案3】:

      以上答案很好,但我注意到提供的某些链接不再有效。这是我设法在不同对话框之间导航的方法

          public MakeChoiceDialog() : base (nameof(MakeChoiceDialog))
          {
              AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
              AddDialog(new LoginDialog());
              AddDialog(new SignUpDialog());
      
              AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
                  {
                      LoginStepAsync,
                      LoginSignUpStepAsync,
                      //Other Steps here
                  }));
      
              InitialDialogId = nameof(WaterfallDialog);
          }
      

      方法调用将是

          private async Task<DialogTurnResult> LoginSignUpStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
          {
              string userChoice = ((FoundChoice)stepContext.Result).Value;
              var msg = string.Empty;
              switch (userChoice)//You can use if statement here
              {
                  case "Login":
                      return await stepContext.BeginDialogAsync(nameof(LoginDialog), null, cancellationToken);
                  default:                  
                    return await stepContext.BeginDialogAsync(nameof(SignUpDialog), null, cancellationToken);
              }
              return await stepContext.EndDialogAsync(null, cancellationToken);
          }
      

      Startup.cs 中添加以下内容

      services.AddSingleton<LoginDialog>();
      services.AddSingleton<SignUpDialog>();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-19
        相关资源
        最近更新 更多