Bot - beginDialogAction (local trigger to dialog, not global as is triggerAction
//See:https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/core-globalMessageHandlers
Using beginDialogAction to localize commands
It doesn't make a lot of sense for our bot to have a global total command. After all, it's only valid if we're currently adding numbers. Using beginDialogAction allows you to register commands specific to that dialog, rather than global to the bot. By using beginDialogAction, we can ensure total is only executed when we're in the process of running a total.
The syntax for beginDialogAction is similar to triggerAction. You provide the name of the DialogAction you're creating, the name of the Dialog you wish to start, and the parameters for controlling when the dialog will be started.
beginDialogAction sample code
bot.dialog('AddNumber', [
// existing waterfall code
])
.triggerAction({matches: /^add$/i})
.beginDialogAction('Total', 'Total', { matches: /^total$/});
bot.dialog('Total', [
(session, results, next) => {
session.endConversation(`The total is ${session.privateConversationData.runningTotal}`);
},
]);
Sample code
beginDialogAction notes
By using endConversation, we reset the entire conversation back to its starting state. This will automatically clear out any privateConversationData, as the conversation has ended.