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.
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”:
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:
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).
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:
And then configure a webhook, and copy its URL. Once that is done, you can use and configure the HTTP action:
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”,
“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.
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.
The code that has to be sent is built from the following sections:
- Body – it contains an HTML structure, including a placeholder for attachment, that will be an adaptive card in this case.
- Attachments – this property contains an escaped Adaptive Card JSON.
- 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.
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.
This blog is part of Power Platform Week.
About the Author
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.
Reference
Poszytek, T., 2022, HOW TO MENTION TAGS, USERS, CHANNELS AND TEAMS USING POWER AUTOMATE, Available at: How to mention tags, users, channels and teams using Power Automate • Tomasz Poszytek, Business Applications MVP [Accessed on 18 January 2023]