Azure Bot NodeJS 等待其他对话框完成
Azure Bot NodeJS wait for other dialog to be finished
我目前正在使用 Azure 的 Bot 服务构建聊天机器人。我使用 NLU-Bot,混合了瀑布流,因为我想根据意图获取一些特定信息。
因此我匹配 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 received your information");
在用户输入答案之前发送。
我也试过 bot.beginDialogAction('getRequiredInformations', 'getRequiredInformations');
但我认为在对话框中调用它是不可能的。
我怎样才能做到这一点?
将发送移至 intent1
对话框的下一个瀑布步骤。我认为这应该有效。
var intents = new builder.IntentDialog({ recognizers: [recognizer] })
.matches('intent1', [(session, args, results) =>{
session.beginDialog("getRequiredInformations");
}, (session, args, results) =>{
session.send("I received your information");
}]);
matches
方法采用 IWaterfallStep 或 IWaterfallStep[]。更多信息 here.
发现你的代码片段有几处错误,请参考以下修改:
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);
});
我目前正在使用 Azure 的 Bot 服务构建聊天机器人。我使用 NLU-Bot,混合了瀑布流,因为我想根据意图获取一些特定信息。
因此我匹配 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 received your information");
在用户输入答案之前发送。
我也试过 bot.beginDialogAction('getRequiredInformations', 'getRequiredInformations');
但我认为在对话框中调用它是不可能的。
我怎样才能做到这一点?
将发送移至 intent1
对话框的下一个瀑布步骤。我认为这应该有效。
var intents = new builder.IntentDialog({ recognizers: [recognizer] })
.matches('intent1', [(session, args, results) =>{
session.beginDialog("getRequiredInformations");
}, (session, args, results) =>{
session.send("I received your information");
}]);
matches
方法采用 IWaterfallStep 或 IWaterfallStep[]。更多信息 here.
发现你的代码片段有几处错误,请参考以下修改:
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);
});