0

When trying to init a conversation and send a user a notification in Production, I receive the following error:

Microsoft.Bot.Schema.ErrorResponseException: Operation returned an invalid status code 'Forbidden'

Update: after further debugging, the message inside the error response exception reads:

The bot is not part of the conversation roster.

During local development connecting to a test app in MS Teams, it works fine. It also worked fine up until last Friday - then suddenly stopped with no code changes.


The code below was based on this example from Microsoft and it's intention is to send a welcome card to a user during the teamMembersAdded event. Am I doing anything wrong here?

// Retrieve and validate channel data
var channelData = turnContext.Activity.GetChannelData<TeamsChannelData>();
if (channelData.Team == null)
{
    logger.LogInformation("Not sending welcome card as Team in payload is null");
    return;
}

// Setup connector and trust url
MicrosoftAppCredentials.TrustServiceUrl(turnContext.Activity.ServiceUrl);
var connector = new ConnectorClient(new System.Uri(turnContext.Activity.ServiceUrl), _credentials);

// Starts new conversation in channel with welcome card
var conversationParameters = new ConversationParameters()
{
    IsGroup = true,
    ChannelData = new TeamsChannelData()
    {
        Channel = new ChannelInfo(channelData.Team.Id),
    },
    Activity = await CreateWelcomeCardTeamActivity(),
};
await connector.Conversations.CreateConversationAsync(conversationParameters);

Update 2: the bot works properly when added to an older team (one that was used for testing some time last year and earlier in this year) but not when added to any newer team.

The only difference seems to be that the older team uses the @thread.skype ID suffix whereas the new teams all use the @thread.tacv2 ID suffix.

Mike R
  • 110
  • 2
  • 10
  • Can you please verify if the bot Id and secret key are correct. Please check if the secret has expired. – Subhasish Jul 22 '20 at 11:27
  • 1
    Hi, yes the AppID and Password are both correct as every other action in our app still works. Only proactive messages fail (those that start conversations). Replying to users, running actions and creating tabs all still work. – Mike R Jul 23 '20 at 06:41
  • can you please check this link. https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-proactive-message?view=azure-bot-service-4.0&tabs=csharp#avoiding-401-unauthorized-errors – Nadeem Taj Jul 27 '20 at 07:32
  • Hi @NadeemTaj , you can see above that I indeed perform the step outlined in the link you sent. `MicrosoftAppCredentials.TrustServiceUrl(turnContext.Activity.ServiceUrl);` – Mike R Jul 27 '20 at 09:54
  • As a further update, I can confirm that this proactive messaging works on an old team but not on any new ones. It still works on the team that i used to test the bot on in production last year but not on any new teams that I create and add the bot to via app install. The only difference really is that the old team uses the `19:XXXXXXXXXXXXXXXXXX@thread.skype` ID format instead of the `19:XXXXXXXXXXXXXXXXXX@thread.tacv2` ID format. – Mike R Jul 27 '20 at 09:57
  • @Mike can you please do breakpoint a) var channelData = turnContext.Activity.GetChannelData(); and b) MicrosoftAppCredentials.TrustServiceUrl(turnContext.Activity.ServiceUrl); and provide screenshot? – Nadeem Taj Jul 27 '20 at 10:12
  • Also more appealing to your issue. 1) https://stackoverflow.com/questions/60392871/teams-updateactivity-events-difference-when-you-test-in-newly-created-teams 2) https://stackoverflow.com/questions/60801497/sending-proactive-messages-to-a-channel-in-teams – Nadeem Taj Jul 27 '20 at 10:26
  • @NadeemTaj I can't breakpoint it because as I wrote, this error doesn't occur when I run the code locally with the bot set to my local environment. Only in production. – Mike R Jul 27 '20 at 11:15
  • The Trace activity is an activity which the developer inserts in to the stream of activities to represent a point in the developers bot logic. The trace activity typically is logged by transcript history components to become part of a Transcript-format history file. In remote debugging scenarios the Trace activity can be sent to the client so that the activity can be inspected as part of the debug flow. – Nadeem Taj Jul 28 '20 at 07:38
  • https://learn.microsoft.com/en-us/azure/bot-service/using-trace-activities?view=azure-bot-service-4.0&tabs=csharp – Nadeem Taj Jul 28 '20 at 07:44
  • Which verson of the sdk are you using exactly? – Eric Dahlvang Jul 29 '20 at 14:42
  • @EricDahlvang 4.9.4 using the Microsoft.Bot.Builder package – Mike R Aug 03 '20 at 12:25
  • Could you please send out an email to [Microsoft Teams developer support](microsoftteamsdev@microsoft.com) so that we can setup a call to check this? – Subhasish Aug 24 '20 at 05:20

0 Answers0