5
votes

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}"
        }
    }
}  
4
What is the base class of your bot?Hilton Giesenow
@HiltonGiesenow TeamsActivityHandlerCorv1nus

4 Answers

1
votes

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:[email protected]",
            "name": "[Group Name]",
            "aadGroupId": "[Guid]"
        },
        "eventType": "teamMemberAdded",
        "tenant": {
            "id": "[Guid]"
        }
    }
1
votes

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

1
votes

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.

0
votes

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>();
}