Sandip
Sandip

Reputation: 262

Is there any common method which will hit all the intents in the LUIS Dialog?

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.

Upvotes: 2

Views: 232

Answers (2)

Eric Dahlvang
Eric Dahlvang

Reputation: 8292

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

Upvotes: 3

Schwammy
Schwammy

Reputation: 233

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.

Upvotes: 0

Related Questions