[英]Bot Framework: Pass DialogContext to ContinueConversationAsync Callback method
I'm looking for a way to pass the DialogContext
to the ContinueConversationAsync
BotCallbackHandler
method.我正在寻找一种将
DialogContext
传递给ContinueConversationAsync
BotCallbackHandler
方法的方法。
For example, when I am inside a childDialog, the DialogContext dc
in the ContinueDialogAsync
method of the childDialog shows correctly 2 dialogs on the stack (childDialog[0] + rootDialog[1]).例如,当我在 childDialog 中时,childDialog 的
ContinueDialogAsync
方法中的DialogContext dc
正确显示堆栈上的 2 个对话框(childDialog[0] + rootDialog[1])。
public override async Task<DialogTurnResult> ContinueDialogAsync(DialogContext dc, CancellationToken cancellationToken = default)
I am trying to access the same DialogContext from an API call using the ContinueConversationAsync
BotCallbackHandler
method.我正在尝试使用
ContinueConversationAsync
BotCallbackHandler
方法从 API 调用访问相同的 DialogContext。
await ((BotAdapter)_adapter).ContinueConversationAsync(_appId, conversationReference, BotCallback, default(CancellationToken));
When constructing a DialogContext
as coded below in the BotCallbackHandler
method, I can use it to start a new Dialog using BeginDialogAsync
.在
BotCallbackHandler
方法中构造如下编码的DialogContext
时,我可以使用它来使用BeginDialogAsync
启动一个新的 Dialog。 However, I am missing the existing childDialog on the stack which indicates the bot's current context.但是,我错过了堆栈上现有的childDialog,它指示了机器人的当前上下文。 I am always getting only the rootDialog[0] on the stack, but not the childDialog which my bot is currently processing.
我总是在堆栈上只得到 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();
}
My goal is to be able to end the active childDialog which is the highest up the stack, to bring back the conversation to the parent dialog.我的目标是能够结束堆栈中最高的活动 childDialog,将对话带回父对话框。 How can I retrieve this DialogContext in the CallBack method?
如何在 CallBack 方法中检索此 DialogContext?
Your case sounds like a good opportunity to use ActivityPrompt
.您的案例听起来像是使用
ActivityPrompt
的好机会。 It's an abstract class so you'll have to derive from it.这是一个抽象的 class 所以你必须从中派生。 The idea is that prompts already have "retry prompts" built into them, which means the dialog will keep telling the user that it's waiting for one specific thing when the user tries to talk to the bot.
这个想法是提示已经内置了“重试提示”,这意味着当用户尝试与机器人交谈时,对话框将不断告诉用户它正在等待一件特定的事情。 In your case, the prompt could waiting for a special activity that only gets sent to your bot when the long-running process ends.
在您的情况下,提示可能会等待仅在长时间运行的过程结束时才会发送到您的机器人的特殊活动。 This may be more intuitive than trying to manually end the dialog from outside of it.
这可能比尝试从外部手动结束对话更直观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.