2

I would like to know if anyone knows any way to call a custom method all the time whenever any Luis Intent method is invoked. Basically I am trying to add a loader message to user when a Bot is getting data from LuisDialog.

D4RKCIDE
  • 3,439
  • 1
  • 18
  • 34
Sandip
  • 252
  • 2
  • 13
  • language? node? c#? – Ezequiel Jadib Dec 22 '17 at 13:35
  • Thanks for your reply. I am using c#. @EzequielJadib – Sandip Dec 22 '17 at 14:47
  • So, what prevents you for putting the call to the method in each of your LUIS Intent methods? – Ezequiel Jadib Dec 22 '17 at 16:08
  • I am planning to have more intents in my application its not effective way to call the common method in each intent. Also one should not miss this call in the future intent. @EzequielJadib. Do you still want me to call this in each intent separately? – Sandip Dec 23 '17 at 09:18
  • You can override the `DispatchToIntentHandler` method inside of the dialog. Control will branch to it first before hitting any of the `LUISIntent` handlers. – Kunal Mukherjee Jan 20 '18 at 19:23

2 Answers2

3

If you have a RootDialog that forwards the message to the LuisDialog, you can show a "loader message" in either the RootDialog or the LuisDialog's StartAsync method. Another option is to override the LuisDialog's MessageReceived, and send the loader message before calling the base.MessageReceived.

[Serializable]
public class RootDialog : IDialog<object>
{
    public Task StartAsync(IDialogContext context)
    {
        context.Wait(MessageReceivedAsync);
        return Task.CompletedTask;
    }

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        var activity = await result as Activity;
        await context.PostAsync("RootDialog.MessageReceivedAsync");
        await context.Forward(new LuisTestDialog(), AfterLuisDialog, activity);            
    }

    private async Task AfterLuisDialog(IDialogContext context, IAwaitable<object> result)
    {
        await context.PostAsync("RootDialog.AfterLuisDialog");            
    }
}

[LuisModel("xxx", "xxx")]
[Serializable]
public class LuisTestDialog : LuisDialog<object>
{
    public async override Task StartAsync(IDialogContext context)
    {
        await context.PostAsync("LuisTestDialog.StartAsync");
        await base.StartAsync(context);
    }

    [LuisIntent("")]
    [LuisIntent("None")]
    public async Task None(IDialogContext context, LuisResult result)
    {
        await context.PostAsync("LuisTestDialog.None");
        context.Done(true);
    }

    protected async override Task MessageReceived(IDialogContext context, IAwaitable<IMessageActivity> item)
    {
        await context.PostAsync("LuisTestDialog.MessageReceived");
        await base.MessageReceived(context, item);
    }
}

The above will result in the following messages:

enter image description here

Eric Dahlvang
  • 8,252
  • 4
  • 29
  • 50
  • Thank you for your answer adding the common method in MessageRecieved Override worked for me. – Sandip Dec 26 '17 at 06:54
0

I have two ideas.

  1. Send the "loader message" from your Messagescontroller.
  2. Have a root dialog that gets called from MessagesController. It can send your loader message before doing a context.forward() to your LUIS dialog

I hope this helps.

Schwammy
  • 223
  • 3
  • 15