[MSGraph]: chatMessageMention resource type: How to add special character in chatMessageMention such as <at id=\"0\"><Alex></at>

Zhengping Liu 1 Reputation point Microsoft Employee
2022-09-26T06:43:12.987+00:00

Hi,

Our team works on sending message to Teams chat including chatMessageMention which means that massage mentions some users. And some user's display name has special characters such as "<",">",etc. For example: <Alex>. In that case, the body will be like this

"body": {
"contentType": "html",
"content": "<at id=\"0\"><Alex></at>"
}

And when sending such payload to Graph API, it will throw BadRequest error with message:
Neither Body nor adaptive card content contains marker for mention with Id '0'. Add '<at id="0">' to the body or an adaptive card.

So my question is:

  1. Is it allowed to use special characters inside chatMessageMention?
  2. If yes, how to add special character in it?

Thanks.

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Shivam Dhiman 6,081 Reputation points
    2022-09-27T01:49:05.527+00:00

    Hi @Zhengping Liu

    To use the special character you need to encode them first. As content type is HTML so we need to encode special character using HTML encoder.
    To address your issue I have created user with name <alex> and added him in teams. To send the message mentioning <alex>
    Please refer to below Screenshot to send Teams message mentioning <alex>.

    244899-tree.jpg

    Body Used:

    {  
        "body": {  
            "contentType": "html",  
            "content": "<at id=\"0\">&lt;alex&gt;</at>"  
        },  
        "mentions": [  
            {  
                "id": 0,  
                "mentionText": "<alex>",  
                "mentioned": {  
                    "user": {  
                        "displayName": "<alex>",  
                        "id": "eb8f93a9-c3d6-44f8-9daf-********"  
                    }  
                }  
            }  
        ]  
    }  
    

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.