This topic has been continuously raised by multiple people I’ve been talking to. How can a user be mentioned in Microsoft Teams when a message is sent from Power Automate? This issue seemed to never been really possible for us, Power Users, until couple days ago Microsoft released new action in Microsoft Teams set in Power Automate called: “Get @mention token for a user”. It’s even cooler, because it works with Adaptive Cards too!
SEE IT IN ACTION!
HOW TO MENTION IN TEAMS VIA POWER AUTOMATE
For couple of days we have new action in Teams actions’ set in Power Automate called “Get @mention token for a user”. At first when I tested it, and noticed it just returns string: “<at>user e-mail</at>
” I thought – that’s nothing special. But then during a short conversation with Harysh Menon from the product group I was that although this action seems easy and doing nothing special, putting its outputs in Message or Adaptive Card is then handled internally by the Flow Bot and then all required mention entities are being added, so it actually works.
If you try to write that manually in Adaptive Card – it won’t work.
How can we use it?
First, get e-mail of the user who you want to mention. That’s the input field for the action.
Next, use it outputs in one of the below actions:
- Post a message (V3)
- Post a reply to a message (V2)
- Post your own adaptive card as the Flow bot to a channel
- Post an Adaptive Card to a Teams channel and wait for a response
It doesn’t work with actions sending messages/ cards to a user.
Next put it inside your action’s configuration.
Important! You need to use user’s e-mail you want to mention. Not AAD ID.
![](https://www.sharepointeurope.com/wp-content/uploads/2021/03/MENTIONING-IN-MICROSOFT-TEAMS-VIA-POWER-AUTOMATE1.png)
Important! The action doesn’t support mentioning of channels. It only support users at this time.
And here is the result!
![MENTIONING IN MICROSOFT TEAMS VIA POWER AUTOMATE](https://poszytek.eu/wp-content/uploads/2020/07/image-1-1024x392.png)
Important! Only below text blocks in Adaptive Cards can be used to display mention: TextBlock, FactSet.
ALTERNATIVES – AKA WHAT I TRIED SO FAR
<at>user mail</at> tags
The first thing I tried was a simple putting <at>user e-mail</at>
inside a messages post to Teams (action: Post a message (V3)). It worked. Although that didn’t allow me to craft nice looking cards, just simple messages. To achieve it, remember to turn input in the action’s configuration to “code view”:
![MENTIONING IN MICROSOFT TEAMS VIA POWER AUTOMATE](https://www.sharepointeurope.com/wp-content/uploads/2021/03/MENTIONING-IN-MICROSOFT-TEAMS-VIA-POWER-AUTOMATE3.png)
At-mention for Adaptive Cards
Then I found this documentation for Adaptive Cards with mention entity: https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cconnector-html#sample-adaptive-card-with-a-mention. I tried following that pattern, although action, when executed, was ending up with an error reading: “One or more mention entity could not be found in card text.“. So I abandoned that approach, since it just wasn’t working. It should be efficient though to simply add the “msteams” object with “entities” table but… no luck.
"body": [
{
"type": "TextBlock",
"text": "Hi <at>John Doe</at>"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0",
"msteams": {
"entities": [
{
"type": "mention",
"text": "<at>John Doe</at>",
"mentioned": {
"id": "29:123124124124",
"name": "John Doe"
}
}
]
}
Plus, I still didn’t figure out what’s that Teams User ID that is mentioned in documentation
At-mention using GraphAPI
For this to work we need to embed the following expression in the POST body:
{
"body": {
"contentType": "html",
"content": "Hello World <at id=\"0\">USER E-MAIL</at>"
},
"mentions": [
{
"id": 0,
"mentionText": "USER DISPLAYNAME",
"mentioned": {
"user": {
"displayName": "USER DISPLAYNAME",
"id": "USER AAD ID",
"userIdentityType": "aadUser"
}
}
}
]
}
At-mention using Invoke an HTTP request with Azure AD
That’s the last approach I tried. It requires us to have an Azure AD app with permissions scope set to post messages and the premium action named “Invoke an HTTP request”. The approach is described here http://www.expiscornovus.com/2019/05/29/mention-a-channel-with-flow/ by Dennis.
Note! This approach requires premium action and therefore a paid Power Automate plan.
And that’s it about mentioning in Teams. Let me know if you have any questions by publishing them below. Thanks!
Find more great content here!
About the Author:
I’m Tomasz Poszytek, Microsoft Business Applications MVP. From more than 10 years now I’m being involved in projects, which aim is production of various applications using SharePoint as a platform. My adventure started absolutely without a purpose, when in the beginning of 2000 I was given FrontPage installation disc and started experimenting with this WYSWIG tool. Today I am mainly focusing on working with Power Platform tools, delivering automation projects in Power Automate and Microsoft RPA. I am also building business applications using Power Apps and building data visualizations with Power Bi (although this is not something I really feel strong in :)). For over 4 years Office 365 is a platform for nearly all the projects I am working in, SharePoint Online is usually a datasource however I was also building solutions with SQL Server and Common Data Service (CDS). Learn more about my journey here.
Reference:
Poszytek, T. (2020). MENTIONING IN MICROSOFT TEAMS VIA POWER AUTOMATE. Available at: https://poszytek.eu/en/microsoft-en/office-365-en/powerautomate-en/mentioning-in-microsoft-teams-via-power-automate/ [Accessed: 3rd March 2021].