Use adaptive cards with mention in Microsoft Teams

kenakamu

Kenichiro Nakamura

Posted on April 29, 2020

Use adaptive cards with mention in Microsoft Teams

Adaptive Card is very flexible way to create rich card which I can send to many platform. One of the platform is Microsoft Teams.

What's more interesting is that Power Automate can send Adaptive Card now.

Use adaptive cards in Microsoft Teams

One thing I couldn't figure out was how to "mention" people. There is a document Mention support within Adaptive cards and it says

The mention object inside of an msteams property in the card content, which includes the Teams user id of the user being mentioned



{
  "contentType": "application/vnd.microsoft.card.adaptive",
  "content": {
    "type": "AdaptiveCard",
    "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"
          }
        }
      ]
    }
  }
}


Enter fullscreen mode Exit fullscreen mode

The question was how to get the Teams user id.

I found an thread discussing this at Ms Teams @ Mentions in adaptive cards and at the end, it seems like I just need to use 8:orgid:{org-ID-of-the-user} format like below.



"entities": [
  {
    "type": "mention",
    "text": "<at>Kenichiro Nakamura</at>",
    "mentioned": {
        "id": "8:orgid:{org-ID-of-the-user}",
        "name": "Kenichiro Nakamura"
     }
  }
]


Enter fullscreen mode Exit fullscreen mode

Now I can simply use any way to get the user id, such as Graph Explorer.

If the user id is f9e0c5cb-f4ee-43d4-91e2-63524d1bacd9, then the message I send in Power Automate looks like:



{
   "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", 
    "type": "AdaptiveCard",
    "version": "1.0",
    "body": [
      {
        "type": "TextBlock",
        "text": "Hi <at>Kenichiro Nakamura</at>"
      }
    ],
    "msteams": {
      "entities": [
        {
          "type": "mention",
          "text": "<at>Kenichiro Nakamura</at>",
          "mentioned": {
            "id": "8:orgid:f9e0c5cb-f4ee-43d4-91e2-63524d1bacd9",
            "name": "Kenichiro Nakamura"
          }
        }
      ]
    }
}


Enter fullscreen mode Exit fullscreen mode

The result is:
Alt Text

Cool :)

💖 💪 🙅 🚩
kenakamu
Kenichiro Nakamura

Posted on April 29, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related