我有一段代码在我的本地机器人上完美运行,与LUIS集成时很奇怪。它是一个简单的对话框,可以重定向到另一个对话框:
// Modelo de datos cargado en luis.ai
var recognizer = new builder.LuisRecognizer(process.env.LUIS_MODEL_URL);
bot.recognizer(recognizer);
//first intent, greeting intent to say hi to the user
bot.dialog('greetings', [
function (session) {
var greetings = ["¡Hola!", "Bonjour amigo!", "zdravstvuyte! (Así se dice hola en ruso)"];
var pickAGreeting = function () {
var rnd_greeting = greetings[Math.floor(Math.random() * 4)];
return rnd_greeting;
};
session.send(pickAGreeting(), session.message.text);
builder.Prompts.text(session, 'What can I do for you about Office?');
},
function (session, results) {
var user_response = results.response;
session.beginDialog('getProductoOffice', user_response);
}
]).triggerAction({
matches: 'greetings',
onInterrupted: function (session) {
session.send('Can I help you with something?');
}
});
bot.dialog('getProductoOffice', [
function (session, args) {
session.send('Welcome to O365 help!', session.message.text);
...
And the bot does this:
[me]: Hola
[bot]: ¡Hola!
[bot]: What can I do for you about Office?
[me]: Tell me about Skype
[bot]: Can I help you with something?
奇怪的是,在提示我关于Office之后,它从未进入"功能(会话,结果)"并直接进入被打断的对话代码。
这段代码完美无需LUIS集成,并在对话之间正确移动。
答案 0 :(得分:1)
每次我输入LUIS识别的话语时,由于triggerAction
行为,对话框都被中断。
要在任务运行时禁用识别器,我必须在识别器中使用方法onEnabled
,如下所示:
var recognizer = new builder.LuisRecognizer('<model>').onEnabled(function (context, callback) {
var enabled = context.dialogStack().length == 0;
callback(null, enabled);
});
这不会中断对话框堆栈,识别器只有在没有对话运行时才能工作。