Top

Mentioning in Microsoft Teams via Power Automate


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.

Important! The action doesn’t support mentioning of channels. It only support users at this time.

And here is the result!

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”:

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

There is a way to mention users using beta endpoint in GraphAPI: https://graph.microsoft.com/beta/teams/{TeamID}/channels/{ChannelID)/messages. However, as per documentation: https://docs.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-beta&tabs=http this operation is only possible with Delegated permissions. And when your account has MFA turned on, it’s not possible to obtain user token via Power Automate. That approach, described by Vesa Nopanem here: https://myteamsday.com/2019/03/05/sending-message-with-atmention-onto-a-channel-using-graphapi/ works for example from Postman, where you can authenticate. But unfortunately for me – no way to automate it using Power Automate.

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!


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.

6 Comments
  • Sam

    Hi Tomasz,

    Thanks for this. It is a really handy feature.

    Do you know if it will come for at mentioning a team or channel?

    Thanks

    July 17, 2020 at 3:12 am Reply
    • Tomasz Poszytek

      I don’t have such information, sorry. You can always request it via UserVoice πŸ™‚

      July 28, 2020 at 7:46 am Reply
  • Sebastian

    Very nice Blog Post Tomasz!
    I’ve written something similar with additional details, like marking the messages as important. Maybe it is of help for some of your readers.
    https://medium.com/@sebastian.zolg/a-million-ways-of-mention-in-microsoft-teams-using-a-power-automate-flow-95e6bfc958f3?source=friends_link&sk=b09e6ec3bc9d3f0ac60c5278ca8dce22

    August 4, 2020 at 4:01 pm Reply
    • Tomasz Poszytek

      Cool that you did scenario with calling HTTP request with Azure AD. That one will certainly fulfill all the options πŸ™‚

      August 7, 2020 at 8:20 am Reply
  • Florian Bartsch

    HI TOmasz,

    the way you do it always gives me this:
    “The name of template action ‘@mention-Token_fΓΌr_einen_Benutzer_abrufen’ at line ‘1’ and column ‘606’ is not defined or not valid.”

    Or it imeadiatelly puts the @mention token into a “apply to all” Step.

    I am getting really frustrated since it works with everybody else so easily :-).

    Any help providable here?

    December 3, 2020 at 2:05 pm Reply
    • Tomasz Poszytek

      Based on what you wrote it’s hard to tell anything. This should be that easy. Maybe try changing name of the action to something like “Get mention token” and try then? You can as well try on a different environment if you have. Or contact the support πŸ™‚

      December 8, 2020 at 4:22 pm Reply

Post a Comment

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