Power Automate: Retrieve teamId and channelId from Teams Trigger
In an effort to reduce the number of edits a user would have to make when importing a Power Automate Flow which responds automatically to a new Teams message, I wanted to retrieve the Team ID and the Channel ID to use later in the Flow.
There were a number of available solutions (e.g. Solved: Re: Get Teams name and Teams Channel - Power Platform Community) however they all seemed to use a complex expression to get the required information.
Looking at the raw information provided by the trigger (add the trigger to a Flow, run it, then examine the run history to retrieve the raw data) showed that it should be possible to retrieve the information required without using a complex expression. Here’s the information in the trigger header and body:
{
"headers": {
"Transfer-Encoding": "chunked",
"Vary": "Accept-Encoding",
"Strict-Transport-Security": "max-age=31536000",
"request-id": "25417c44-XXXX-XXXX-XXXX-1795a8963e18",
"client-request-id": "25417c44-XXXX-XXXX-XXXX-1795a8963e18",
"x-ms-ags-diagnostic": "{\"ServerInfo\":{\"DataCenter\":\"UK South\",\"Slice\":\"E\",\"Ring\":\"3\",\"ScaleUnit\":\"003\",\"RoleInstance\":\"LO2PEPF00000033\"}}",
"Preference-Applied": "odata.track-changes",
"OData-Version": "4.0",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "true",
"retry-after": "180",
"Date": "Tue, 03 Aug 2021 19:19:38 GMT",
"Location": "https://uk-001.azure-apim.net/apim/teams/…/trigger/beta/teams/channels/ $deltatoken~…",/messages?%24top=50&triggerState=
"Content-Type": "application/json",
"Content-Length": "1439"
},
"body": {
"@odata.type": "#microsoft.graph.chatMessage",
"etag": "…",
"messageType": "message",
"createdDateTime": "2021-08-03T19:15:19.411Z",
"lastModifiedDateTime": "2021-08-03T19:15:19.411Z",
"importance": "normal",
"locale": "en-us",
"webUrl": https://teams.microsoft.com/l/message/1628018119411?groupId= ,&tenantId= &createdTime=1628018119411&parentMessageId=162XXXX11XXXX
"id": "…",
"from": {
"user": {
"id": "…”,
"displayName": "Andy Dawson",
"userIdentityType": "aadUser"
}
},
"body": {
"contentType": "text",
"content": "This is another test, this time to see if the variable I need is directly readable..."
},
"channelIdentity": {
"teamId": "",
"channelId": ""
},
"attachments": [],
"mentions": [],
"reactions": []
}
}
From this, the expressions to retrieve the TeamID and ChannelID are respectively:
- triggerBody()?['channelIdentity/teamId']
- triggerBody()?['channelIdentity/channelId']