Search code examples
c#botframeworkmicrosoft-teams

Sending Typing activity in Teams bot fails - BadGateway


I am pretty confident this is caused by Teams engineers screwing something up again, but might be worth a try...

Using Microsoft.Bot.Builder 4.8.0

I's a pretty simple problem actually. When called from Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken),
the following code:

await turnContext.SendActivityAsync(typing).ConfigureAwait(false);

causes the following exception:

Operation returned an invalid status code 'BadGateway'

with the following stack trace:

at Microsoft.Bot.Connector.Conversations.<ReplyToActivityWithHttpMessagesAsync>d__10.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Bot.Connector.ConversationsExtensions.<ReplyToActivityAsync>d__17.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at Microsoft.Bot.Builder.BotFrameworkAdapter.<SendActivitiesAsync>d__34.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.TurnContext.<>c__DisplayClass25_0.<<SendActivitiesAsync>g__SendActivitiesThroughAdapter|1>d.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.Bot.Builder.TurnContext.<SendActivityAsync>d__24.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Blabla.<OnMessageActivityAsync>d__4.MoveNext() in path\to\blabla.cs:line xx

Replying with text messages works fine.

Oh and just in case, if you are wondering if I tried to use ShowTypingMiddleware to display "typing" indicator, sure, tried that too, but the indicator is never shown. I did that by adding Use(new ShowTypingMiddleware(1000)); to my BotFrameworkHttpAdapter constructor, which is registered to DI container as singleton. It's just that, it does nothing.


Solution

  • Have a look at the Microsoft Teams: Developer Blog; API outage: Bots posting typing indicators may receive 502s.

    As a part of our commitment to customers and Microsoft cloud services continuity during these unprecedented times, we’re making temporary adjustments to select capabilities within Microsoft 365. One of those adjustments is that we are temporarily scaling back typing indicators support in Teams. As a result bots posting typing indicators to users in the Europe region using any of the following values for ServiceUrl may receive errors and users may not see the typing indicators sent by bots.

    Currently the guidance in the post above is:

    As a bot developer, you may either modify your code to not use typing indicators for now, or ignore the errors encountered while sending typing indicators.