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

[Question]How do you start a dialog via a backchannel triggered event?

Open jfantell opened this issue 9 years ago • 5 comments

SDK Platform: Node.js SDK Version: 3.11.0 Active Channels: web, direct line Deployment Environment: localhost

Question: How do you start a dialog via a backchannel triggered event? I tried doing bot.beginDialog('Welcome-Dialog') and event.beginDialog('Welcome-Dialog') without any luck.

bot.on("event", function (event) {
    var msg = new builder.Message().address(event.address);
    msg.textLocale("en-us");
    if (event.name === "buttonClicked") {
        msg.text("Hi "+ event.value.name");
        bot.send(msg);
    }
   bot.begin('Welcome-Dialog')
});

bot.dialog('Welcome-Dialog', function(session,args) {
    /* Dialog flow logic */
}).triggerAction( { matches: 'Hi' } );

jfantell avatar Nov 15 '17 07:11 jfantell

A working solution would be to store a map of user-id and session and then use seesion.send to send a dialog to the corresponding user .

Aashish-Amber avatar Nov 16 '17 09:11 Aashish-Amber

Thank you for your response, but I am not sure that I understand. Could you provide a brief example?

jfantell avatar Nov 16 '17 23:11 jfantell

@jfantell You need to call bot.beginDialog() with the correct arguments, including address and dialogId.

You can find the method signature via VSCode intellisense: screen shot 2017-11-17 at 4 24 01 pm

in the Typescript SDK reference doc: https://docs.botframework.com/en-us/node/builder/chat-reference/classes/botbuilder_d.universalbot.html#begindialog

or read the file here: https://github.com/Microsoft/BotBuilder/blob/master/Node/core/src/bots/UniversalBot.ts#L243

Since the bot of type UniversalBot has no access to the session object, you need to grab the address from the event.address and pass it to beginDialog as the first argument. Eg: bot.beginDialog(address, dialogId);

nwhitmont avatar Nov 18 '17 00:11 nwhitmont

Hi @jfantell - Were you able to get it working using the info provided in my last comment?

Let me know if you still have questions.

nwhitmont avatar Dec 01 '17 01:12 nwhitmont

reopen if you're still having issues.

nwhitmont avatar Dec 04 '17 23:12 nwhitmont