我希望我能在这个问题上说清楚。我的问题是,我想使用简单的Luis触发对话框来向给定的当前对话框发回意图/实体。
也就是说,我希望将触发对话框从我的业务对话框中解耦,定义其唯一功能是触发并返回相关数据的对话框,例如:
bot.dialog('NegativeAnswerTriggeredDialog', [
(session, args, next) => {
var response = { type: 'bool', value: false, index: 1, entity: 'No', score: 1};
session.endDialogWithResult({ response:response });
}
]).triggerAction({
matches: 'NegativeAnswer',
onSelectAction: (session, args, next) => {
session.beginDialog(args.action, args);
}
});所以,请注意,我只是准备了一些对象,然后我endDialogWithResult将这个对象传递给上一个对话框。
问题是提示符不能识别这个对象,或者这个对象的格式,我不确定。有没有办法返回它,使其被接受为提示的有效输入?
顺便说一句,我想在这里实现的目标是允许用户用自然语言回答提示。
发布于 2018-06-22 08:34:38
我假设您正在处理的提示类型是基于您试图传递的NegativeAnswerTriggeredDialog对话框的Prompt.confirm。
根据the BotBuilder Handle User Actions documentation,问题是triggerAction,默认情况下会清除对话堆栈。从文档中:
将triggerAction绑定到对话框可将其注册到机器人。一旦触发,triggerAction将清除对话堆栈,并将触发的对话框压入堆栈。此操作最适合用于在会话主题之间切换,或允许用户请求任意独立任务。如果要覆盖此操作清除对话框堆栈的行为,请向triggerAction添加onSelectAction选项。
您可能希望改用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是一个Yes/No提示,因此将"Yes“映射到true,将"No”映射到false。它不接受您试图在代码示例中传递的对象。在我的测试运行中,根据我设置的LUIS意图,"Yep“、”course“和”Yes“都映射到”Yes“。“否定”、“不”和“我不这么认为”(在其他变体中)映射到“否”。您在LUIS intent方面的设置可能有所不同。
另一方面,Prompt.choice期望响应对象包含在“红色”、“蓝色”和“黄色”示例customAction中。在这种情况下,我为适当的意图设置了“深红色”、“栗色”、“琥珀”、“天蓝色”等可能的发音。
只要你对每个意图都有预期的可能答案,它就应该映射到正确的答案。
https://stackoverflow.com/questions/49994377
复制相似问题