在聊天中发送消息

命名空间:microsoft.graph

在指定的聊天 中发送新的chatMessage 此 API 无法创建新聊天;必须先使用 列表聊天 方法检索现有聊天的 ID,然后才能创建聊天消息。

注意:不建议使用此 API 进行数据迁移。 它不具有典型迁移所需的吞吐量。

注意:使用 Microsoft Teams 是违反 使用条款日志文件。 仅发送用户将阅读的邮件。

权限

要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限

权限类型 权限(从最低特权到最高特权)
委派(工作或学校帐户) ChatMessage.Send、Chat.ReadWrite
委派(个人 Microsoft 帐户) 不支持。
应用程序 不支持。

HTTP 请求

POST /chats/{chat-id}/messages

请求标头

名称 说明
Authorization Bearer {code}。 必需。

请求正文

在请求正文中,提供 chatMessage 对象的 JSON 表示形式。

响应

如果成功,此方法在响应正文中返回 响应代码和新 201 Created chatMessage 对象。

示例

有关示例的更全面的列表,请参阅在频道或聊天中创建 chatMessage。

请求

下面展示了示例请求。

POST https://graph.microsoft.com/v1.0/chats/19:2da4c29f6d7041eca70b638b43d45437@thread.v2/messages
Content-type: application/json

{
  "body": {
     "content": "Hello world"
  }
}

响应

下面展示了示例响应。

HTTP/1.1 201 Created
Content-type: application/json

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#chats('19%3A2da4c29f6d7041eca70b638b43d45437%40thread.v2')/messages/$entity",
    "id": "1616991463150",
    "replyToId": null,
    "etag": "1616991463150",
    "messageType": "message",
    "createdDateTime": "2021-03-29T04:17:43.15Z",
    "lastModifiedDateTime": "2021-03-29T04:17:43.15Z",
    "lastEditedDateTime": null,
    "deletedDateTime": null,
    "subject": null,
    "summary": null,
    "chatId": "19:2da4c29f6d7041eca70b638b43d45437@thread.v2",
    "importance": "normal",
    "locale": "en-us",
    "webUrl": null,
    "channelIdentity": null,
    "policyViolation": null,
    "eventDetail": null,
    "from": {
        "application": null,
        "device": null,
        "conversation": null,
        "user": {
            "id": "8ea0e38b-efb3-4757-924a-5f94061cf8c2",
            "displayName": "Robin Kline",
            "userIdentityType": "aadUser"
        }
    },
    "body": {
        "contentType": "text",
        "content": "Hello World"
    },
    "attachments": [],
    "mentions": [],
    "reactions": []
}