BotBuilderCommunity / botbuilder-community-dotnet

Part of the Bot Builder Community Project. Repository for extensions for the Bot Builder .NET SDK, including middleware, dialogs, recognizers and more.
MIT License
278 stars 170 forks source link

Multiple responses from Slack adapter in Bot framework Composer #533

Open NeethithevanR opened 1 year ago

NeethithevanR commented 1 year ago

I use the Bot Builder community Slack adapter in my Bot service (using Bot Framework Composer v 2.1.2). And it is implemented using DOTNET(version 3.1). Currently, the issue I am facing is: when I trigger a message from my Bot channel to my Bot service, I receive multiple responses in my Bot channel. I looked at a few documents and worked around the issue using the "X-Slack-Retry-Num" request header coming along with slack API. But I feel that this is not a proper fix for the issue, as there could be genuine needs for retries later.

The workaround I made: string slackRetry = Request.Headers["X-Slack-Retry-Num"]; if (string.IsNullOrEmpty(slackRetry)){ await adapter.ProcessAsync(Request, Response, _bot).ConfigureAwait(false); }

Please let me know if there is a better fix for the issue above, which I believe is something to do with sending acknowledgement back to slack. This is something I am not able to figure out where and how to code. If possible, please refer some appropriate documentation to me.

martinlarosa commented 1 year ago

Hey! I believe it's something I ran into. This happens because the bot is not acknowledging the request in less than 3 seconds to slack.

Check this out: https://github.com/microsoft/botbuilder-dotnet/pull/5405 I had a fix that was never merged but I implemented it in a custom adapter.

NeethithevanR commented 1 year ago

@martinlarosa , Thank you for responding. I tried that fix. But its not working in my case.

paulio commented 1 year ago

@martinlarosa , Thank you for responding. I tried that fix. But its not working in my case.

Have you tried just immediately echoing a response in your bot? As previously stated it sounds like your bot just needs to send some sort of response but has gone quiet. IMO extending the timeout isn't a great solution, people have a very low threshold to waiting for some form of response

NeethithevanR commented 1 year ago

@martinlarosa , That fix you have made in https://github.com/microsoft/botbuilder-dotnet. But that repository was no longer active. So,I am using @botbuildercommunity .

martinlarosa commented 1 year ago

Check the code in the commit of my PR, it's very few lines of code. They never merged it to the other repo anyway. you can see their reasoning here: https://github.com/microsoft/BotFramework-Composer/issues/6484#issuecomment-817048812

There problem is that Slack needs the HTTP request to be acknowledged by the bot in less than 3 seconds. Otherwise it will start retrying. That's why you see multiple messages. This in my experience happens in 2 ways. The most common is doing some "heavy" processing or calling an API from the bot. If this takes more than 3 seconds then you run into this situation because the ACK of the HTTP call doesn't get back to slack until everything finishes. The other time when this happened to me was when running it locally on the first interaction, because Bot Framework took a bit of time to load up a bunch of things during the first interaction after launching it.

My solution was to not await the RunPipelineAsync call, and change the code so that it would run async. That way the bot can return the ACK to Slack, telling Slack that the message was received, while it's moving on doing it's own thing.