如何自定义提示选择(Microsoft Botbuilder SDK) [英] How to Customize Prompt Choice (Microsoft Botbuilder SDK)

查看:83
本文介绍了如何自定义提示选择(Microsoft Botbuilder SDK)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Microsoft Botbuilder SDK in node.js using ES6 babel.

基于这篇有用的StackOverflow帖子 https://stackoverflow.com/a/45597651/3304185 ,我是尝试以相同的方式修改builder.Prompts.choice 的行为,以便对重试提示有更多控制,而不是默认为我听不懂".但是,当我尝试遵循此实现模式并将其应用于builder.Prompts.choice时,我只是得到了由机器人发送的undefined的选择,如下所示:

Based on this helpful StackOverflow post, https://stackoverflow.com/a/45597651/3304185, I am trying to modify the behavior of builder.Prompts.choice in the same way, to have more control over the retry prompt instead of defaulting to "I didn't understand." However, when I try to follow this implementation pattern and apply it to builder.Prompts.choice, I just get choices of undefined sent by the bot, like so:

// 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,我会希望会出现这些选择,但是这似乎并不需要全部.

Desired Behavior

I would have expected the choices to appear if I simply initialized args.choice to choices || args.choices, but that does not seem to be all that is necessary.

感谢您提供的任何帮助.

Thank you for any help you can give.

推荐答案

在这种情况下,传递strings的数组将不起作用,因为看起来提示符要求

In this case passing in an array of strings will not work as it looks like the prompt is expecting a list of 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)和模拟器正确显示了前两个选项,但没有正确显示后两个选项:

Here's a screenshot with the console.log(args) inside builder.Prompts.choice and the emulator displaying the first two choices properly, but not the last two:

这篇关于如何自定义提示选择(Microsoft Botbuilder SDK)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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