Bot 框架:将 DialogContext 传递给 ContinueConversationAsync 回调方法

Bot Framework: Pass DialogContext to ContinueConversationAsync Callback method

我正在寻找将 DialogContext 传递给 ContinueConversationAsync BotCallbackHandler 方法的方法。

例如,当我在 childDialog 中时,childDialog 的 ContinueDialogAsync 方法中的 DialogContext dc 在堆栈上正确显示了 2 个对话框 (childDialog[0] + rootDialog[1]) .

public override async Task<DialogTurnResult> ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default)

我正在尝试使用 ContinueConversationAsync BotCallbackHandler 方法从 API 调用访问 same DialogContext。

await ((BotAdapter)_adapter).ContinueConversationAsync(_appId, conversationReference, BotCallback, default(CancellationToken));

当在 BotCallbackHandler 方法中构建如下编码的 DialogContext 时,我可以使用它来启动一个使用 BeginDialogAsync 的新对话框。但是,我在堆栈上缺少 existing childDialog,它指示机器人的当前上下文。我总是 只有 堆栈上的 rootDialog[0],而不是我的机器人当前正在处理的 childDialog。

private async Task BotCallback(ITurnContext turnContext, CancellationToken cancellationToken)
{
   var conversationStateAccessors = conversationState.CreateProperty<DialogState>(nameof(DialogState));
   var dialogSet = new DialogSet(conversationStateAccessors);
   Dialog rootDialog Dialog = new RootDialog();
   dialogSet.Add(rootDialog);
   Dialog childDialog = new ChildDialog();
   dialogSet.Add(childDialog);
   var dialogContext = await dialogSet.CreateContextAsync(turnContext, cancellationToken);

   //end the most recent dialog on the stack, which should bring the conversation back to the parent root dialog
   var results = await dialogContext.EndDialogAsync();
}

我的目标是能够结束堆栈最高处的活动子对话框,将对话带回父对话框。如何在 CallBack 方法中检索此 DialogContext?

您的案例听起来是使用 ActivityPrompt 的好机会。它是一个抽象 class 所以你必须从它派生。这个想法是提示已经内置了“重试提示”,这意味着当用户尝试与机器人交谈时,对话框将不断告诉用户它正在等待一件特定的事情。在您的情况下,提示可能会等待一个特殊的 activity,它只会在 long-运行 进程结束时发送给您的机器人。这可能比尝试从外部手动结束对话更直观。