Thursday, 25 May 2017

Unable to pass control to another method within a dialog in botbuilder for Node.js

I'm creating my first bot with Node.js and MS Bot Framework and I'm trying to figure out how to pass control from one method to another within a dialog.

In Bot Framework for C#, it's very easy:

context.Wait(NextMethodName);

where NextMethodName is the name of the method that runs after the bot receives the next user message.

I am trying to do a similar thing in Node.js. I have two functions. The first one prompts the user to enter something or click a button, and the second should process the user's input. I am struggling with passing control to the second function.

bot.dialog('subscribe', [
function (session) {
    var card = new builder.HeroCard(session)
        .title("Subscribe for reminders?")
        .text("It seems you're not enrolled yet. Subscribe for reminders to submit your work hours?")
        .buttons([
            builder.CardAction.imBack(session, "subscribe", "Subscribe")
        ]);

    var msg = new builder.Message(session).attachments([card]);

    session.send(msg);
    //next(); //compile error
},
function (session, results) {
    if (results.response === 'subscribe') {
        session.send('You are now subscribed to reminders through ' + session.message.user.channelId + '.');
    }
    else {
        session.send('You must subscribe to reminders before using this bot.');
    }
}
]);

How do I make the second function run after the user clicks the button or answers anything?



via K48

No comments:

Post a Comment