botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Manually call LUIS without making request to the API

Open piffarettig opened this issue 9 years ago • 3 comments

To put you in context of what I am trying to achieve:

  1. The user types 'Hello' to the bot.

  2. In response, the bot shows a HeroCard with buttons, where each button has a function linked to it. Similar to this:

bot-blog_v3-4-500-opt

  1. Whenever the user clicks a button some of those functions should be called and some behaviour will be done. However, the user can avoid clicking on any of those buttons and try to type something by himself. That should work and that should call LuisDialog intent handling behaviour again.

How can I achieve that?

private async Task AfterUserChoseOptionInSalute(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            var option = await result;
            string value = option.Text;
            switch (value)
            {
                    case "help":
                        // do sth
                        break;
                    case "contact_us":
                        // do sth
                        break;
                    default:
                       // the user typed something else
                       // for example: "view my credit card balance"
                       // I want to call my current LuisDialog again...
                       break;
             }
       }

Should I create a new LuisDialog as a child dialog and forward the message to It? Or what would be the best way? I dont wan't to call the API by hand, I want to use the SDK.

Other option I thought was calling context.Wait(MessageReceived) and then manually sending the text to the bot, simulating the behaviour of the user typing it... But I dont know how to achieve this.

Any thoughts on this?

piffarettig avatar Dec 27 '16 14:12 piffarettig

Here are a few options:

  1. Use a scorable that looks at all user input before it reaches the dialogs on the stack - here is an example: https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Samples/AlarmBot/Models/AlarmScorable.cs#L104

  2. Use a root dialog to intercept the input, try to parse out button actions, and then forward to LUIS child dialog (as you suggest)

  3. Override LUIS dialog's MessageReceived to intercept button actions, otherwise delegate to base class implementation.

  4. Use dispatch dialog and regular expressions to intercept button actions, otherwise delegate to your LUIS model through the next ScorableGroup.

willportnoy avatar Dec 27 '16 21:12 willportnoy

@piffarettig , Please refer to this ticket, I hope this will help you. https://github.com/Microsoft/BotBuilder/issues/1895

virendrak avatar Dec 28 '16 09:12 virendrak

Thanks @virendrak that was exactly the thing I was trying to achieve. @willportnoy thanks as well for the many options!

piffarettig avatar Dec 28 '16 18:12 piffarettig