2

目前有一个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
    });
}

4

1 回答 1

1

您需要像这样添加一个 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'
    });
}
于 2021-06-10T19:57:17.130 回答