Bot Framework:将DialogContext传递给ContinueConversationAsync回调方法 [英] Bot Framework: Pass DialogContext to ContinueConversationAsync Callback method

查看:81
本文介绍了Bot Framework:将DialogContext传递给ContinueConversationAsync回调方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将DialogContext传递给ContinueConversationAsync BotCallbackHandler方法的方法.

I'm looking for a way to pass the DialogContext to the ContinueConversationAsync BotCallbackHandler method.

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

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]).

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

我正在尝试使用ContinueConversationAsync BotCallbackHandler方法通过API调用访问相同 DialogContext.

I am trying to access the same DialogContext from an API call using the ContinueConversationAsync BotCallbackHandler method.

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

在按BotCallbackHandler方法中的以下代码构造DialogContext时,我可以使用它使用BeginDialogAsync启动新的对话框.但是,我在堆栈上缺少 existing childDialog,它指示了bot的当前上下文.我总是获得堆栈上的rootDialog [0],而不是我的机器人当前正在处理的childDialog.

When constructing a DialogContext as coded below in the BotCallbackHandler method, I can use it to start a new Dialog using BeginDialogAsync. However, I am missing the existing childDialog on the stack which indicates the bot's current context. I am always getting only the rootDialog[0] on the stack, but not the childDialog which my bot is currently processing.

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?

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. How can I retrieve this DialogContext in the CallBack method?

推荐答案

您的案例听起来像是使用

Your case sounds like a good opportunity to use ActivityPrompt. It's an abstract class so you'll have to derive from it. 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.

这篇关于Bot Framework:将DialogContext传递给ContinueConversationAsync回调方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆