聊天: getAllMessages

命名空间:microsoft.graph

从用户是参与者的所有聊天中获取所有消息,包括一对一聊天、群组聊天和会议聊天。

要了解有关如何使用 Microsoft Teams 导出 API 来导出内容的详细信息,请参阅 使用 Microsoft Teams 导出 API 导出内容。

此 API 可用于以下国家级云部署。

全局服务 美国政府 L4 美国政府 L5 (DOD) 由世纪互联运营的中国
✅ ✅ ✅ ❌

权限

为此 API 选择标记为最低特权的权限。 只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。

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

HTTP 请求

GET /users/{id | user-principal-name}/chats/getAllMessages

可选的查询参数

此方法还支持 日期范围参数 来自定义响应,如以下示例所示。

GET /users/{id}/chats/getAllMessages?$top=50&$filter=lastModifiedDateTime gt 2020-06-04T18:03:11.591Z and lastModifiedDateTime lt 2020-06-05T21:00:09.413Z

此方法支持 $filter 查询参数。 下表列出了示例。

应用场景 $filter 参数 可能的值
获取用户标识类型发送的消息 $filter=from/user/userIdentityType eq '{teamworkUserIdentityType}' aadUser, onPremiseAadUser, anonymousGuest, federatedUser, personalMicrosoftAccountUser, skypeUser, phoneUser
获取按应用程序类型发送的消息 $filter=from/application/applicationIdentityType eq '{teamworkApplicationIdentity}' aadApplication, 机器人, tenantBot, office365Connector, outgoingWebhook
获取用户 ID 发送的消息 $filter=from/user/id eq '{oid}'
获取控制 (系统事件) 消息 $filter=messageType eq 'systemEventMessage'
排除控件 (系统事件) 消息 $filter=messageType ne 'systemEventMessage'

注意: 可以使用 运算符联接 or 这些筛选器子句。 筛选器子句可以在查询中多次出现,并且每次在查询中出现时,它都可以根据不同的值进行筛选。

请求标头

标头 值
Authorization 持有者 {token}。 必填。 详细了解 身份验证和授权。

响应

如果成功,此方法将在正文中返回 200 OK 响应代码和chatMessages 的列表。

示例

请求

GET https://graph.microsoft.com/v1.0/users/0b4f1cf6-54c8-4820-bbb7-2a1f4257ade5/chats/getAllMessages?$top=2

响应

注意:为了提高可读性,可能缩短了此处显示的响应对象。

HTTP/1.1 200 OK
Content-type: application/json

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(chatMessage)",
    "@odata.count": 2,
    "@odata.nextLink": "https://graph.microsoft.com/v1.0/users('0b4f1cf6-54c8-4820-bbb7-2a1f4257ade5')/chats/getallMessages?$top=2&$skiptoken=U2tpcFZhbHVlPTIjTWFpbGJveEZvbGRlcj1NYWlsRm9sZGVycy9UZWFtc01lc3NhZ2VzRGF0YQ%3d%3d",
    "value": [
        {
            "@odata.type": "#microsoft.graph.chatMessage",
            "id": "1621973534864",
            "replyToId": null,
            "etag": "1621973534864",
            "messageType": "message",
            "createdDateTime": "2021-05-25T20:12:14.864Z",
            "lastModifiedDateTime": "2021-05-25T20:12:14.864Z",
            "lastEditedDateTime": null,
            "deletedDateTime": null,
            "subject": null,
            "summary": null,
            "chatId": "19:3c9e92a344704332bbf5bda58f4d37b1@thread.v2",
            "importance": "normal",
            "locale": "en-us",
            "webUrl": null,
            "channelIdentity": null,
            "policyViolation": null,
            "eventDetail": null,
            "from": {
                "application": null,
                "device": null,
                "user": {
                    "id": "0b4f1cf6-54c8-4820-bbb7-2a1f4257ade5",
                    "displayName": "user1 a",
                    "userIdentityType": "aadUser"
                }
            },
            "body": {
                "contentType": "text",
                "content": "Hello user2, user 3"
            },
            "attachments": [],
            "mentions": [],
            "reactions": []
        },
        {
            "@odata.type": "#microsoft.graph.chatMessage",
            "id": "1622762567488",
            "replyToId": null,
            "etag": "1622762567488",
            "messageType": "message",
            "createdDateTime": "2021-06-03T23:22:47.488Z",
            "lastModifiedDateTime": "2021-06-03T23:22:47.488Z",
            "lastEditedDateTime": null,
            "deletedDateTime": null,
            "subject": null,
            "summary": null,
            "chatId": "19:0b4f1cf6-54c8-4820-bbb7-2a1f4257ade5_0d7c63d3-1306-4eec-8f21-588a70fb6ef1@unq.gbl.spaces",
            "importance": "normal",
            "locale": "en-us",
            "webUrl": null,
            "channelIdentity": null,
            "policyViolation": null,
            "eventDetail": null,
            "from": {
                "application": null,
                "device": null,
                "user": {
                    "id": "0b4f1cf6-54c8-4820-bbb7-2a1f4257ade5",
                    "displayName": "user1 a",
                    "userIdentityType": "aadUser"
                }
            },
            "body": {
                "contentType": "text",
                "content": "hi user2"
            },
            "attachments": [],
            "mentions": [],
            "reactions": []
        }
    ]
}

Microsoft Graph 特定于服务的节流限制