根据您尝试传递的 NegativeAnswerTriggeredDialog 对话框,我将假设您正在处理的提示类型是 Prompt.confirm。
问题是triggerAction 与the BotBuilder Handle User Actions documentation 一样,默认情况下它会清除对话框堆栈。来自文档:
将 triggerAction 绑定到对话框会将其注册到机器人。一旦触发,triggerAction 将清除对话框堆栈并将触发的对话框推入堆栈。此操作最适合用于在对话主题之间切换或允许用户请求任意独立任务。如果要覆盖此操作清除对话框堆栈的行为,请将 onSelectAction 选项添加到 triggerAction。
您可能想改用customActions,它直接绑定到机器人而不是对话框对象。
考虑一下我的代码示例,其中有Prompt.confirm 和Prompt.choice 的对话框:
bot.dialog('GreetingDialog', [
(session) => {
session.send('You reached the Greeting intent. You said \'%s\'.', session.message.text);
builder.Prompts.confirm(session, "Would you like to learn more?");
}, (session, results) => {
console.log(results.response);
if (results.response) {
session.endDialog("You're doing your part!");
} else if (!results.response) {
session.endDialog("Awwww.... no fun.");
} else {
session.endDialog("Something else is going on here.");
}
}
]).triggerAction({
matches: 'Greeting'
});
bot.dialog('HelpDialog',[
(session) => {
session.send('You reached the Help intent. You said \'%s\'.', session.message.text);
builder.Prompts.choice(session, "Pick something colorful", ["Red", "Yellow", "Blue"]);
}, (session, results) => {
switch(results.response.entity) {
case "Red":
session.endDialog("Red it is.");
break;
case "Yellow":
session.endDialog("Yellow it is.");
break;
case "Blue":
session.endDialog("Blue it is.")
break;
default:
session.endDialog("I have no idea what that is.");
}
}
]).triggerAction({
matches: 'Help'
});
bot.customAction({
matches: 'NegativeAnswer',
onSelectAction: (session, args, next) => {
session.endDialogWithResult({response: false});
}
});
bot.customAction({
matches: "PositiveAnswer",
onSelectAction: (session, args, next) => {
session.endDialogWithResult({response: true});
}
});
bot.customAction({
matches: "Red",
onSelectAction: (session, args, next) => {
session.endDialogWithResult({response: { index: 0, entity: 'Red', score: 1 }});
}
});
bot.customAction({
matches: "Yellow",
onSelectAction: (session, args, next) => {
session.endDialogWithResult({response: { index: 1, entity: 'Yellow', score: 1 }});
}
});
bot.customAction({
matches: "Blue",
onSelectAction: (session, args, next) => {
session.endDialogWithResult({response: { index: 2, entity: 'Blue', score: 1 }});
}
});
Prompt.confirm 是一个是/否提示,因此将“是”映射到true,将“否”映射到false。它不接受您试图在代码示例中传递的对象。在我的测试运行中,根据我设置的 LUIS 意图,“是”、“当然”和“是”都映射为“是”。 “否定”、“不”和“我不这么认为”(以及其他变体)映射到“否”。您的设置可能在 LUIS 意图方面有所不同。
另一方面,Prompt.choice 期望响应对象包含在“红色”、“蓝色”和“黄色”示例 customActions 中。在这种情况下,我为适当的意图设置了“深红色”、“栗色”、“琥珀色”、“蔚蓝”等可能的话语。
只要您对每个意图都有预期的可能答案,它就应该映射到正确的答案。