mikalai
mikalai

Reputation: 1736

A very long message for LUIS dialog resets dialog state

Using bot framework emulator v.3.5.36, if a user sends long text (about 1K characters), emulator silently resets dialog stack back to root dialog, without any errors or warnings. (see the screenshot below.)

Is there a declared message limit for bot framework?

Is there a way for bot to handle such situations and warn user instead of this silent something?

enter image description here

There is nothing really specific about the code at all:

[LuisModel("{GUID}", "{CODE}", LuisApiVersion.V2, domain: "westeurope.api.cognitive.microsoft.com", threshold: 0.5)]
[Serializable]
public class LuisSearchDialog2 : LuisDialog<object>
{
    [LuisIntent("")]
    [LuisIntent("None")]
    public async Task None(IDialogContext context, LuisResult result)
    {
        await context.PostAsync(JsonConvert.SerializeObject(result));
        context.Wait(this.MessageReceived);
    } 
}

Upvotes: 0

Views: 106

Answers (2)

mikalai
mikalai

Reputation: 1736

The reason is that base LuisDialog doens't handle failed API requests (in case if query is too long, it returns 414 code). So the simplest way to handle such errors is to override MessageReceived as follows:

[Serializable]
public class LuisSearchDialog2 : LuisDialog<object>
{
    protected override async Task MessageReceived(IDialogContext context, IAwaitable<IMessageActivity> activity)
    {
        try
        {
            await base.MessageReceived(context, activity);
        }
        catch(HttpRequestException e)
        {
            // Handle error here
            //await context.PostAsync("Error: " + e.ToString());
            context.Wait(this.MessageReceived);
        }
    }
}

Upvotes: 1

Anita George
Anita George

Reputation: 1153

A simple approach would be to check the length of your message in the MessageController and decide whether you want to process it or not.

 public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
 {
    if (activity.Type == ActivityTypes.Message)
    {
        MicrosoftAppCredentials.TrustServiceUrl(activity.ServiceUrl);
        var connector = new ConnectorClient(new Uri(activity.ServiceUrl));

        if (activity.Text != null && activity.Text.Length > 200)
        {
                var errorReply = activity.CreateReply();
                errorReply.Text = "Well well, that is too much of data. How about keeping it simple? How can I help you?";
                await connector.Conversations.ReplyToActivityAsync(errorReply);
        }
        else
        {

               await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
        }
    }
}

Upvotes: 1

Related Questions