0

I'm currently building a chatbot with Azure's Bot service. I use a NLU-Bot, mixed with a waterfall flow, because dependent on the intent I want to get some specific information. Therefore I match the intent1 and want to

var intents = new builder.IntentDialog({ recognizers: [recognizer] })
.matches('intent1', (session, args, results) =>{

    session.beginDialog("getRequiredInformations");
    session.send("I received your information");
})

bot.dialog('getRequiredInformations', [
    (session) =>{       
        var levels = ['Beginner', 'Intermediate', 'Expert'];
        builder.Prompts.choice(session, "What's your level ?", levels, { listStyle: builder.ListStyle.button, maxRetries: 0 });
    },
    (session, results) => {
        session.conversationData.level = results.response.entity;
    }
]);

What I want to do is to wait until we received the answer from the getRequiredInformations dialog and then continue with the original dialog containing the recognized intent. With the code above the session.send("I received your information");is sent before the user entered an answer.

I also tried with bot.beginDialogAction('getRequiredInformations', 'getRequiredInformations'); but I think it's not possible to call this inside the dialog.

How am I able to achieve this?

fsulser
  • 853
  • 2
  • 10
  • 34

2 Answers2

1

Move the send to next waterfall step of the intent1 dialog. I think this should work.

var intents = new builder.IntentDialog({ recognizers: [recognizer] })
.matches('intent1', [(session, args, results) =>{

    session.beginDialog("getRequiredInformations");
}, (session, args, results) =>{
    session.send("I received your information");
}]);

matches method takes IWaterfallStep or IWaterfallStep[]. More info here.

Master Chief
  • 2,520
  • 19
  • 28
1

Found there several misstakes in your code snippet, please refer the following modification:

bot.dialog('intent1', [(session, args, next) => {
    session.beginDialog("getRequiredInformations");
}, (session, args, next) => {
    session.send("I received your information");
    session.send(session.conversationData.level)
}]).triggerAction({
    matches: 'intent1'
})

bot.dialog('getRequiredInformations', [
    (session) => {
        var levels = ['Beginner', 'Intermediate', 'Expert'];
        builder.Prompts.choice(session, "What's your level ?", levels, {
            listStyle: builder.ListStyle.button,
            maxRetries: 0
        });
    },
    (session, results) => {
        session.conversationData.level = results.response.entity;
        session.endDialog();
    }
]);

But this means there is not really an opportunity to wait for the dialog to finish like a callback or anything, I need to do this with a waterfall?

If I understand correct, you can try to use the following code snippet to enable the luis recognizer only if there is no dialog in stack.

var recognizer = new builder.LuisRecognizer(luisAppUrl)
 .onEnabled(function (context, callback) {
     var enabled = context.dialogStack().length == 0;
     callback(null, enabled);
 });
Gary Liu
  • 13,758
  • 1
  • 17
  • 32
  • Thanks a lot. But this means there is not really an opportunity to wait for the dialog to finish like a callback or anything, I need to do this with a waterfall? – fsulser Mar 20 '18 at 07:11