0

I have LUIS app created, with 1 intent(Order Pizza) and 9 entities(Order,Kind, Signature, Size, Toppings, address, Time, Duration, Range).

I need to create a bot in Azure Bot Framework. I'm unable to understand and use the waterfall for all the entities. Please let me know how to go about it

Code :

 dialog.matches('OrderPizza', [
 function (session, args, next) {

   var order = builder.EntityRecognizer.findEntity(args.entities, 'order');
   var kind = builder.EntityRecognizer.findEntity(args.entities, 'Kind');
   session.dialogData.intentScore = args.score;

   if (!order) {
       builder.Prompts.text(session, 'welcome please order pizza');
   } else {
       session.dialogData.order = order;
       next();
   }
 },
 function (session, results) {
   var order = session.dialogData.order;
   if (results.response) {
       session.send('what kind?');
   }else{
       session.send(`we don't have that kind of pizza`);
   }
 }

    ]);

How to go further for other entities?

Anagha
  • 3,073
  • 8
  • 25
  • 43
  • Try [the documentation](https://learn.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-dialog-manage-conversation) – stuartd Jun 14 '17 at 10:34
  • Thanks, I tried. But can only write 2 functions. After which its not executing – Anagha Jun 14 '17 at 13:36

1 Answers1

1

I'm not sure what you mean by only being able to write 2 functions; but if you're trying to call LUIS inside of your dialog you can follow this example. You'll call a LuisRecognizer inside your waterfall step on session.message.text. The snippet from the example is below:

builder.LuisRecognizer.recognize(session.message.text, '<model url>', function (err, intents, entities) {
   if (entities) {
     var entity = builder.EntityRecognizer.findEntity(entities, 'TYPE');
     // do something with entity...
   }
});

This would allow you to call LUIS inside a waterfall for recognizing your user's messages.

Regarding your code there is a number of issues:

// Original Code
dialog.matches('OrderPizza', [
  function (session, args, next) {
   var order = builder.EntityRecognizer.findEntity(args.entities, 'order');
   var kind = builder.EntityRecognizer.findEntity(args.entities, 'Kind');
   session.dialogData.intentScore = args.score;

   if (!order) { // What about kind?
       builder.Prompts.text(session, 'welcome please order pizza');
   } else {
       session.dialogData.order = order; // What about kind?
       next();
   }
 },
 function (session, results) {
   var order = session.dialogData.order;
   if (results.response) {
       session.send('what kind?');
   }else{
       session.send(`we don't have that kind of pizza`);
   }
 }
]); 

In your first waterfall step you're not saving the "Kind" entity to your dialogData.

function (session, args, next) {
  var order = builder.EntityRecognizer.findEntity(args.entities, 'order');
  var kind = builder.EntityRecognizer.findEntity(args.entities, 'Kind');
  session.dialogData.intentScore = args.score;

  if (kind) {
    session.dialogData.kind = kind;
  }

  if (!order) {
    builder.Prompts.text(session, 'welcome please order pizza');
  } else {
     session.dialogData.order = order;
     next();
  }
}

In your second waterfall step you are not calling next, nor are you sending a Prompt to the user, which results in you being stuck after two functions.

function (session, results, next) {
  var order = session.dialogData.order ? session.dialogData.order : results.response;
  var kind = session.dialogData.kind;

  if (results.response && !kind) {
    builder.Prompts.text(session, 'what kind?');
  } else {
    session.send('we don\'t have that kind of pizza');
    next();
  }
}
Steven G.
  • 1,632
  • 1
  • 11
  • 14