【问题标题】:How to call a waterfall dialog in a Dialog - Azure Bot builder如何在对话框中调用瀑布对话框 - Azure Bot builder
【发布时间】:2020-01-25 02:05:20
【问题描述】:

在我的 azure 机器人中,我有默认机器人“DialogBot.cs”。在其 OnMessageActivityAsync() 方法中,我想根据用户输入调用特定的瀑布。

然而,一旦我解析了输入,我就不知道如何触发特定的瀑布。假设瀑布被称为“SpecificDialog”。我试过这个:

await Dialog.RunAsync(turnContext, ConversationState.CreateProperty<DialogState>(nameof(SpecificDialog)), cancellationToken);

但这不起作用。我将如何做到这一点?

【问题讨论】:

  • 你能用我的回答来解决这个问题吗?如果是这样,请“接受”并投票,以便其他人可以快速找到答案,我可以从我的支持跟踪器中清除它。如果没有,请告诉我我还能提供哪些帮助!
  • 我为延误道歉!是的,你的回答很棒。我投了赞成票,但不幸的是没有足够的声誉来展示它。希望您仍然可以从您的支持跟踪器中清除此问题!
  • 没问题!只是想确保您获得所需的所有帮助!

标签: c# azure azure-bot-service


【解决方案1】:

我假设您正在使用其中一个示例。我的答案将基于CoreBot

您应该将Dialog.RunAsync() 调用的对话框视为“根”或“父”对话框,所有其他对话框都从该对话框分支和流出。要更改由此调用的对话框,请查看Startup.cs for a line that looks like this

// Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
services.AddTransient<IBot, DialogAndWelcomeBot<MainDialog>>();

要将其更改为MainDialog 以外的对话框,只需将其替换为适当的对话框即可。

一旦你在你的根或父对话框中,你call another dialog with BeginDialogAsync()

stepContext.BeginDialogAsync(nameof(BookingDialog), new BookingDetails(), cancellationToken);

仅供参考:

这在 Node.js 中的工作方式略有不同。在 CoreBot 中,the MainDialog is passed to the bot in index.js

const dialog = new MainDialog(luisRecognizer, bookingDialog);
const bot = new DialogAndWelcomeBot(conversationState, userState, dialog);

[...]

// Listen for incoming activities and route them to your bot main dialog.
server.post('/api/messages', (req, res) => {
    // Route received a request to adapter for processing
    adapter.processActivity(req, res, async (turnContext) => {
        // route to bot activity handler.
        await bot.run(turnContext);

你可以看到它调用了DialogAndWelcomeBot,它扩展了DialogBotwhich calls MainDialog on every message

this.onMessage(async (context, next) => {
    console.log('Running dialog with Message Activity.');

    // Run the Dialog with the new message Activity.
    await this.dialog.run(context, this.dialogState);

    // By calling next() you ensure that the next BotHandler is run.
    await next();
    });

您没有必须以这种方式设置您的机器人,但这是目前推荐的设计,如果您遵循这一点,您将更容易实施我们的文档和示例。

【讨论】:

  • 为了澄清这一点,如果我使用根对话框,当没有其他对话框正在进行时,它会默认运行吗?我目前只是在我的 bot.js 文件中启动对话框(基于 LUIS 意图)。
  • @billoverton 是和否。我在答案中添加了描述。应该澄清一些事情。
猜你喜欢
  • 1970-01-01
  • 2019-10-11
  • 1970-01-01
  • 2019-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多