有简单的瀑布对话框:
SendMessageDialog = [
function (session) {
builder.Prompts.time(session, "Enter dates?");
},
function (session, results) {
session.conversationData.start = builder.EntityRecognizer.resolveTime([results.response]).toISOString();
if(typeof results.response.resolution.end != "undefined")
session.conversationData.end = results.response.resolution.end.toISOString();
}
];
Bot成功识别不同格式的时间,如果格式无效,则默认提示用户建议重新输入以下数据:
我不明白。请从列表中选择一个选项。
在Prompts
选项中,我只能更改此默认retryPrompt
消息。如果我需要额外的验证,例如:
Prompts.number()
是否有一种简单的方法添加其他验证以重试相同的瀑布步骤并要求用户重新输入数据?怎么实现这个? BotBuilder 3.9有可行的代码吗?
存在some examples以使用LUIS API调用进行一些验证,但它们仅适用于下一个瀑布步骤。目标是在输入正确的数据之前不要进入下一步 - 是否可能?谢谢!
答案 0 :(得分:1)
在提出问题之后,找到了操作方法Create custom prompts to validate input:
结果代码:
[
function (session) {
// Call start/end time prompt dialog
session.beginDialog("DatePromptDialog");
},
...
]
DatePromptDialog = [
function (session, args) {
var options = { retryPrompt: "I didn’t recognize dates you entered. Please try again using format: start - end dates" };
if (args && args.reprompt && args.endTimeMissed) {
builder.Prompts.time(session, "Please specify both start - end times:", options);
} else if (args && args.reprompt && args.dateInPast){
builder.Prompts.time(session, "That date seems to be in the past! Please enter a valid date.", options);
} else {
builder.Prompts.time(session, "Enter dates?", options);
}
},
function (session, results) {
var args = {};
delete session.conversationData.start; // Clear previous values
delete session.conversationData.end;
// Get start time
session.conversationData.start = builder.EntityRecognizer.resolveTime([results.response]).toISOString();
// Get duration end time if available
if(typeof results.response.resolution.end != "undefined")
session.conversationData.end = results.response.resolution.end.toISOString();
else {
args.endTimeMissed = true;
args.reprompt = true;
}
// Convert dates from string
var currDate = new Date(); // Current date
var startDate = new Date(session.conversationData.start);
var endDate = new Date(session.conversationData.end);
if(startDate < currDate || endDate < currDate) {
args.dateInPast = true;
args.reprompt = true;
}
if (args.reprompt) {
// Repeat the dialog
session.replaceDialog('DatePromptDialog', args);
} else {
// Success
session.endDialog();
}
}
];