我目前正在使用 Azure 的 Bot 服务构建一个聊天机器人。我使用 NLU-Bot,与 waterfall 流混合,因为根据我想要获取一些特定信息的意图。
因此我匹配 intent1
并想要
var intents = new builder.IntentDialog({ recognizers: [recognizer] })
.matches('intent1', (session, args, results) =>{
session.beginDialog("getRequiredInformations");
session.send("I received your information");
})
bot.dialog('getRequiredInformations', [
(session) =>{
var levels = ['Beginner', 'Intermediate', 'Expert'];
builder.Prompts.choice(session, "What's your level ?", levels, { listStyle: builder.ListStyle.button, maxRetries: 0 });
},
(session, results) => {
session.conversationData.level = results.response.entity;
}
]);
我想要做的是等到我们收到来自 getRequiredInformations
对话框的答案,然后继续使用包含已识别意图的原始对话框。上面的代码 session.send("I receive your information");
在用户输入答案之前发送。
我也尝试过使用 bot.beginDialogAction('getRequiredInformations', 'getRequiredInformations');
但我认为不可能在对话框中调用它。
我怎样才能实现这一目标?
最佳答案
发现您的代码片段存在多处错误,请引用以下修改:
bot.dialog('intent1', [(session, args, next) => {
session.beginDialog("getRequiredInformations");
}, (session, args, next) => {
session.send("I received your information");
session.send(session.conversationData.level)
}]).triggerAction({
matches: 'intent1'
})
bot.dialog('getRequiredInformations', [
(session) => {
var levels = ['Beginner', 'Intermediate', 'Expert'];
builder.Prompts.choice(session, "What's your level ?", levels, {
listStyle: builder.ListStyle.button,
maxRetries: 0
});
},
(session, results) => {
session.conversationData.level = results.response.entity;
session.endDialog();
}
]);
But this means there is not really an opportunity to wait for the dialog to finish like a callback or anything, I need to do this with a waterfall?
如果我理解正确,您可以尝试使用以下代码片段仅在堆栈中没有对话框的情况下启用 luis 识别器。
var recognizer = new builder.LuisRecognizer(luisAppUrl)
.onEnabled(function (context, callback) {
var enabled = context.dialogStack().length == 0;
callback(null, enabled);
});
关于node.js - Azure Bot NodeJS 等待其他对话框完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49350200/