OfficeDev / microsoft-teams-apps-company-communicator

Company Communicator app template
MIT License
329 stars 400 forks source link

Failing to send to members of Teams, Microsoft.Bot.Schema.ErrorResponseException: Operation returned an invalid status code 'Forbidden' #852

Closed captainhook closed 2 years ago

captainhook commented 2 years ago

I have updated to 5.2 however I am getting this error when I attempt to send to members of a Team where I am the only member. Please note that I may have removed the Company Communicator Users app from my Teams profile prior to the upgrade.

User ID UPN Name User Type Delivery Status Status Reason Error
8fc300d9-ef29-4e6d-9091-6afd6c369521 x@x.com John Doe Member Failed 403 : Failed "Microsoft.Bot.Schema.ErrorResponseException: Operation returned an invalid status code 'Forbidden'
at Microsoft.Bot.Connector.Conversations.ReplyToActivityWithHttpMessagesAsync(String conversationId, String activityId, Activity activity, Dictionary2 customHeaders, CancellationToken cancellationToken)<br> at Microsoft.Bot.Connector.ConversationsExtensions.ReplyToActivityAsync(IConversations operations, String conversationId, String activityId, Activity activity, CancellationToken cancellationToken)<br> at Microsoft.Bot.Builder.BotFrameworkAdapter.SendActivitiesAsync(ITurnContext turnContext, Activity[] activities, CancellationToken cancellationToken)<br> at Microsoft.Bot.Builder.TurnContext.<>c__DisplayClass31_0.<<SendActivitiesAsync>g__SendActivitiesThroughAdapter|1>d.MoveNext()<br>--- End of stack trace from previous location where exception was thrown ---<br> at Microsoft.Bot.Builder.TurnContext.SendActivityAsync(IActivity activity, CancellationToken cancellationToken)<br> at Microsoft.Teams.Apps.CompanyCommunicator.Common.Services.Teams.MessageService.<>c__DisplayClass3_1.<<SendMessageAsync>b__1>d.MoveNext() in D:\home\site\repository\Source\CompanyCommunicator.Common\Services\Teams\Messages\MessageService.cs:line 94<br>--- End of stack trace from previous location where exception was thrown ---<br> at Polly.Retry.AsyncRetryEngine.ImplementationAsync[TResult](Func3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates1 shouldRetryResultPredicates, Func5 onRetryAsync, Int32 permittedRetryCount, IEnumerable1 sleepDurationsEnumerable, Func4 sleepDurationProvider, Boolean continueOnCapturedContext)
at Polly.AsyncPolicy.ExecuteAsync[TResult](Func`3 action, Context context, CancellationToken cancellationToken, Boolean continueOnCapturedContext)
at Microsoft.Teams.Apps.CompanyCommunicator.Common.Services.Teams.MessageService.<>c__DisplayClass3_0.<b__0>d.MoveNext() in D:\home\site\repository\Source\CompanyCommunicator.Common\Services\Teams\Messages\MessageService.cs:line 94"

I managed to fix this by installing the 'Company Communicator' (users) app on my Teams, however should this not be happening proactively? I do have 'ProactivelyInstallUserApp' set to 'true'.

If I remove the user app from my Teams profile, Company Communicator should just reinstall it for me, should it not?

captainhook commented 2 years ago

I did try to remove the row from UserData table where my AadId is present to see if that would cause Company Communicator to trigger a reinstall of the user app for me, but it seems that didn't work.

gsv022 commented 2 years ago

Hi @captainhook , Thanks for logging the issue. We will get back to you with proper response soon.

gsv022 commented 2 years ago

Hi @captainhook , Could you please upload the user app at the tenant level and try sending messages.

captainhook commented 2 years ago

Hi @captainhook , Could you please upload the user app at the tenant level and try sending messages.

Is it already uploaded at tenant level via Teams Admin Center: image

gsv022 commented 2 years ago

Hi @captainhook , Could you please share the MS teams Id so that we can discuss more on the issue over the call and will try to troubleshoot it.

captainhook commented 2 years ago

Thanks for the help, folks. It turns out the issue may have been that the 5.2 code didn't deploy to the App Service or I had removed the User App from my Teams profile. I've reinstalled the User App onto my Teams profile and synced 5.2 code on the App Service - all working perfectly now.