0

I am trying to call a dialog in the bot which has to go to specific function, Here is the scenario... I have a dialog bot as shown below

bot.dialog('/Welcome', [
function(session){
builder.Prompts.text(session, "Welcome to the Bot");
},
function (session, args) {
// Has some code 
},
function (session, args){
//has some code
}......

When ever i do replace dialog ie.

bot.replaceDialog('/Welcome') 

it should not go to the first function ie. Welcome to the Bot It should skip this and go to next function.

Is there any way to accomplish this in azure bot?

Vinay Jayaram
  • 1,030
  • 9
  • 29

1 Answers1

0

This is quite simple if you look at their article

https://learn.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-dialog-replace

Their example is like below

// This dialog prompts the user for a phone number. 
// It will re-prompt the user if the input does not match a pattern for phone number.
bot.dialog('phonePrompt', [
    function (session, args) {
        if (args && args.reprompt) {
            builder.Prompts.text(session, "Enter the number using a format of either: '(555) 123-4567' or '555-123-4567' or '5551234567'")
        } else {
            builder.Prompts.text(session, "What's your phone number?");
        }
    },
    function (session, results) {
        var matched = results.response.match(/\d+/g);
        var number = matched ? matched.join('') : '';
        if (number.length == 10 || number.length == 11) {
            session.userData.phoneNumber = number; // Save the number.
            session.endDialogWithResult({ response: number });
        } else {
            // Repeat the dialog
            session.replaceDialog('phonePrompt', { reprompt: true });
        }
    }
]);

So yours would be something like below

bot.dialog('/Welcome', [
function(session, args, next){
if (!args || args.prompt)
    builder.Prompts.text(session, "Welcome to the Bot");
else
    next();
},
function (session, args) {
// Has some code 
},
function (session, args){
//has some code
}......

and you will call it like below

bot.replaceDialog('/Welcome', {prompt: false}))
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • Hi Tarun, Thanks for the update, But your solution doesn't work as per my requirements. If i parse replaceDialog('/Welcome', {prompt: false})).. It will however not go to *if* condition however it will be in the same function ie. it doesn't go to the next function automatically – Vinay Jayaram Apr 10 '18 at 05:23
  • @VinayJayaram, thanks for the feedback. I assume it is the `function (session, args) { // Has some code },` you had? I will take a look why – Tarun Lalwani Apr 10 '18 at 05:49
  • It is not going to function (session, args) { // Has some code }, . It is sitting idle in function(session, args){ if (!args || args.prompt) builder.Prompts.text(session, "Welcome to the Bot"); } – Vinay Jayaram Apr 10 '18 at 05:51