繁体   English   中英

Bot Framework:将 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 调用访问相同的 DialogContext。

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

BotCallbackHandler方法中构造如下编码的DialogContext时,我可以使用它来使用BeginDialogAsync启动一个新的 Dialog。 但是,我错过了堆栈上现有的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();
}

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM