botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Guidance on handling Intent and dialog actions - Node.js

Open haganbt opened this issue 9 years ago • 4 comments

I would like check for matching intents and fall back to menu driven dialogs if the intents dont match. The idea being that somebody can provide a natural langue request first, backed up by a menu.

Heres what I have:

// Create chat bot
const connector = new builder.ChatConnector({
    appId: process.env.MICROSOFT_APP_ID || config.get('MICROSOFT_APP_ID'),
    appPassword: process.env.MICROSOFT_APP_PASSWORD || config.get('MICROSOFT_APP_PASSWORD')
});

const bot = new builder.UniversalBot(connector);

// Create LUIS recognizer that points at our model and add it as the root '/' dialog for our Cortana Bot.
const model = process.env.LUIS_MODEL_URL || config.get('LUIS_MODEL_URL');
const recognizer = new builder.LuisRecognizer(model);
const intents = new builder.IntentDialog({ recognizers: [recognizer] });

/* POST /api/messages */
router.post('/',  connector.listen());

bot.dialog('/', intents);
intents.matches('foo', (session) => {
    session.send(`foo.....`);
})
.onDefault((session) => {
    session.send('no intents matched, using default.....');
    session.endDialog('menu');
});

bot.dialog('menu', [
    function (session, args, next) {
        session.send(`Menu called.....`);
    }
]);

Can anyone advise if this is a reasonable approach or is it flawed in any way? If there is an example available, that would be ideal.

haganbt avatar Dec 08 '16 19:12 haganbt

Did you have any luck with this @haganbt ?

scottmcconnell avatar Jan 09 '17 03:01 scottmcconnell

Hi @scottmcconnell - I have not progressed this as the AI/LUIS part of my project has been de-prioritized (were using menu approach at first). The above appeared to work ok however as a novice it would be nice to see a recommended solution as im guessing im not the only one who would like to use this approach.

If you make any progress here, please do share and I will do the same if/when I get to this stage.

haganbt avatar Jan 09 '17 18:01 haganbt

@Stevenic I think you had a demo illustrating how to do this?

eanders-ms avatar Jan 18 '17 21:01 eanders-ms

Sorry for the delay... The basics-menu example shows how to implement a menu that's returned from your bots default handler. You can use this in conjunction with dialogs that are triggered by natural language and you should essentially have a bot that understands NL but will show menus when it doesn't understand. Basically just merge the basics-menu with the basics-naturalLanguage example and you should get the desired behavior,

Stevenic avatar Feb 23 '17 00:02 Stevenic