Search code examples
node.jsbotframeworkazure-language-understanding

dialogs in botframework using LUIS.ai


I have a piece of code that works perfectly on my local bot, and weird when integrated with LUIS. It's a simple dialogue that redirects to another dialog:

    // 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?

The weird thing is that after prompting me about Office, it never enters the "function (session, results)" and goes directly into the interrupted dialogue code.

This piece of code works perfectly without LUIS integration and moves correctly between dialogues.


Solution

  • The dialog was interrupted every time I entered an utterance recognized by LUIS because of the triggerAction behavior.

    To disable the recognizer when a task is running I had to use the method onEnabled in the recognizer as follows:

    var recognizer = new builder.LuisRecognizer('<model>').onEnabled(function (context, callback) {
         var enabled = context.dialogStack().length == 0;
         callback(null, enabled);
    });
    

    This won't interrupt the dialog stack and the recognizer will work only when there is no conversation running.