MS Teams Bot: Adaptive Card User Mention Not Working

  Kiến thức lập trình

I am trying to mention a user in an Adaptive Card sent by a Microsoft Teams bot, but the mention is not working as expected. Below is the Adaptive Card template I am using:

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.6",
  "body": [
    {
      "type": "TextBlock",
      "text": "On-call users for: ${shiftDate}",
      "weight": "Bolder",
      "size": "Large",
      "wrap": true
    },
    {
      "type": "TextBlock",
      "text": "Schedule: ${scheduleName}",
      "weight": "Bolder",
      "size": "Medium",
      "wrap": true
    },
    {
      "type": "FactSet",
      "facts": "${data}"
    },
    {
      "type": "ActionSet",
      "actions": [
        {
          "type": "Action.OpenUrl",
          "title": "View Full Schedule",
          "url": "${baseUrl}/abc/abcd?scheduleid=${scheduleId}"
        }
      ],
      "msteams": {
        "entities": [
          {
            "type": "mention",
            "text": "<at>john</at>",
            "mentioned": {
              "id": "[email protected]",
              "name": "john"
            }
          }
        ]
      }
    }
  ]
}

After sending the message to the Teams channel, I can see the card and other details, but the user mention (john) does not trigger the expected mention behavior in Microsoft Teams. The text is displayed as-is and does not show up as a clickable mention in the Teams chat.

What I’ve Tried:

Ensured that the user ID and email are correct.
Verified the correct Adaptive Card version (1.6).
Tried different formats for the mention but nothing seems to work.
Questions:

Is there something I am missing in the card definition that would allow mentions to work?
Do mentions in Adaptive Cards need to follow a specific format or configuration for MS Teams bots?
Are there additional settings required to enable mentions in Teams bot messages?
Any help would be greatly appreciated!

Mentions should be placed within the body of the Adaptive Card, not within the actions. This ensures that the mention is rendered correctly within the card content.

The msteams property with the entities array should be placed at the root level of the Adaptive Card, not within the ActionSet.

Here’s an updated version of your Adaptive Card template:

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.6",
  "body": [
    {
      "type": "TextBlock",
      "text": "On-call users for: ${shiftDate}",
      "weight": "Bolder",
      "size": "Large",
      "wrap": true
    },
    {
      "type": "TextBlock",
      "text": "Schedule: ${scheduleName}",
      "weight": "Bolder",
      "size": "Medium",
      "wrap": true
    },
    {
      "type": "FactSet",
      "facts": "${data}"
    },
    {
      "type": "TextBlock",
      "text": "<at>john</at>",
      "wrap": true
    },
    {
      "type": "ActionSet",
      "actions": [
        {
          "type": "Action.OpenUrl",
          "title": "View Full Schedule",
          "url": "${baseUrl}/abc/abcd?scheduleid=${scheduleId}"
        }
      ]
    }
  ],
  "msteams": {
    "entities": [
      {
        "type": "mention",
        "text": "<at>john</at>",
        "mentioned": {
          "id": "[email protected]",
          "name": "john"
        }
      }
    ]
  }
}

In this updated template:

The mention is placed within a TextBlock in the body of the card.
The msteams property with the entities array is placed at the root level of the Adaptive Card.

Additionally,ensure that,The user ID and email are correct.
The Adaptive Card version is compatible with the features you are using.

Reference document-https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cdesktop%2Cconnector-html#mention-support-within-adaptive-cards

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT