Sathis Sakthivel
Sathis Sakthivel

Reputation: 79

How do I beginDialog for a specific LUIS intent?

Here's my code:

 async dispatchToTopIntentAsync(context, intent, recognizerResult) {
         console.log(context);
         switch (intent) {
             case 'INeedInsurance':{ 
                 const bookingDetails={};
                  bookingDetails.type="Auto"; 
                return await context.beginDialog(ConfirmAuto)

             }

             default:
                 console.log(`Dispatch unrecognized intent: ${ intent }.`);
                 await context.sendActivity(`Dispatch unrecognized intent: ${ intent }.`);
                 // await next();
                 break;
         } 
     }

I need to push waterfall dialog according to the LUIS Intent Result ? Could you help me guys?

Upvotes: 1

Views: 254

Answers (3)

Sathis Sakthivel
Sathis Sakthivel

Reputation: 79

Import {DialogSet} from 'bot-builder-dialogs'; 
const { ConfirmHome } = require("../dialogs/confirmHome");

    //clear old dialog stack 
     const dialogs = new DialogSet(this.dialogState); 
        const dc = await dialogs.createContext(context); 
        await dc.endDialog(); 
    //end  

    //run() dialog context 
       const home = new ConfirmHome(); 
              await home.run(
                context,
                this.dialogState
              );

Upvotes: 0

billoverton
billoverton

Reputation: 2885

Have you tried just removing return? It should work. Below is an example from one of my bots, works fine. You also don't need the {} around the case, though I'm not sure that is causing your problem.

I also noticed also you're not creating a separate dialog context. I honestly don't know if that is required, I picked it up from the example. So when I pass in context to dispatchToTopIntentAsync, I'm then creating dialog context via const dc = await this.dialogs.createContext(context); before I get into the case statement. But I'm also using an older version of the Dispatch Bot template. Regardless, I starting the dialog as follows should be the same either way.

switch (intent) {
    case VIEW_ORDER_INTENT:
        await dc.beginDialog(VIEW_ORDER_DIALOG,recognizerResult);
        break;
    default:
        var processResult = await this.qnaDialog.processAsync(userDialog.qnaState, 
        context.activity);
        userDialog.qnaState = processResult[0];
        await this.userDialogStateAccessor.set(context,userDialog);
        var output = processResult[1];
        var result = processResult[2];
        await dc.context.sendActivity(output);      
        break;
}

Another note, it looks like you're defining bookingDetails only in the dispatch function. This won't be available to your dialog nor will the object get updated when your dialog completes. You can pass the object as a second parameter in beginDialog and you can have the dialog return a result. You should be able to accomplish this via bookingDetails = await context.beginDialog(ConfirmAuto,bookingDetails);. Note though that you're only awaiting "beginDialog", so that variable is going to be pending until the dialog completes.

Upvotes: 0

Horatiu Jeflea
Horatiu Jeflea

Reputation: 7414

Try with session.replaceDialog instead of context.beginDialog and no need to return await, just follow the example in the link:

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

Edit:

Can you also check

https://learn.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-recognize-intent-luis?view=azure-bot-service-3.0

on how to react on LUIS intents? More exactly on

// Make sure you add code to validate these fields
var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;
var luisAPIHostName = process.env.LuisAPIHostName || 'westus.api.cognitive.microsoft.com';

const LuisModelUrl = 'https://' + luisAPIHostName + '/luis/v2.0/apps/' + luisAppId + '?subscription-key=' + luisAPIKey;

// Create a recognizer that gets intents from LUIS, and add it to the bot
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
bot.recognizer(recognizer);

// Add a dialog for each intent that the LUIS app recognizes.
// See https://learn.microsoft.com/bot-framework/nodejs/bot-builder-nodejs-recognize-intent-luis 
bot.dialog('GreetingDialog',
    (session) => {
        session.send('You reached the Greeting intent. You said \'%s\'.', session.message.text);
        session.endDialog();
    }
).triggerAction({
    matches: 'Greeting'
})

bot.dialog('HelpDialog',
    (session) => {
        session.send('You reached the Help intent. You said \'%s\'.', session.message.text);
        session.endDialog();
    }
).triggerAction({
    matches: 'Help'
})

bot.dialog('CancelDialog',
    (session) => {
        session.send('You reached the Cancel intent. You said \'%s\'.', session.message.text);
        session.endDialog();
    }
).triggerAction({
    matches: 'Cancel'
}) 

Upvotes: 1

Related Questions