node.js - 如何将触发操作中的对话框与提示分开 (Microsoft Botbuilder SDK)

标签 node.js botframework

注意

我正在使用 ES6 babel 在 node.js 中使用 Microsoft Botbuilder SDK。

问题

我有一个对话框“/MainMenu”,它提示用户进行自由回复,以便进入另一个更相关的对话框。然而,我也希望用户能够触发一个与主题完全无关的操作(即询问机器人“你好吗?”的对话框),返回到原始的 MainMenu 对话框就像他们离开时一样。我知道在 SDK 的文档中,onSelectAction 可用于将触发的对话框放在堆栈顶部而不是替换整个堆栈,但是一旦“/HowAreYou”对话框结束,机器人也会认为该响应是对于初始的 MainMenu 提示,回复“我不明白。请重试”,如下所示:

Bot dialog screenshot

代码

// I am using the builder.Library routing standard, and have confirmed that     
// this gets triggered as expected. this dialog exists in a different file
lib.dialog('/HowAreYou', [
    (session, args, next) => {
        session.send('I\'m doing well. Thanks for asking!');
        builder.Prompts.text(session, 'How are you doing today?');
    }, (session, results) => {
        session.endDialog('Good to hear that!');
    }
]).triggerAction({
    matches: /^how are you?$/i,
    onSelectAction: (session, args, next) => {
        // Add the help dialog to the top of the dialog stack (override the    
        // default behavior of replacing the stack)
        session.beginDialog(args.action, args);
    }
});

bot.dialog('mainMenu', [
    (session, args, next) => {
        builder.Prompts.text(session, 'Hi there! What can I do for you today?');
    },
    (session, results) => {
        session.endConversation('Goodbye!');
    }
]).beginDialogAction('weatherAction', '/Weather', {
    matches: /^weather$/i,
}).beginDialogAction('sportsAction', '/Sports', {
    matches: /^sports$/i,
}).beginDialogAction('cookingAction', '/Cooking', {
    matches: /^cooking$/i,
});

期望的行为

虽然当前的结果非常接近所需的行为,但我理想情况下希望机器人在 HowAreYou 对话框结束后以与开始时相同的 MainMenu 提示进行回复,不要说它不理解

问题

这可能吗?如果是这样,怎么办?如果没有,有什么替代方案?

感谢您提供的任何帮助。

最佳答案

GitHub 上有一个解释:https://github.com/Microsoft/BotBuilder/issues/2421 ,我们可以意识到提示是内置对话框,它将处理输入验证

当您第一次进入 mainMenu 中的“提示”对话框时,当第一个“提示”对话框等待输入文本时,您会触发 HowAreYou 对话框。
然后 HowAreYousession.endDialog('Good to learn that!'); 结尾,而 mainMenu 中的第一个 Prompts 对话框没有结果,验证失败。

根本原因应该相当于为 builder.Prompts.text(session, 'Hi There! What can I do for you Today?'); 输入一个空文本。

更新

找到promptAfterAction提示对话框的 IPromptOptions 属性,我正在考虑这个问题。我认为这应该是设计使然。

由于句子我不明白...是属性retryPrompt的默认文本。因此,当您结束 HowAreYou 对话框并返回 mainPage 对话框堆栈时。提示对话框将重新启动并向用户发送 retryPrompt,这会引发您的问题。

对于辅助功能,您可以尝试使用:

builder.Prompts.text(session, 'Hi there! What can I do for you today?', {
            retryPrompt: 'Hi there! What can I do for you today?'
        });

关于node.js - 如何将触发操作中的对话框与提示分开 (Microsoft Botbuilder SDK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48795036/

相关文章:

javascript - 使用 express.js 打开 HTML 文件

css - 如何使用UnCSS

azure - Microsoft 基础结构当前的 OAuth URL 和范围是什么?

javascript - Realm 不会在 React native 上返回异常

ios - 服务器端如何将来自同一手机的 2 个不同请求解释为具有 2 个不同的 IP?

azure - 使用 Azure Bot 服务在 MS Teams 中以线程响应形式回复消息

javascript - 我怎样才能让机器人工作?

node.js - MS Bot 框架 v4 - 无法将 QnA 生成器添加到机器人 - 主机名加密值不是有效格式

node.js - 可以使用 Node.js 构建 FormFlow 对话框吗?

javascript - 如何使用 sequelize.js 将表的列设置为外键