Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Namespace: microsoft.graph
Important
APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Send a new reply to a chatMessage in a specified channel or chat.
Notes:
- We don't recommend that you use this API for data migration via the standard create message flow. For data migration scenarios, use the import messages flow instead.
- It is a violation of the terms of use to use Microsoft Teams as a log file. Only send messages that people will read.
This API is available in the following national cloud deployments.
| Global service | US Government L4 | US Government L5 (DOD) | China operated by 21Vianet |
|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ |
Permissions
The following tables show the least privileged permission or permissions required to call this API on each supported resource type. Follow best practices to request least privileged permissions. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
Permissions for channel replies
| Permission type | Least privileged permissions | Higher privileged permissions |
|---|---|---|
| Delegated (work or school account) | ChannelMessage.Send | Group.ReadWrite.All |
| Delegated (personal Microsoft account) | Not supported. | Not supported. |
| Application | Teamwork.Migrate.All | Not available. |
Note
- The Group.ReadWrite.All permission is supported only for backward compatibility. We recommend that you update your solutions to use an alternative permission listed in the previous table and avoid using these permissions going forward.
- Application permissions are only supported for migration. In the future, Microsoft may require you or your customers to pay additional fees based on the amount of data imported.
Permissions for chat replies
| Permission type | Least privileged permissions | Higher privileged permissions |
|---|---|---|
| Delegated (work or school account) | ChatMessage.Send | Chat.ReadWrite |
| Delegated (personal Microsoft account) | Not supported. | Not supported. |
| Application | Teamwork.Migrate.All | Not available. |
HTTP request
Send a reply to a message in a channel
POST /teams/{team-id}/channels/{channel-id}/messages/{message-id}/replies
Send a reply to a message in a chat
POST /chats/{chat-id}/messages/{message-id}/replies
POST /users/{user-id | user-principal-name}/chats/{chat-id}/messages/{message-id}/replies
Use the id of the root message as {message-id}. The service sets the replyToId of the reply from this ID; don't supply replyToId in the request body.
For delegated requests to the user-scoped route, the specified user must be the signed-in user. This create route doesn't imply support for user-scoped reply reads, updates, soft deletion, or restoration. Use the chat-scoped URLs for those operations.
Note
Chat reply endpoints are currently supported only for bot sessions (bot conversations).
Request headers
| Name | Type | Description |
|---|---|---|
| Authorization | string | Bearer {token}. Required. Learn more about authentication and authorization. |
| Content-Type | string | application/json. Required. |
Request body
In the request body, supply a JSON representation of a message object. Only the body property is mandatory. Other properties are optional.
For chat replies, use body.contentType to specify text or html, and body.content for the reply content. For HTML that references inline images, include the image data in hostedContents and reference the @microsoft.graph.temporaryId of each item in the HTML. The service assigns the persisted hosted content IDs. Don't supply server-populated properties such as id or replyToId.
Response
If successful, this method returns 201 Created response code with the message that was created.
Examples
Example 1: Send a new reply to a chatMessage
For a more comprehensive list of examples, see Create chatMessage in a channel or a chat.
Request
The following example shows a request.
POST https://graph.microsoft.com/beta/teams/fbe2bf47-16c8-47cf-b4a5-4b9b187c508b/channels/19:4a95f7d8db4c4e7fae857bcebe0623e6@thread.tacv2/messages/1616990032035/replies
Content-type: application/json
{
"body": {
"contentType": "html",
"content": "Hello World"
}
}
Response
The following example shows the response.
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#teams('fbe2bf47-16c8-47cf-b4a5-4b9b187c508b')/channels('19%3A4a95f7d8db4c4e7fae857bcebe0623e6%40thread.tacv2')/messages('1616990032035')/replies/$entity",
"id": "1616990171266",
"replyToId": "1616990032035",
"etag": "1616990171266",
"messageType": "message",
"createdDateTime": "2021-03-29T03:56:11.266Z",
"lastModifiedDateTime": "2021-03-29T03:56:11.266Z",
"lastEditedDateTime": null,
"deletedDateTime": null,
"subject": null,
"summary": null,
"chatId": null,
"importance": "normal",
"locale": "en-us",
"webUrl": "https://teams.microsoft.com/l/message/19%3A4a95f7d8db4c4e7fae857bcebe0623e6%40thread.tacv2/1616990171266?groupId=fbe2bf47-16c8-47cf-b4a5-4b9b187c508b&tenantId=2432b57b-0abd-43db-aa7b-16eadd115d34&createdTime=1616990171266&parentMessageId=1616990032035",
"policyViolation": null,
"eventDetail": null,
"from": {
"application": null,
"device": null,
"user": {
"@odata.type": "#microsoft.graph.teamworkUserIdentity",
"id": "8ea0e38b-efb3-4757-924a-5f94061cf8c2",
"displayName": "Robin Kline",
"userIdentityType": "aadUser"
}
},
"body": {
"contentType": "text",
"content": "Hello World"
},
"channelIdentity": {
"teamId": "fbe2bf47-16c8-47cf-b4a5-4b9b187c508b",
"channelId": "19:4a95f7d8db4c4e7fae857bcebe0623e6@thread.tacv2"
},
"onBehalfOf": null,
"attachments": [],
"mentions": [],
"reactions": [],
"messageHistory": []
}
Example 2: Import messages
The following example shows how to import a message reply. For more information, see Import messages into Microsoft Teams chats and channels using Microsoft Graph.
Note: The permission scope
Teamwork.Migrate.Allis required for this scenario.
Important
The createdDateTime must be unique down to the millisecond within the target channel. If a message with the same createdDateTime exists, the request fails with 409 Conflict. Adjust the createdDateTime and retry. For more information, see Import messages into Microsoft Teams chats and channels using Microsoft Graph.
Request
The following example shows how to import back-in-time messages using the createDateTime and from keys in the request body.
POST https://graph.microsoft.com/beta/teams/57fb72d0-d811-46f4-8947-305e6072eaa5/channels/19:4b6bed8d24574f6a9e436813cb2617d8@thread.tacv2/messages/1590776551682/replies
{
"createdDateTime":"2019-02-04T19:58:15.511Z",
"from":{
"user":{
"id":"8c0a1a67-50ce-4114-bb6c-da9c5dbcf6ca",
"displayName":"John Doe"
}
},
"body":{
"contentType":"html",
"content":"Hello World"
}
}
Response
The following example shows the response.
HTTP/1.1 200 OK
{
"@odata.context":"https://graph.microsoft.com/beta/$metadata#teams('57fb72d0-d811-46f4-8947-305e6072eaa5')/channels('19:4b6bed8d24574f6a9e436813cb2617d8@thread.tacv2')/messages('1590776551682')/replies/$entity",
"id":"1591039710682",
"replyToId":"1590776551682",
"etag":"1591039710682",
"messageType":"message",
"createdDateTime":"2019-02-04T19:58:15.511Z",
"lastModifiedDateTime":null,
"deleted":false,
"subject":null,
"summary":null,
"importance":"normal",
"locale":"en-us",
"policyViolation":null,
"eventDetail": null,
"from":{
"application":null,
"device":null,
"user":{
"@odata.type": "#microsoft.graph.teamworkUserIdentity",
"id":"8c0a1a67-50ce-4114-bb6c-da9c5dbcf6ca",
"displayName":"Joh Doe",
"userIdentityType":"aadUser",
"tenantId": "e61ef81e-8bd8-476a-92e8-4a62f8426fca"
}
},
"body":{
"contentType":"html",
"content":"Hello World"
},
"attachments":[],
"mentions":[],
"reactions":[],
"messageHistory": []
}
Example 3: Send a text reply
The following example shows how to reply to a message in a chat.
Request
The following example shows a request.
POST https://graph.microsoft.com/beta/chats/19:8b13f6c95f8b4e39a2e79fce14f205a1@thread.v2/messages/1757077200000/replies
Content-Type: application/json
{
"body": {
"contentType": "text",
"content": "The deployment is ready for review."
}
}
Response
The following response shows selected properties of the created reply.
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": "1757077260000",
"replyToId": "1757077200000",
"body": {
"contentType": "text",
"content": "The deployment is ready for review."
}
}
Example 4: Send a reply by using the user-scoped URL
The following example shows how to send a reply on behalf of the signed-in user.
Request
The following example shows a request.
POST https://graph.microsoft.com/beta/users/8f2670f1-5d1a-4c45-8b2f-994db1139e65/chats/19:8b13f6c95f8b4e39a2e79fce14f205a1@thread.v2/messages/1757077200000/replies
Content-Type: application/json
{
"body": {
"contentType": "text",
"content": "I reviewed the deployment plan."
}
}
Response
The following response shows selected properties of the created reply.
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": "1757077320000",
"replyToId": "1757077200000",
"body": {
"contentType": "text",
"content": "I reviewed the deployment plan."
}
}
Example 5: Send a reply with inline hosted content
The following example shows how to include a PNG image in an HTML reply. The temporary ID connects the image in the HTML to the hostedContents item.
Request
The following example shows a request.
POST https://graph.microsoft.com/beta/chats/19:8b13f6c95f8b4e39a2e79fce14f205a1@thread.v2/messages/1757077200000/replies
Content-Type: application/json
{
"body": {
"contentType": "html",
"content": "<p>Here is the status image.</p><img src=\"../hostedContents/1/$value\" alt=\"Status image\">"
},
"hostedContents": [
{
"@microsoft.graph.temporaryId": "1",
"contentBytes": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aBv0AAAAASUVORK5CYII=",
"contentType": "image/png"
}
]
}
Response
The following response shows selected properties of the created reply. To retrieve the persisted image ID, list the hosted content for the reply.
HTTP/1.1 201 Created
Content-Type: application/json
{
"id": "1757077380000",
"replyToId": "1757077200000"
}