Top
Photo by Jason Goodman on Unsplash

How to mention tags, users, channels and teams using Power Automate


In this post I would like to share with you my latest findings about the ways you can mention actually anything in Microsoft Teams in messages sent from Power Automate, whether it is a user, a tag, a channel or a team.

Built-in mentioning

In Power Automate there are dedicated actions to let you mention a user or a tag.

@mention actions in Power Automate

The “Get an @mention token for a user” and “Get an @mention token for a tag”. These two actions return tokens, that can be used in any other action that sends message to Microsoft Teams, like “Post adaptive card in a chat or channel”, or “Post message in a chat or channel”:

Post messages action in Power Automate

Important! The @mention token for a tag can only be used when an adaptive card or a message is posted using user context. It will not work using bot context.

You just need to add the tokens into your cards or messages:

@mention token and generated Adaptive Card

Mentioning using msteams property in Adaptive Card JSON

The second approach you can use is to benefit from msteams property that can be added at the end of an adaptive card sent to Microsoft Teams. By the way – this property can help in many other scenarios (source: Text formatting in cards – Teams | Microsoft Docs).

Mentioning using msteams property in Adaptive Card JSON

Why would you do it this way not through the @mention actions, I don’t know, however I need to emphasize, that this way I wasn’t able to mention tags, channels and teams. Although a “link” to a channel was displayed on a sent card, it didn’t behave as one, because hovering did not expand channel details.

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.4",
    "body": [
        {
            "type": "TextBlock",
            "id": "MentionTextBlock",
            "text": "Fun with mentions!",
            "weight": "Bolder",
            "size": "Medium"
        },
        {
            "type": "TextBlock",
            "text": "This is user mention. Hi: <at>USER NAME</at>!",
            "size": "Medium"
        }
        {
            "type": "TextBlock",
            "text": "And this mentions tag <at>TAG NAME</at>!",
            "size": "Medium"
        },
        {
            "type": "TextBlock",
            "text": "This is channel mention. Hello: <at>CHANNEL NAME</at>!",
            "size": "Medium"
        }
    ],
    "msteams": {
        "entities": [
            {
                "type": "mention",
                "text": "<at>USER NAME</at>",
                "mentioned": {
                    "id": "8:orgid:USER AAD ID",
                    "name": "USER NAME"
                }
            }
            {
                "type": "mention",
                "text": "<at>TAG NAME</at>",
                "mentioned": {
                    "id": "TAG ID",
                    "name": "TAG NAME"
                }
            },
            {
                "type": "mention",
                "text": "<at>CHANNEL NAME</at>",
                "mentioned": {
                    "id": "CHANNEL ID",
                    "displayName": "CHANNEL NAME",
                    "conversationIdentityType": "channel"
                }
            }
        ]
    }
}

Important! To mention a user you must prefix its AAD ID with the 8:orgid: value.

What is also important is that I was only able to use the above method when sending card using bot context. When using user context, action was constantly ending with an error: “Message mention text needs to be specified.” and no matter how I was formatting mention objects, it couldn’t be resolved. So I gave up. If you know how to make it work, please write down in comments 🙂

Mentioning using channel’s webhook

First, to create a webhook to a channel you need to navigate to “Connectors” menu within a channel:

Connectors menu in channel

And then configure a webhook, and copy its URL. Once that is done, you can use and configure the HTTP action:

How to send Adaptive Card via channel's webhook

It has to be a POST request to channel’s webhook. And about the contents:

{
    "type": "message",
    "attachments": [
      {
        "contentType": "application/vnd.microsoft.card.adaptive",
        "content": {
          "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
          "type": "AdaptiveCard",
          "version": "1.4",
          "body": [
            {
              "type": "TextBlock",
              "id": "MentionTextBlock",
              "text": "Fun with mentions!",
              "weight": "Bolder",
              "size": "Medium"
            },
            {
              "type": "TextBlock",
              "text": "This is user mention. Hi: <at>USER NAME</at>!",
              "size": "Medium"
            },
            {
              "type": "TextBlock",
              "text": "And this mentions tag <at>TAG NAME</at>!",
              "size": "Medium"
            },
            {
              "type": "TextBlock",
              "text": "This is channel mention. Hello: <at>CHANNEL NAME</at>!",
              "size": "Medium"
            }
          ],
          "msteams": {
            "entities": [
              {
                "type": "mention",
                "text": "<at>USER NAME</at>",
                "mentioned": {
                  "id": "8:orgid:USER AAD ID",
                  "name": "USER NAME"
                }
              },
              {
                "type": "mention",
                "text": "<at>TAG NAME</at>",
                "mentioned": {
                  "id": "TAG ID",
                  "name": "TAG NAME"
                }
              },
              {
                "type": "mention",
                "text": "<at>CHANNEL NAME</at>",
                "mentioned": {
                  "id": "CHANNEL ID",
                  "displayName": "CHANNEL NAME",
                  "conversationIdentityType": "channel",
                  "conversationIdentityType@odata.type": "#Microsoft.Teams.GraphSvc.conversationIdentityType"
                }
              }
            ]
          }
        }
      }
    ]
  }

Here again, as you see, the msteams property is used. In this approach all mentions are being generated.

Mentions sent using team's channel webhook

Despite that in my opinion they don’t work. Because when I hover any of them, it doesn’t display any details also message is not highlighted as mentioning me. If it works for you, please let me know.

Important! Adaptive Cards sent through webhooks won’t allow you to perform any submit actions. So if you plan to add form to the card that users could fill and send, with this approach you won’t be able to receive responses.

Mentioning using GraphAPI

With this approach you are able to send Adaptive Card to GraphAPI /beta/teams/team-id/channels/channel-id/messages endpoint. More details about this approach can be found here: Send chatMessage in a channel or a chat – Microsoft Graph beta | Microsoft Docs.

I am doing this using the action called “Send an HTTP request” from “Office 365 Groups” stack of actions. Why? Because this action is standard one, so does not require additional license. You are able to achieve the same using “Invoke an HTTP Request” from “HTTP with Azure AD” stack of actions. However this one is a premium action.

Sending Adaptive Card with mentions through GraphAPI

The code that has to be sent is built from the following sections:

  1. Body – it contains an HTML structure, including a placeholder for attachment, that will be an adaptive card in this case.
  2. Attachments – this property contains an escaped Adaptive Card JSON.
  3. Mentions – this property contains mentions objects per each mention id present in either Adaptive Card content or within the Body -> Content property itself.
{
    "subject": "Adaptive Cards test",
    "body": {
        "contentType": "html",
        "content": "<attachment id=\"AttachmentID\"></attachment>"
    },
    "attachments": [
        {
            "id": "AttachmentID",
            "contentType": "application/vnd.microsoft.card.adaptive",
            "contentUrl": null,
            "content": "{\r\n  \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\",\r\n  \"type\": \"AdaptiveCard\",\r\n  \"version\": \"1.4\",\r\n  \"body\": [\r\n    {\r\n      \"type\": \"TextBlock\",\r\n      \"id\": \"MentionTextBlock\",\r\n      \"text\": \"Fun with mentions!\",\r\n      \"weight\": \"Bolder\",\r\n      \"size\": \"Medium\"\r\n    },\r\n    {\r\n      \"type\": \"TextBlock\",\r\n      \"text\": \"This is user mention. Hi: <at id=\\\"0\\\">USER NAME</at>!\",\r\n      \"size\": \"Medium\"\r\n    },\r\n    {\r\n      \"type\": \"TextBlock\",\r\n      \"text\": \"This is channel mention. Hello: <at id=\\\"1\\\">CHANNEL NAME</at>!\",\r\n      \"size\": \"Medium\"\r\n    },\r\n    {\r\n      \"type\": \"TextBlock\",\r\n      \"text\": \"This is team mention. Hello: <at id=\\\"2\\\">TEAM NAME</at>!\",\r\n      \"size\": \"Medium\"\r\n    },\r\n    {\r\n      \"type\": \"TextBlock\",\r\n      \"text\": \"This mentions tag <at id=\\\"3\\\">TAG NAME</at>!\",\r\n      \"size\": \"Medium\"\r\n    }\r\n  ]\r\n}",
            "name": null,
            "thumbnailUrl": null
        }
    ],
    "mentions": [
        {
            "id": 0,
            "mentionText": "USER NAME",
            "mentioned": {
                "user": {
                    "id": "USER AAD ID",
                    "displayName": "USER NAME",
                    "userIdentityType": "aadUser"
                }
            }
        },
        {
            "id": 1,
            "mentionText": "CHANNEL NAME",
            "mentioned": {
                "conversation": {
                    "id": "CHANNEL ID",
                    "displayName": "CHANNEL NAME",
                    "conversationIdentityType": "channel"
                }
            }
        },
        {
            "id": 2,
            "mentionText": "TEAM NAME",
            "mentioned": {
                "conversation": {
                    "id": "TEAM ID",
                    "displayName": "TEAM NAME",
                    "conversationIdentityType": "team"
                }
            }
        },
        {
            "id": 3,
            "mentionText": "TAG NAME",
            "mentioned": {
                "tag": {
                    "id": "TAG ID",
                    "displayName": "TAG NAME"
                }
            }
        }
    ]
}

This way it is possible to really mention anything and it works for all types of tags. And that is because the action works in a context of the user, if you would like to send it in a context of an application, you will need to use the HTTP action and there provide Azure AD app details to authenticate the call.

Adaptive Card with mentions sent via GraphAPI

Important! Adaptive Cards sent this way will not allow you to perform submit actions. If you plan to allow users to submit forms sent in Adaptive Cards, you need to choose another approach.

And that’s it! I really hope you find it useful.

Further reading

Some useful links that helped me better understand how to mention in Microsoft Teams:


Tomasz Poszytek

Hi, I am Tomasz. I am expert in the field of process automation and business solutions' building using Power Platform. I am Microsoft MVP and Nintex vTE.

15 Comments
  • Ricky

    Is it possible to use @Channel with Teams webhook, without using Flow/Automate ? Seems like it’s not possible at the moment? – https://docs.microsoft.com/en-us/answers/answers/943653/view.html

    July 27, 2022 at 4:21 am Reply
    • Tomasz Poszytek

      Hi, I unfortunately don’t know answer to this question.

      October 3, 2022 at 1:13 pm Reply
  • Maciej

    Hey Tomasz,
    Long time no speak 🙂
    Thanks for great tutorial! In the past I faced some issues when tried to send AC with channel mention and after a while I noticed that it’s not support by MS (https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cconnector-html#mention-support-within-adaptive-cards). I’ve tried your way but no luck (Power Automate Flow Bot is posting AC but there is no channel mention there, on the other hand Logic App is returning 400 with message: One or more mention entity could not be found in card text). Of course body and schema is exactly the same.

    So…. how did you do that? How it’s possible that on your end it’s working fine. I’ve used your example (copy-paste) and it wasn’t worked for me.

    Thanks Maciej!

    August 5, 2022 at 8:33 am Reply
    • Tomasz Poszytek

      Hi Maciej, are you using the “Send an HTTP request” from “Office 365 Groups”? Because I was able to really mention a channel only by using this action.

      October 3, 2022 at 1:56 pm Reply
  • Jakub

    Hi
    I have an error at “Send an HTTP request” from “Office 365 Groups” it returns an error: URI path is not a valid Graph endpoint, path is neither absolute nor relative or resource/object is not supported for this connector. Resources: groups. Uri: https://graph.microsoft.com/v1.0/teams/aff2bbe5-07f9-4798-9d6e-a7f612f8da9c/channels/19:e574234b882e440daf9fbac9616b50df@thread.tacv2/messages
    Could you help me?

    August 11, 2022 at 9:07 pm Reply
  • Mike Collins

    Hey Tomasz,

    Excellent article, followed it to the letter and it all worked amazingly. I have a question though… I was previously posting adaptive cards, using the [Post card in a chat or channel] action, using the Post As – Flow Bot. Using this approach I cant @mention Teams or Channels, hence why I’m looking at your article. However, when I implement your approach, my posts come directly from my account. Is it possible to adapt you graph api call to mimic posting as a flow bot? Cheers

    March 15, 2023 at 11:58 pm Reply
    • Tomasz Poszytek

      Nope. Graph API, at least those calls, need delegated permissions. So they will be always posted in a context of am account that triggers the action. You could create a “service account” that is called whatever “company bot” and then use it to post cards.

      April 4, 2023 at 9:22 pm Reply
  • Telkom Jakarta

    Are there any security considerations to keep in mind when implementing the mention feature in Power Automate?

    June 23, 2023 at 2:34 pm Reply
    • Tomasz Poszytek

      I honestly can’t think of any. This is just a GET request, so no harm can be made, I guess?

      June 29, 2023 at 10:48 am Reply
  • Dan Mc

    Hi Tomasz, I tried your method and my mention looks like this in the content, but it just displays it as normal Text and not a mention?

    General

    My mention has the correct ID, channel name and display names too. Any ideas?

    February 15, 2024 at 1:49 pm Reply
    • Tomasz Poszytek

      It’s really difficult to say 🙁 What are you trying to mention?

      February 24, 2024 at 10:48 pm Reply
  • Perry Andrews

    Using your second method “MENTIONING USING MSTEAMS PROPERTY IN ADAPTIVE CARD JSON” it is possible to mention tags in my experience. If you specify the “type”: “tag” then the notifications work as expected.

    {
    “type”: “mention”,
    “text”: “TAG NAME”,
    “mentioned”: {
    “id”: “TAG ID”,
    “name”: “TAG NAME”,
    “type”: “tag”
    }
    },

    I haven’t tried this for channels and teams. But will be testing in the near future

    March 5, 2024 at 11:49 am Reply

Post a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.