将对话框添加到堆栈

Adding a Dialog to the stack

我有一个简单的机器人来监听 facebook 事件触发器(不是消息) 当它获得触发器时,它应该启动一个新的对话框(RegisterPledgeDialog)并将其压入堆栈。但是我不知道怎么办?

public class DialogBot<T> : ActivityHandler where T : Dialog

protected override async Task OnEventAsync(ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken)
{
       // How do i start a new Dialog and push it to the top of an exiting dialog stack?
       // The code below is what I tried. It starts the new Dialog but doesn't return to it after the turn

       var set = new DialogSet();
       set.Add(_pledgeDialog);
       DialogContext dc = new DialogContext(set , turnContext, new DialogState());
       await dc.BeginDialogAsync(nameof(RegisterPledgeDialog), null, cancellationToken);

}

protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
      Logger.LogInformation("Running dialog with Message Activity.");  
      await Dialog.RunAsync(turnContext, _conversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);          
}

两件事:

  1. 它没有 return 对话框的原因是因为 OnMessageActivity 在用户响应时被触发,并且在你的主对话框上调用 Dialog.RunAsync .

  2. 无法将对话框t/shouldn动态添加到机器人中。它们必须添加到构造函数中,然后用 BeginDialogAsync().

  3. 调用

我推荐:

  1. 了解如何 CoreBot implements its dialogs, particularly the CancelAndHelp Dialog, which handles interruptions. See how BookingDialog extends CancelAndHelpDialog so that every time BookingDialog is called, CancelAndHelpDialog checks to see if it needs to interrupt
  2. 在您的 ActivityHandler 中,调用正常的 Dialog.Run,而不是 BeginDialog
  3. 创建一个处理中断and/or事件的对话框;它应该分析 turnContext,如果它看到 Activity.Type === ActivityTypes.Event(以及您需要的任何其他条件),则 然后 它调用 BeginDialog。请务必在此对话框的构造函数中使用 AddDialog