0
votes

Using PowerShell's Invoke-RestMethod, I have successfully been able to make a call to "https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/chatThreads" to post a message to my desired Team/Channel in a very neatly formatted way.

What I am now struggling with is @mentioning a user in the same message. I've followed the short tutorial on https://myteamsday.com/2019/03/05/sending-message-with-atmention-onto-a-channel-using-graphapi/

I get to the point where I added the mentions section to the body of the request, complete with id of the user and id of the mention.

Once I make the call, the message is posted but only the text as show in the content property. No link/mention to the actual user.

{
    "rootMessage": {
        "body": {
            "contentType": "html",
            "content": "Hello, World! <at id=\"0\">Jack Black</at>"
        },
        "mentions": [ {
            "id": 0,
            "mentionText": "Jack Black",
            "mentioned": {
                "id": "ac5e5x81-39Dd-4748-beTa-b5cd6t93ba67",
                "displayName": "Jack Black",
                "userIdentityType": "aadUser"
            }
        }
        ]
    }
}

Here's one thing I noticed in the tutorial though, the guy references "https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/messages" , but Microsoft Graph references "https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/chatThreads"

When I replace chatThreads with message in Microsoft Graph, I get an Bad Request error message complaining about the content property cannot be null, but it is NOT null.

EDIT 1: When using https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/messages on graph explorer

{
    "error": {
        "code": "BadRequest",
        "message": "Value cannot be null.\r\nParameter name: Content",
        "innerError": {
            "request-id": "f0d4fed8-7726-4338-8a68-9685a690eab5",
            "date": "2019-07-02T12:46:14"
        }
    }
}
1
Tried. When I do the request with /chatThreads, the response code is 201 and the message is posted to the channel in question. User is not @mentioned. When I do the request with /messages (as per the MS Documentation), the response code is 400 and returns the following error:"message": "Value cannot be null.\r\nParameter name: Content"GaaTY
Could you please share the request body here?Gousia Begum
Request body or request response? I updated my post with the response. If request body, which one? My one or the one from the example?GaaTY
Please share the request body from the example link I have shared.Gousia Begum

1 Answers

1
votes

You need to include entities, with type 'mention', in your message and the message of the text should include <at>username</at> for each entity mentioned.