Getting Bad Request and Forbidden when sending Notifications in MS teams Bot framework

Viewed 834

I am sending the notification to around 50k users, and I noticed two different errors are getting logged in error logs for very few users.

The two errors are

Operation returned an invalid status code 'Forbidden'

Operation returned an invalid status code 'BadRequest'

I am not able to understand why this error coming for only few users.

I have tried one way, where I blocked my bot and send a notification to myself then Forbidden error got logged.

Is there any other reasons why these two error occurs while sending the message to the users.

Edit:- For Forbidden error at Microsoft.Bot.Connector.Conversations.SendToConversationWithHttpMessagesAsync(String conversationId, Activity activity, Dictionary 2 customHeaders, CancellationToken cancellationToken)at Microsoft.Bot.Connector.ConversationsExtensions.SendToConversationAsync(IConversations operations, String conversationId, Activity activity, CancellationToken cancellationToken)

For BadRequest:- at Microsoft.Bot.Connector.Conversations.CreateConversationWithHttpMessagesAsync(ConversationParameters parameters, Dictionary2 customHeaders, CancellationToken cancellationToken) at Microsoft.Bot.Connector.ConversationsExtensions.CreateConversationAsync(IConversations operations, ConversationParameters parameters, CancellationToken cancellationToken)

Thanks.

2 Answers

Try using Microsoft.Bot.Builder 4.10.2

Microsoft recently released updates bo the Bot.Builder library. I've seen errors like this with the PowerBI API Library when not using a recent version.

https://www.nuget.org/packages/Microsoft.Bot.Builder/4.10.2

You could also try to add the following before the call to CreateConversationAsync():

MicrosoftAppCredentials.TrustServiceUrl(ServiceUrl, DateTime.MaxValue);

https://docs.microsoft.com/en-us/dotnet/api/microsoft.bot.connector.authentication.appcredentials.trustserviceurl?view=botbuilder-dotnet-stable

  1. The message "Operation returned an invalid status code 'Forbidden'" is returned whenever a user proactively blocks the bot contact (e.g. right click the contact or app in Teams -> "Block"). In such case, the channel logs in the Azure portal should also report the message: "User blocked the conversation with the bot".

  2. The message "Operation returned an invalid status code 'BadRequest'" is trickier to be solved; in my experience, it is generally related to some payload that is not supported by the Teams channel: e.g. an unsupported property in an AdaptiveCard, or an improperly formatted URL in an OpenUrl action. My suggestion is to test any AdaptiveCard content by using the Card Editor in the App Studio Teams application, before posting it to real conversations. It might be quite tricky to find what's causing the issue, otherwise.

Related