注意
我正在使用 ES6 babel 在 node.js
中使用 Microsoft Botbuilder SDK。
问题
我有一个对话框“/MainMenu”,它提示用户进行自由回复,以便进入另一个更相关的对话框。然而,我也希望用户能够触发一个与主题完全无关的操作(即询问机器人“你好吗?”的对话框),返回到原始的 MainMenu 对话框就像他们离开时一样。我知道在 SDK 的文档中,onSelectAction 可用于将触发的对话框放在堆栈顶部而不是替换整个堆栈,但是一旦“/HowAreYou”对话框结束,机器人也会认为该响应是对于初始的 MainMenu 提示,回复“我不明白。请重试”,如下所示:
代码
// I am using the builder.Library routing standard, and have confirmed that
// this gets triggered as expected. this dialog exists in a different file
lib.dialog('/HowAreYou', [
(session, args, next) => {
session.send('I\'m doing well. Thanks for asking!');
builder.Prompts.text(session, 'How are you doing today?');
}, (session, results) => {
session.endDialog('Good to hear that!');
}
]).triggerAction({
matches: /^how are you?$/i,
onSelectAction: (session, args, next) => {
// Add the help dialog to the top of the dialog stack (override the
// default behavior of replacing the stack)
session.beginDialog(args.action, args);
}
});
bot.dialog('mainMenu', [
(session, args, next) => {
builder.Prompts.text(session, 'Hi there! What can I do for you today?');
},
(session, results) => {
session.endConversation('Goodbye!');
}
]).beginDialogAction('weatherAction', '/Weather', {
matches: /^weather$/i,
}).beginDialogAction('sportsAction', '/Sports', {
matches: /^sports$/i,
}).beginDialogAction('cookingAction', '/Cooking', {
matches: /^cooking$/i,
});
期望的行为
虽然当前的结果非常接近所需的行为,但我理想情况下希望机器人在 HowAreYou 对话框结束后以与开始时相同的 MainMenu 提示进行回复,不要说它不理解。
问题
这可能吗?如果是这样,怎么办?如果没有,有什么替代方案?
感谢您提供的任何帮助。
最佳答案
GitHub 上有一个解释:https://github.com/Microsoft/BotBuilder/issues/2421 ,我们可以意识到提示
是内置对话框,它将处理输入验证。
当您第一次进入 mainMenu
中的“提示”对话框时,当第一个“提示”对话框等待输入文本时,您会触发 HowAreYou
对话框。
然后 HowAreYou
以 session.endDialog('Good to learn that!');
结尾,而 mainMenu
中的第一个 Prompts 对话框没有结果,验证失败。
根本原因应该相当于为 builder.Prompts.text(session, 'Hi There! What can I do for you Today?'); 输入一个空文本。
。
更新
找到promptAfterAction
提示对话框的 IPromptOptions
属性,我正在考虑这个问题。我认为这应该是设计使然。
由于句子我不明白...
是属性retryPrompt
的默认文本。因此,当您结束 HowAreYou
对话框并返回 mainPage
对话框堆栈时。提示对话框将重新启动并向用户发送 retryPrompt
,这会引发您的问题。
对于辅助功能,您可以尝试使用:
builder.Prompts.text(session, 'Hi there! What can I do for you today?', {
retryPrompt: 'Hi there! What can I do for you today?'
});
关于node.js - 如何将触发操作中的对话框与提示分开 (Microsoft Botbuilder SDK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48795036/