简体   繁体   中英

Microsoft BOT framework intents maching

I recently started development of a BOT application using Microsoft BOT framework with Node.js SDK. I want to know whether it's possible to check for a matching intent inside a dialog. For example,

var builder = require('botbuilder');
var bot = new builder.UniversalBot(connector);
var intents = new builder.IntentDialog();
bot.dialog('/', intents);

This intent will check for greetings.

intents.matchesAny([/^hi/i, /^hello/i], [
    function (session) {
        var displayName = session.message.user.name;
        var firstName = displayName.substr(0, displayName.indexOf(' '));
        session.send('Hello I’m M2C2! How can I help you %s? If you need help just say HELP.', firstName);
    }
]);

This intent will match for check card balance.

intents.matchesAny([/^balance/i, /^card balance/i], [
    function (session) {
        session.beginDialog('/check-balance');
    }
]);

And this is the dialog for check-balance.

bot.dialog('/check-balance', [
    function (session) {
        builder.Prompts.text(session, "Sure, I can find the balance for you! May I know the card number that you want to check the balance of?");
    },
    function (session, results) {
        if (isNaN(results.response)) {
            session.send('Invalid card number %s', results.response);
        } else {
            session.send('The balance on your %s card is $ 50', results.response);
        }
        session.endDialog();
    }
]);

what I want to know is whether it's possible to check for any of the matching intent inside the check-balance dialog. Let's say user enters an invalid card number and I want to make sure that command is not match with any of the defined intents so that I can show invalid card number response for sure and if its match, execute the matching intent.

intents.matches(/^(exit)|(quit)/, [
function (session) {
    session.beginDialog('/exit');
}]);


bot.dialog('/exit',[
function(session){
    if(session.message.text=='exit'||'quit'){
        session.send("Yor are exit");
    } else { session.send("you are not exit"); }                                                            
}])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM