6

I'm installing a Teams bot and adding it to a team. When I add it to the team, on the initial call I get the "conversationUpdate" event correctly, in OnTurnAsync. The issue I'm running into is that any call to get the team itself is failing because there is nothing there, that I can see, for getting the Id to call to get the team data.

I want to be able to add it to the team, get that event and then get the data related to the team it was added to.

Here is what I'm trying.

        private const string ActOnType = "conversationUpdate";

        public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default)
        {
            if (IsConversationUpdate(turnContext))
            {
                // This fails because TeamsGetInfo is returning null
                var teamDetails = await TeamsInfo.GetTeamDetailsAsync(turnContext,  turnContext.Activity.TeamsGetTeamInfo().Id, cancellationToken);
            }
        }

        private bool IsConversationUpdate(ITurnContext turnContext) => string.Equals(turnContext.Activity.Type,
            ActOnType, StringComparison.InvariantCultureIgnoreCase);

Other notes...
turnContext.Activity.TeamsGetChannelId() is null, as is ChannelData. Any further calls have the channel data, but the initial one where I add the bot to the team does not have any.

Adding my JSON from the call

{
    "membersAdded": [
        {
            "id": "29:1HqtPeQvYpNL682R_NeBMndg6kYbZbBHsZliZdAT2xWsJWzS0_b50S1ijo2hmPu5i0HTrvqPiOBxqpbtJjS7zyja",
            "aadObjectId": "{valid guid}"
        },
        {
            "id": "28:{valid guid}"
        }
    ],
    "type": "conversationUpdate",
    "timestamp": "2021-01-11T18:15:49.9118003Z",
    "id": "f:{valid guid}",
    "channelId": "msteams",
    "serviceUrl": "https://smba.trafficmanager.net/amer/",
    "from": {
        "id": "29:1HqtPeQvYpNL682R_NeBMndg6kXaZbBHsZliZdAT2xWsJWzS0_gOS1ijo2hmPu5i0HTrvqPiOBxqpbtJjS6zyjA",
        "aadObjectId": "{valid guid}"
    },
    "conversation": {
        "conversationType": "personal",
        "tenantId": "{valid guid}",
        "id": "a:1UgWdBcfpF4JUtOCCjQZsvhjl-QK9YBBnALG7ACgA0QdKx_xGICsQ3d6l94t_pPed7fvtnwSnRlYcWe7kXT7dStP-YCtuvliI8GPZj9Sd5P2wHsBAAn1ibwdad4Lq-O3B"
    },
    "recipient": {
        "id": "28:{valid guid}",
        "name": "LocalBot"
    },
    "channelData": {
        "tenant": {
            "id": "{valid guid}"
        }
    }
}  
Corv1nus
  • 4,523
  • 1
  • 26
  • 37

4 Answers4

1

I'm looking at an old conversationUpdate log I have, and there's definitely a TeamId in there - I can't imagine it's been removed. You can check if you're working locally, by looking at the ngrok logs (http://127.0.0.1:4040). If it IS there, it might just not be populating onto the TeamsChannelData for some reason, but you should still be able to access it fine, directly, by accessing activity.ChannelData itself.

[Update] This is a sample from a old payload I saved from a some time in 2020:

"channelData": {
        "team": {
            "id": "19:02...55@thread.skype",
            "name": "[Group Name]",
            "aadGroupId": "[Guid]"
        },
        "eventType": "teamMemberAdded",
        "tenant": {
            "id": "[Guid]"
        }
    }
Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24
  • I've added my JSON from the call. Where it says {valid guid} is a valid GUID that I replaced. I don't see the usable TeamId. The f:GUID throws a Bad Request. Activity.ChannelData only has the tenant data. – Corv1nus Jan 11 '21 at 18:21
  • From and Recipient also throw the BadRequest – Corv1nus Jan 11 '21 at 18:27
  • 1
    Yeah that's definitely strange - see my updated answer with a sample payload. I don't know if something has changed in Teams, or if you're experiencing an issue with the payload. There are a number of people from Teams here on SO, so they might be able to look more into this behind the scenes. – Hilton Giesenow Jan 11 '21 at 19:19
  • 1
    I will try what @HiltonGiesenow suggested above; in past i tried in similar lines and it worked. But i hear that you're hearing a bad request, which is bad. You may want to use NGROK to see what's going there. In addition to this, i remember a [related older thread, but they use it differently](https://stackoverflow.com/questions/61632246/retrieve-teams-user-id-based-on-aad-id) to see if it helps. – Dev Jan 20 '21 at 16:20
1

You can find these channel data in OnMessageActivityAsync also. enter image description here

Jagadeesh-MSFT
  • 316
  • 1
  • 4
1

I'll post the answer here in case anyone comes into it...

You can only get this event once for when the bot was added to the team. If you miss it, you no longer get the data. Uninstalling and reinstalling the bot will not fire the event again. If you're still not getting it, the recommended action was to remove the app from Azure and re-do it with the same name.

See more on the github discussion

In our scenario, I decided that the limitations on this were not within the realm of what I considered a working solution and I decided to go down a different route for getting the team data. Since the data was coming through in events after this one, I grab it then and do what I need to do with it.

Corv1nus
  • 4,523
  • 1
  • 26
  • 37
0

Searched around a bit in the source code at https://github.com/microsoft/botbuilder-dotnet and found two things that indicate that there is no Channel in your turnContext.

Here's the code:

// Microsoft.Bot.Builder.Teams.TeamsActivityExtensions
public static TeamInfo TeamsGetTeamInfo(this IActivity activity)
{
    var channelData = activity.GetChannelData<TeamsChannelData>();
    return channelData?.Team;
}

// Microsoft.Bot.Schema.Activity
public TypeT GetChannelData<TypeT>()
{
    if (this.ChannelData == null)
    {
        return default(TypeT);
    }

    if (this.ChannelData.GetType() == typeof(TypeT))
    {
        return (TypeT)this.ChannelData;
    }

    return ((JObject)this.ChannelData).ToObject<TypeT>();
}


Christian
  • 1,250
  • 9
  • 12
  • That's my issue, that I'm hoping there is a way around. Any subsequent calls have the channel data, but the initial one where I add the bot to the team does not have any. – Corv1nus Jan 11 '21 at 16:17
  • 1
    We are checking internally with our team, will get back to you soon. – Rama-MSFT Jan 12 '21 at 10:09