Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Botframework: how to handle long running tasks with a bot?

How do I handle a long running tasks on a bot so the client dosnt retry to send the message after 15 seconds again.

I got a bot with the botframework v3 and connect the client with directline

like image 892
Johnny Avatar asked Nov 01 '18 16:11

Johnny


1 Answers

The Direct Line channel connector itself does not retry sending messages. If it does not receive an ack within 15 seconds of sending a message to your bot, it will throw a Gateway Timeout.

If you are using the DirectLineClient, you can override the retry policy, ensuring the client does not retry messages:

DirectLineClientCredentials creds = new DirectLineClientCredentials(directLineSecret);
DirectLineClient directLineClient = new DirectLineClient(new Uri("https://directline.botframework.com"), creds);
directLineClient.SetRetryPolicy(new Microsoft.Rest.TransientFaultHandling.RetryPolicy(new Microsoft.Rest.TransientFaultHandling.HttpStatusCodeErrorDetectionStrategy(), 0));

If you have a long running process, that takes more than 15 seconds, consider queuing the message somewhere, so you can acknowledge the call immediately, then process the message on a background thread. This is conceptually called Proactive Messaging. More information can be found here: https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-proactive-messages?view=azure-bot-service-3.0

Edit: This blog post also explains one method for handling long operations within a bot, by using Azure Queue storage and an Azure Function which processes the operation and calls the bot when finished: Manage a long-running operation

Another option is to process incoming messages, or long processing messages, on a background thread. This experimental sample demonstrates some methods using this design: Immediate Accept Bot

like image 183
Eric Dahlvang Avatar answered Nov 13 '22 02:11

Eric Dahlvang