Search code examples
botswarningsdelaymicrosoft-teamsrest

MS Teams Chat Bot - Unable to reach app. Please try again


I am calling a third party REST API in MS Teams Bot on a particular input form user in the chat bot. Sometimes, the third party REST API response time is slower than usual. In such cases. MS Teams show the following message to the user with a Red color warning icon - "Unable to reach app. Please try again." Within few seconds of the Red color warning, the Teams however shows the correct data returned by the API successfully in the chat windows.

How do I handle such scenarios ("red warning") gracefully in the Teams Chat Bot caused by delay caused by calls to external REST APIs. Is there any time-out value in Microsoft Teams App that I have to modify to eliminate this kind of Warnings ?

Thanks!


Solution

  • There is a 10 or 15 second timeout that can occur, and if it does then I think that would cause what you're seeing. See more at https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-long-operations-guidance?view=azure-bot-service-4.0 where it states:

    If the bot does not complete the operation within 10 to 15 seconds, depending on the channel, the Azure Bot Service will timeout and report back to the client a 504:GatewayTimeout, as described in How bots work.

    In a nutshell, a simple approach could be:

    1. have your bot send a message back instantly
    2. queue the long-running operation on a queue somewhere (e.g. Azure), with a background processor to deal with it (e.g. Azure Function)
    3. when the operation completes, have the background processor send a pro-active message

    The example in the article gives some guidance a sample to handle a long-running operation like this, using another approach with dialogs etc.

    Update: This might actually give some useful background on the conversation, so see how the proactive messaging would fit in: https://hilton.giesenow.com/how-bot-calls-actually-work

    Update 2: Here's a relatively recent sample for proactive messaging, hopefully it's useful: https://github.com/pnp/teams-dev-samples/tree/master/samples/bot-proactive-messaging