node.js - 如何自定义提示选择 (Microsoft Botbuilder SDK)

标签 node.js botframework

注意

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

问题

基于这篇有用的 StackOverflow 帖子,https://stackoverflow.com/a/45597651/3304185 ,我试图以同样的方式修改 builder.Prompts.choice 的行为,以更好地控制重试提示,而不是默认为“我不明白”。但是,当我尝试遵循此实现模式并将其应用于 builder.Prompts.choice 时,我只是得到机器人发送的 undefined 选项,如下所示:

Screenshot of Undefined Choices

代码

// snippet showing how I call the choice function, where
// welcome_subtitle is a string, and menuOptions is an array of strings
builder.Prompts.choice(session, welcome_subtitle, menuOptions, {
    listStyle: builder.ListStyle.button
});

builder.Prompts.choice = (session, prompt, choices, options) => {
    let args = options || {};
    args.prompt = prompt || args.prompt;
    args.choices = choices || args.choices;

    args.retryPrompt = args.retryPrompt || args.prompt;
    session.beginDialog('BotBuilder:prompt-choice', args);
}

期望的行为

如果我只是将args.choice初始化为choices ||,我就会期望出现这些选择args.choices,但这似乎并不是全部必要的。

感谢您提供的任何帮助。

最佳答案

在这种情况下,传递字符串数组将不起作用,因为提示似乎需要 IChoice 的列表。 .

builder.Prompts.choice = (session, prompt, choices, options) => {
    let args = options || {};
    args.prompt = prompt || args.prompt;
    args.choices = choices || args.choices;

    args.retryPrompt = args.retryPrompt || args.prompt;
    console.log(args);
    session.beginDialog('BotBuilder:prompt-choice', args);
}

bot.dialog('/', [
    (session, args) => {
        welcome_subtitle = 'Hello Stack Overflow!';
        menuOptions = [{value: '1st Choice'}, {value: '2nd Choice'}, '3rd Choice', '4th Choice'];
        builder.Prompts.choice(session, welcome_subtitle, menuOptions, {
            listStyle: builder.ListStyle.button
        });
    },
    (session, results) => {
        session.endDialog();
    }
]);

下面是 builder.Prompts.choice 内的 console.log(args) 的屏幕截图,模拟器正确显示了前两个选择,但没有显示后两个:

enter image description here

关于node.js - 如何自定义提示选择 (Microsoft Botbuilder SDK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48893767/

相关文章:

node.js - 如何在不同 Node 之间持久保存对话数据?

azure - 为 Azure Bot 服务设置插槽或多个环境

node.js - 命名空间 'Express' 没有导出成员 'SessionData'

javascript - Node.js - 开发中的自动刷新

javascript - Sails.js:在特定 View 上加载脚本

c# - 基于 Microsoft Bot Framework 的机器人可以连接到多个 channel 吗?

adaptive-cards - 自适应卡片根据 if 条件更改文本颜色

node.js - Firebase 的云功能 child_added

javascript - Nodejs、 express 、Ajax : Function triggers only Six Times

botframework - PromptDialog.Choice 不显示选项