Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] triggerAction for Intent does not work as expected #3233

Closed
zixiangfu opened this issue Aug 1, 2017 · 3 comments
Closed

[Question] triggerAction for Intent does not work as expected #3233

zixiangfu opened this issue Aug 1, 2017 · 3 comments
Assignees

Comments

@zixiangfu
Copy link

zixiangfu commented Aug 1, 2017

System Information (Required)

SDK Language: NODE JS
SDK Version: 3.9.0
Development Environment: LOCALHOST

Issue Description

I have the following code snippet using three recognisers but the triggering of the intent doesn't work for me. Did I pass in the intent wrongly? I tried replacing with regular expression and it works for me. I have included a help dialog that execute when with the regular expression for help and it works. I am using botbuilder version 3.9.0.

Code Example

var restify = require('restify');
var builder = require('botbuilder');

function create(connector){

    // Create Chatbot
    var bot = new builder.UniversalBot(connector, {
        persistConversationData: false
    });

    // Declare custom recognizer
    var greeting = require('./bot/recognizer/greeting');

    // Declare dialogs
    var dialog = {
        welcome: require('./bot/dialogs/welcome'),
        faq: require('./bot/dialogs/faq'),
        weather: require('./bot/dialogs/weather'),
        reservation: require('./bot/dialogs/reservation')
    };

    //Declare LUIS service - FAQBot
    var model = 'my model link';
    var luisRecognizer = new builder.LuisRecognizer(model);

    // Declare QnA maker recognizer
    var qnaRecognizer = new cognitiveservices.QnAMakerRecognizer({
        knowledgeBaseId: MY_ID,
        subscriptionKey: MY_KEY,
        top: 5
    });

    // Declare intents dialog
    var intents = new builder.IntentDialog({
        recognizers: [
            greeting,
            qnaRecognizer,
            luisRecognizer
        ],
        intentThreshold: 0.4,
        recognizeOrder: builder.RecognizeOrder.series
    });

    // Define handler/dialog for matched intent
    intents.matches('Greeting', '/welcome');
    intents.matches('qna', '/faq');
    intents.matches('reservation', '/reservation');
    intents.matches('weather', '/weather');
    intents.onDefault('/confused');

    //Associate handler to custom dialog
    bot.dialog('/', intents);
    bot.dialog('/welcome', dialog.welcome).triggerAction({matches:'Greeting'});
    bot.dialog('/faq', dialog.faq).triggerAction({matches:'qna'});
    bot.dialog('/weather', dialog.botIntro).triggerAction({matches:'weather'});
    bot.dialog('/reservation', dialog.reservation).triggerAction({matches:'reservation'});
    bot.dialog('help', function (session, args, next) {
    session.endDialog("This is a bot that can help you make a dinner reservation. <br/>Please say 'next' to continue");
})
.triggerAction({
    matches: /^help$/i,
});

I tried removing the IntentDialog and used only the LuisRecognizer and it works for me. However, I will like to use more than one recogniser as I will like to use QnAMaker as well. Is there any way to make that work?

var restify = require('restify');
var builder = require('botbuilder');

function create(connector){

    // Create Chatbot
    var bot = new builder.UniversalBot(connector, {
        persistConversationData: false
    });

    // Declare custom recognizer
    var greeting = require('./bot/recognizer/greeting');

    // Declare dialogs
    var dialog = {
        welcome: require('./bot/dialogs/welcome'),
        faq: require('./bot/dialogs/faq'),
        weather: require('./bot/dialogs/weather'),
        reservation: require('./bot/dialogs/reservation')
    };

    //Declare LUIS service - FAQBot
    var model = 'my model link';
    var luisRecognizer = new builder.LuisRecognizer(model);
    bot.recognizer(luisRecognizer);

    //Associate handler to custom dialog
    bot.dialog('/', intents);
    bot.dialog('/welcome', dialog.welcome).triggerAction({matches:'Greeting'});
    bot.dialog('/faq', dialog.faq).triggerAction({matches:'qna'});
    bot.dialog('/weather', dialog.botIntro).triggerAction({matches:'weather'});
    bot.dialog('/reservation', dialog.reservation).triggerAction({matches:'reservation'});
    bot.dialog('help', function (session, args, next) {
    session.endDialog("This is a bot that can help you make a dinner reservation. <br/>Please say 'next' to continue");
})
.triggerAction({
    matches: /^help$/i,
});
@stevengum stevengum self-assigned this Aug 1, 2017
@stevengum
Copy link
Member

@zixiangfu I'm not entirely sure of what you're asking for, if I understand correctly you want to be able to plug in multiple recognizers into your bot? You're able to do this using bot.recognizer(). This method adds the recognizer to an IntentRecognizerSet inside the bot. If you want greater control of how the recognition is performed, you can actually use bot.recognizer() to add IntentRecognizerSets.

Here's an example of just adding a LuisRecognizer and QnaMakerRecognizer to a bot:

var QnAConfig = { } // QnaMaker key and knowledge base ID

bot.recognizer(new builder.LuisRecognizer(process.env.LUIS_MODEL))
.recognizer(new cognitiveservices.QnAMakerRecognizer(QnAConfig));

Heading away from this however... For your first code snippet, I'd like to highlight this section:

// Define handler/dialog for matched intent
intents.matches('Greeting', '/welcome');
intents.matches('qna', '/faq');
intents.matches('reservation', '/reservation');
intents.matches('weather', '/weather');
intents.onDefault('/confused');

//Associate handler to custom dialog
bot.dialog('/', intents);
bot.dialog('/welcome', dialog.welcome).triggerAction({matches:'Greeting'});
bot.dialog('/faq', dialog.faq).triggerAction({matches:'qna'});
bot.dialog('/weather', dialog.botIntro).triggerAction({matches:'weather'});
bot.dialog('/reservation', dialog.reservation).triggerAction({matches:'reservation'});

The second parameter in intents.matches() can be either a waterfall, bot/library, or a dialogId, as you've done. With this, you don't need to add a triggerAction({ matches : "someIntent" }) to your dialogs because you're already matching the dialogs with the intents. At best it's redundant, at worse it's probably the root of your error with the first code snippet.

This said however, I recommend that you continue with your second method of plugging the recognizers in at the bot level as opposed to at the dialog level as it affords more control when handling intents.

Does this clear things up?

@zixiangfu
Copy link
Author

Yes, I removed the intent.matches() and used bot.recognizer()to add IntentRecognizerSets. It works perfectly fine for me now. Thanks!

@nwhitmont
Copy link
Contributor

Thanks for the update @zixiangfu - I'm happy you got it working. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants