botframework选择无效的响应类型
我使用nodejs SDK来创建我的机器人与MSFT botframework。代码段如下:
function(session, args, next){
builder.Prompts.choice(session, "Please select one of the options:", ['AAA', 'BBB','CCC'], {retryPrompt: "Invalid choice, Please pick below listed choices",
listStyle: builder.ListStyle.button,
maxRetries: 1
});
},
function(session,results){
if (results.response) {
//Do something
}
}
我有两个问题:
- 我想导航到另一个对话框Flow,以防用户输入除选项之外的任何内容(“AAA”,“BBB”,“CCC”)。那可能吗?
- 我想改变重试提示每次让我们说从列表中选择话语。那可能吗?
我想导航到另一个对话框Flow,以防用户输入除选项之外的任何内容(“AAA”,“BBB”,“CCC”)。那可能吗?
是的,这是可能的。您可以使用与选项相关的所需瀑布步骤定义多个对话框。喜欢:
bot.dialog('AAA',[...])
并利用replaceDialog
将用户重定向到新的对话流程:
(session,result)=>{
//result.response.entity should be one of string `AAA`,`BBB`,`CCC`
session.replaceDialog(result.response.entity);
}
我想改变重试提示每次让我们说从列表中选择话语。那可能吗?
是的,这是可能的。根据choice定义,我们可以设置扩展IPromptChoiceOptions
的选项扩展[IPromptOptions][2]
,我们可以找到retryPrompt?: TextOrMessageType;
,挖掘TextOrMessageType
定义的源代码:
/**
* Flexible range of possible prompts that can be sent to a user.
* * _{string}_ - A simple message to send the user.
* * _{string[]}_ - Array of possible messages to send the user. One will be chosen at random.
...
...
*/
export type TextOrMessageType = string|string[]|IMessage|IIsMessage;
所以我们可以为retryPrompt
设置一个字符串列表,bot builder会随机选择一个。请尝试以下方法:
builder.Prompts.choice(session, "Please select one of the options:", ['AAA', 'BBB', 'CCC'], {
listStyle: builder.ListStyle.button,
maxRetries: 1,
retryPrompt:['utterance 1','utterance 2','utterance 3','utterance 4']
});