取消 builder.Prompts.choice()

Cancel builder.Prompts.choice()

我的机器人有一个要求用户输入的提示:

builder.Prompts.choice(session, "Is it ok?", ["Yes", "No"]);

现在,当用户回复 "Yes" 或 "No" 以外的其他内容时,程序将始终回复:

I did not understand. Please choose an option from the list

和之前一样的选择。

如果用户键入 "Yes" 或 "No" 以外的其他内容(并重置提示堆栈),我希望机器人不再要求输入。

您可以如图所示更改提示的 maxRetries 选项(默认为无限)

builder.Prompts.choice(session, "Is it ok?", ["Yes", "No"],maxRetries:'2'); 

您可以在提到的 URL

中看到 IPrompt 选项

https://docs.botframework.com/en-us/node/builder/chat-reference/interfaces/_botbuilder_d_.ipromptoptions.html

您还可以在提示期间使用触发器操作捕获其他特定输入(例如 "help"):

// Add default dialog
bot.dialog('/', function (session) {
    builder.Prompts.choice(session, "Is it ok?", ["Yes", "No"]);
});

// Add help dialog with a trigger action bound to a regular 
// expression looking for the users to ask for help.
bot.dialog('/help', function (session) {
    session.endDialog("Type 'Yes' or 'No'");
}).triggerAction({ matches: /^(help|options)/i });

请注意,您需要安装 BotBuilder 的预发布版本:

npm install --save botbuilder@next