MoreBeerMorePower

Power Platform中心だけど、ノーコード/ローコード系を書いてます。

Post a teams message with Tag mention from Power Automate

Posting a teams channel message with Tag mention is achieved using Graph API via flow with following Url

https://graph.microsoft.com/v1.0/teams/<teamId>/channels/<channelId>/messages

and request body (See Ref. Mention a tag with a flow – Expiscornovus from Dennis )

{
    "body": {
        "content": "Test message <at id=\"0\">SomeTagName</at>. ",
        "contentType": "html"
    },
    "mentions": [
        {
            "id": 0,
            "mentionText": "SomeTagName",
            "mentioned": {
                "tag": {
                    "id": "YABCDEFk5N2EtNjQzZC00MDA3LWEyZTUtNmVjOWM1YWI4NWNiIyM3ODdkMzVhMC0yZWU1LTQ5YzYtYWVkZC1mZDkzYmM0NDlkZDEjI3RrSU1TdGNpMg==",
                    "displayName": "SomeTagName"
                }
            }
        }
    ]
}

Mention block in content <at ...>...</at>, mentionText , and displayName of Tag are easily obtained from Teams UI - name of Tag.

The last piece to build a request body is id of Tag (YABC...kjI3RrSU1TdGNpMg==).

In this post, I will show how to dynamically generate this ID and post message with Tag mention in Power Automate.

How to get Tag IDs via Teams API

As Damien shared in his blog post (Teams Status Update via Power Automate - DamoBird365), undocumented Teams API can be called from Power Automate by leveraging "Send HTTP request to SharePoint" action.

Tag IDs are also retrieved through Teams API with following Url:

GET https://teams.microsoft.com/api/csa/api/v1/teams/<General Channel ID>/tagCards?tagType=any

Response body contains detail information about Tag in given team.

{
  "tagCards": [
    {
      "tagId": "tkIMAtci2",
      "tagName": "Test Tag",
      "memberIds": [
        "8:orgid:b8bc1234-c929-4b08-8228-7109ee7b4545",
        "8:orgid:55551347-6623-4fb3-9694-1d411f03ae5d"
      ],
      "memberCount": 2,
      "tagType": "team",
      "currentMemberIsPartOfTag": true,
      "scheduledMembers": [],
      "version": 1
    }
  ],
  "teamTagSettings": {
    "onlyOwnersCanUpdate": true,
    "tagCount": 1,
    "disallowedSources": [],
    "version": 1
  }
}

This response body does indeed contain a "tagId", but it is easy to see that this is not what we expect (like YABC...kjI3RrSU1TdGNpMg==).

Actually, this "tagId" is part of the lengthy id needed for the mention, which needs to be reformatted into the following and further base64 encoded.

base64('<tenantId>##<teamId>##<tagId>')

Flow seup

The flow retrieving Tag ID via API and building TagID includes several Compose action to define TenantID, TeamID, ChannelID, TagName, and TagID.

f:id:mofumofu_dance:20211013000127p:plain
Flow

If you want to try this flow, you can download sample flow from my github repo 👇

github.com

Please replace each IDs and Tag name with your environment's.

That's all!

f:id:mofumofu_dance:20211013002857p:plain