DEV Community

Kenichiro Nakamura
Kenichiro Nakamura

Posted on

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

Top comments (26)

Collapse
 
task4233 profile image
task4233

Hello.
I'd like to send the message which contains @mention with incoming webhook.

However, I couldn't make work @mention with 8:orgid:{org-ID-of-the-user}.
I consider the reason why I couldn't do was org-ID-of-the-user was too short, c57b6b553*******(16 digits), which is got with Graph Explorer(graph.microsoft.com/v1.0/me).

As I have no idea to solve this problem, I appreciate if you would let me know the solution.

Thanks in advance.

Collapse
 
kenakamu profile image
Kenichiro Nakamura

The user id is guid form one, which you can find from graph results.

for example, this is my result.

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
    "businessPhones": [
        "xxxx"
    ],
    "displayName": "Kenichiro Nakamura",
    "givenName": "Kenichiro",
    "jobTitle": "SR SOFTWARE ENGINEER",
    "mail": "xxxxx",
    "mobilePhone": "xxxx",
    "officeLocation": "xxxx",
    "preferredLanguage": null,
    "surname": "Nakamura",
    "userPrincipalName": "xxxxx",
    "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" <- This one
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
task4233 profile image
task4233

Thank you for replying.

This is my result with calling graph.microsoft.com/v1.0/me

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
    "displayName": "xxxx",
    "surname": "xx",
    "givenName": "xx",
    "id": "xxxxxxxxxxxxxxxx", <- This is too short, I think
    "userPrincipalName": "xxxxxxxxxxxxxxxxxx@yahoo.co.jp",
    "businessPhones": [],
    "jobTitle": null,
    "mail": null,
    "mobilePhone": null,
    "officeLocation": null,
    "preferredLanguage": null
}
Enter fullscreen mode Exit fullscreen mode

I think the format of id is a different to from yours.
Would you tell me why they are different if you know.

Thread Thread
 
kenakamu profile image
Kenichiro Nakamura

That's interesting which I don't have much idea. And you can query your info via graph.microsoft.com/v1.0/users/ ?

Thread Thread
 
task4233 profile image
task4233

Of cource!
However, it seems that the value is same...

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
    "value": [
        {
            "displayName": "xxxx",
            "surname": "xx",
            "givenName": "xx",
            "id": "xxxxxxxxxxxxxxxx",
            "userPrincipalName": "xxxxxxxxxxxxxxxx@yahoo.co.jp",
            "businessPhones": [],
            "jobTitle": null,
            "mail": null,
            "mobilePhone": null,
            "officeLocation": null,
            "preferredLanguage": null
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
kenakamu profile image
Kenichiro Nakamura

Then I assume that's your user id. Not sure why format is different. So if you create mention by using the id with 8:orgid:{org-ID-of-the-user} , nothing happens?

Thread Thread
 
kenakamu profile image
Kenichiro Nakamura

And check this thread as well please. powerusers.microsoft.com/t5/Buildi...

Thread Thread
 
task4233 profile image
task4233

So if you create mention by using the id with 8:orgid:{org-ID-of-the-user} , nothing happens?

Yes, it says nothing at all.

It's a sent JSON with incoming webhook URL.

{
    "type": "message",
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.adaptive",
            "content": {
                "type": "AdaptiveCard",
                "body": [
                    {
                        "type": "TextBlock",
                        "text": "Hi <at>John</at>"
                    }
                ],
                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                "version": "1.0",
                "msteams": {
                    "entities": [
                        {
                            "type": "mention",
                            "text": "<at>John</at>",
                            "mentioned": {
                                "id": "8:orgid:xxxxxxxxxxxxxxxx",
                                "name": "XXXX YYYY"
                            }
                        }
                    ]
                }
            }
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

And, the attached image is a message displayed in teams. On hovering the purple message, John, there's no reaction.

attached image

Thread Thread
 
kenakamu profile image
Kenichiro Nakamura

interesting.. i am not sure about the id format. If you are keen to debug in different environment too, you can create trial instance and test. I just did but the id of user was GUID format.

Thread Thread
 
task4233 profile image
task4233 • Edited

Thank you for taking the time to check it out.
Actually, I can't set up a new trial instance, as it was an technical verifiaction in my company.
Thus, I've concluded to give up on this method for now.
Thank you very much for your help so far.

Thread Thread
 
kenakamu profile image
Kenichiro Nakamura

I am sorry to hear that we couldn't figure out the issue. Why don't you issue support ticket to get more assistance!? Please let me know if you have any further question anytime.

Thread Thread
 
task4233 profile image
task4233

Thank you for the suggestion.
Would you tell me which site I can issue support ticket?
I'd like to do that if I can.

Thread Thread
 
kenakamu profile image
Kenichiro Nakamura

As long as I know, if you may log ticket from Microsoft 365 portal, which may requires some permission. If you cannot do it, you may want to find admin of the tenant to issue the ticket.

Thread Thread
 
task4233 profile image
task4233

I'll contact the admin of my community.
Thank you for that.

Thread Thread
 
jishwin13 profile image
jishwin13 • Edited

Hello, any update on this issue? I am also facing the same issue here. I cant find the orgid. Can anyone help? I am also getting such a b58f56fa8a54b578 from graph query just like @task4233 . Not even the content inside the "at" tags tags are displayed in the teams. Only the text is coming. Someone give me some pointers please?

Thread Thread
 
kenakamu profile image
Kenichiro Nakamura

I am also curious about this. Appreciate if anyone can share any findings!

Thread Thread
 
bmesft profile image
Andrew

Has anyone been able to figure this one out? I am getting the same issues as most here, the user "link" is blue, but there is no action or mention created. I checked that the id is correct by doing a mention and inspecting the page to make sure I was using the correct ID. I am just sending the adaptive card using a webhook.

Thread Thread
 
jonasbjoralt profile image
Jonas Bjøralt

Hi, I was able to get it to work by replacing the id with my email. Here's the full JSON:

{
    "type": "message",
    "attachments": [
      {
        "contentType": "application/vnd.microsoft.card.adaptive",
        "content": {
          "type": "AdaptiveCard",
          "$schema": "https://adaptivecards.io/schemas/adaptive-card.json",
          "version": "1.4",
          "body": [
            {
              "type": "ColumnSet",
              "columns": [
                {
                  "type": "Column",
                  "width": 2,
                  "items": [
                    {
                      "type": "TextBlock",
                      "text": "<at>John Doe</at> you should really see this.. ",
                      "wrap": true
                    }
                  ]
                }
              ]
            }
          ],
          "msteams": {
            "entities": [
              {
                "type": "mention",
                "text": "<at>John Doe</at>",
                "mentioned": {
                  "id": "john@example.com",
                  "name": "John Doe"
                }
              }
            ]
          }
        }
      }
    ]
  }

Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
nemopeti profile image
Kovács Péter

Save my day, that worked to me also with email address :)

Thread Thread
 
kenakamu profile image
Kenichiro Nakamura

I am glad to hear that!

Collapse
 
cassavaexp profile image
Michael

Anyone still following along here I found that I could get the user Id option to work by dropping the 8:orgId: prefix. Hope that helps.

Collapse
 
kenakamu profile image
Kenichiro Nakamura

Thanks for your update!

Collapse
 
vladsmanolescu profile image
Vlad Manolescu

Hello i managed to to mention someone but that person is not alerted and when i hover over his name nothing happens as opposed to a manual mention. Any suggestions?

Collapse
 
kenakamu profile image
Kenichiro Nakamura

that's wired.. please check org id is correct.

Collapse
 
phoenixfangor profile image
phoenixfangor

I am also having this issue; I'm using what I know to be our organization's tenant id. Is the "org id" different?

Thread Thread
 
kenakamu profile image
Kenichiro Nakamura

It's not organization id but organization user id in mention.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.