首页 > 解决方案 > 为 botframework v4 选择提示应用列表样式:NodeJS

问题描述

您好我正在尝试在 botbuilder-dialog 的选项中添加列表样式;Botframework v4,NodeJS。

我正在尝试使用下面的代码来实现它,但似乎列表样式对选择没有任何影响。它应该提示一个编号列表,但它会提示一个类似列表的按钮。

const{ChoicePrompt, ListStyle} = require('botbuilder-dialogs');
const CHOICE_PROMPT = 'CHOICE_PROMPT';

//Set up ChoicePrompt
var cp = new ChoicePrompt(CHOICE_PROMPT);
cp.Style = ListStyle.list;
this.addDialog(cp);

this.choicesX = ['Pick1', 'Pick2', 'Pick3'];


//function
async test(stepContext){
    return await stepContext.prompt(CHOICE_PROMPT, {
        prompt: 'Select item:',
        choices: this.choicesX
    });
}

在选择提示中添加列表样式的正确方法是什么?

标签: node.jsbotframework

解决方案


这似乎是这个 StackOverflow 问题的副本;但是,答案在 C# 中。这就是在 Node SDK 中设置样式提示选项的方式。

节点SDK v4.5

const { ListStyle, ... } = require('botbuilder-dialogs');

async transportStep(step) {
    // WaterfallStep always finishes with the end of the Waterfall or with another dialog; here it is a Prompt Dialog.
    // Running a prompt here means the next WaterfallStep will be run when the users response is received.
    return await step.prompt(CHOICE_PROMPT, {
        prompt: 'Please enter your mode of transport.',
        choices: ChoiceFactory.toChoices(['Car', 'Bus', 'Bicycle']),
        style: ListStyle.list
    });
}

列表样式选项是noneautoinlinelistsuggestedActionheroCard

希望这可以帮助!


推荐阅读