Get Teams Graph API id from bot framework request
Asked Answered
L

1

1

Bot framework .Activity.TeamsGetTeamInfo().Id Docs gives Ids in the format of 19:[email protected], but Graph API takes Ids in the form of GUIDs 1be44bc0-02cb-4715-9ecc-cba191e64cb5 Docs.

Graph API will return the "InternalId" which matches the Bot Framework, but how do I get the GUID from the Bot framework request?

I just want to do simple stuff like invite people to a team, create/delete teams/channels.

The Request to the server does not include the info, so DialogContext.Activity.TeamsGetTeamInfo().AadGroupId is useless:

{
    "text": "<at>TestBot</at> help\n",
    "textFormat": "plain",
    "attachments": [
        {
            "contentType": "text/html",
            "content": "<div><div><span itemscope=\"\" itemtype=\"http://schema.skype.com/Mention\" itemid=\"0\">TestBot</span> help</div>\n</div>"
        }
    ],
    "type": "message",
    "timestamp": "2022-05-26T06:33:49.1002055Z",
    "localTimestamp": "2022-05-26T13:33:49.1002055+07:00",
    "id": "165354145676828864",
    "channelId": "msteams",
    "serviceUrl": "https://smba.trafficmanager.net/emea/",
    "from": {
        "id": "29:1d9mrAWL8cZKs3gp4Pasd8WD771EhsE1tlCs_MQn1Rb5QTmzk71GK934z8sxyHBE0eRFhWf-YslJXt_HdNDag",
        "name": "MyName",
        "aadObjectId": "guid-guid-guid-guid-guid"
    },
    "conversation": {
        "isGroup": true,
        "conversationType": "channel",
        "tenantId": "guid-guid-guid-guid-guid",
        "id": "19:[email protected];messageid=1653026739856"
    },
    "recipient": {
        "id": "28:guid-guid-guid-guid-guid",
        "name": "TestMyBot2343456345656367"
    },
    "entities": [
        {
            "mentioned": {
                "id": "28:guid-guid-guid-guid-guid",
                "name": "TestBot"
            },
            "text": "<at>TestBot</at>",
            "type": "mention"
        },
        {
            "locale": "en-US",
            "country": "US",
            "platform": "Windows",
            "timezone": "here",
            "type": "clientInfo"
        }
    ],
    "channelData": {
        "teamsChannelId": "19:[email protected]",
        "teamsTeamId": "19:[email protected]",
        "channel": {
            "id": "19:[email protected]"
        },
        "team": {
            "id": "19:[email protected]"
        },
        "tenant": {
            "id": "guid-guid-guid-guid-guid"
        }
    },
    "locale": "en-US",
    "localTimezone": "here"
}
Liquid answered 17/5, 2022 at 7:48 Comment(8)
Could you please elaborate your requirement and share the repro steps, so that we can try it from our end.Alwitt
@Alwitt I thought I made it quite clear. DialogContext.Activity.TeamsGetTeamInfo().Id gives an id like 19:[email protected]. Graph API requires GUIDs graph.microsoft.com/v1.0/teams/GUID, any attempt to use the 19:.. gives an error that it requires a valid GUID.Liquid
Can you please use DialogContext.Activity.TeamsGetTeamInfo().AadGroupId Ref Doc- learn.microsoft.com/en-us/dotnet/api/…Alwitt
{ "id": "19:[email protected]", "name": null, "aadGroupId": null }Liquid
@Alwitt I included the full request from teams to my server above.Liquid
@Cine-Are you looking for this-learn.microsoft.com/en-us/graph/api/… In the channelIdentity section you will get the teams id as mention above- "channelIdentity": { "teamId": "fbe2bf47-16c8-47cf-b4a5-4b9b187c508b", "channelId": "19:[email protected]" },Alwitt
@Alwitt that one still requires me to know the team guid, which is exactly what i am trying to get.Liquid
@Alwitt I found the solution, as you can see in my answer below.Liquid
L
2

It seems DialogContext.Activity.TeamsGetTeamInfo() only returns the information given from the payload, and the default from Teams is to NOT include the AadGroupId.

There is however an 'active' version of the same await TeamsInfo.GetTeamDetailsAsync(dc.Context). This will return the full object.

Liquid answered 2/6, 2022 at 8:8 Comment(2)
Thanks, this helped me a lot!Gast
It is worth mentioning, that this won't work from within the Bot Framework. It takes a real Teams App context, or the call will fail.Folium

© 2022 - 2024 — McMap. All rights reserved.