在Choice Prompt中修改Choice Validation-Bot Framework Node.js



当前有一个choice_prompt,要求用户验证一些选项。要进入瀑布的下一步,用户的输入必须是值或与该值相关的同义词。

如果用户键入的内容不是值或同义词,则choicePrompt将循环。我想警告用户";输入一个介于1-6"之间的数字;。

async question2_1(step) {
return await step.prompt(CHOICE_PROMPT, {
prompt: '"1/3: How easy were the course materials to navigate and follow?',
choices: ChoiceFactory.toChoices([' = Very Hard', '', '', '', '', ' = Very Easy']),
style: ListStyle.list
});
}

您需要添加一个retryPrompt选项,如下所示:

async question2_1(step) {
return await step.prompt(CHOICE_PROMPT, {
prompt: '"1/3: How easy were the course materials to navigate and follow?',
choices: ChoiceFactory.toChoices([' = Very Hard', '', '', '', '', ' = Very Easy']),
style: ListStyle.list,
retryPrompt: 'Enter a number between 1 - 6'
});
}

如果您想重新提示任何原始提示,也需要添加它。用户只会收到您在retryPrompt下添加的文本的重新提示。

编辑:我再次考虑使用同义词,我认为尽管显示为编号列表,但使用所有这些空字符串不会得到预期的值。也许我错了,因为我还没有做出这样的选择,但我可能会明确定义我的选择,如下所示。这允许您为每个选项设置一个单独的标题(显示(和值(在后端发送(,如果需要,还可以添加同义词(您也可以使用上面更简单的定义添加同义词(。

async question2_1(step) {
return await step.prompt(CHOICE_PROMPT, {
prompt: '"1/3: How easy were the course materials to navigate and follow?',
choices: [
{value:'1', action: {type: 'imBack', title: '= Very Hard', value: '1'}, synonyms: ['1']},
{value: '2', action: {type: 'imBack', title: ' ', value: '2'}, synonyms: ['2']},
{value: '3', action: {type: 'imBack', title: ' ', value: '3'}, synonyms: ['3']},
{value: '4', action: {type: 'imBack', title: ' ', value: '4'}, synonyms: ['4']},
{value: '5', action: {type: 'imBack', title: ' ', value: '5'}, synonyms: ['5']},
{value: '6', action: {type: 'imBack', title: '= Very Easy', value: '6'}, synonyms: ['6']},
],
style: ListStyle.list,
retryPrompt: 'Enter a number between 1 - 6'
});
}

最新更新