# 获取会话历史消息
注意事项:
- 根据时间获取会话中的历史消息
- 暂时仅支持获取单聊中的历史消息(即用户与当前应用机器人的对话记录)
- 目前仅支持 text、image、new_rich_text、rich_text、system_card 类型的消息被查询
# 请求
基本 | |
---|---|
HTTP URL | https://hi-gw.weizhipin.com/open-apis/im/v2/messages |
HTTP Method | GET |
支持的应用类型 | 自建应用 商店应用 |
权限要求开启任一权限即可 | 获取单聊、群聊消息 |
# 请求头
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
Authorization | string | 是 | tenant_access_token 值格式:"Bearer access_token "示例值:"Bearer t-7f1bcd13fc57d46bac21793a18e560" |
# 查询参数
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
user_id_type | string | 是 | 用户 ID 类型示例值:"open_id" 可选值有: open_id:用户的 open id union_id:用户的 union id user_id:用户的 user id 默认值:user_id 当值为 user_id,字段权限要求: 获取用户 user ID |
user_id | string | 是 | 用户ID,需要与查询参数中的user_id_type类型保持一致。 示例值:"ou_7dab8a3d3cdcc9da365777c7ad535d62" |
start_time | long | 是 | 开始查询10位时间戳 |
end_time | long | 是 | 结束查询10位时间戳,与开始时间相差不得超过一天 |
message_id | string | 否 | 起始消息id,如果不为空,将从此消息id开始查找数据 |
message_type | string | 是 | 需要查询的消息类型,多个用英文 , 分隔, 可指定类型image、 system_card、 rich_text、text |
page_size | int | 否 | 此次调用中拉取的数据大小,默认值:20 示例值:20 数据校验规则: * 取值范围: 1 ~ 50 |
# 响应
# 响应体
名称 | 类型 | 描述 |
---|---|---|
code | int | 错误码,非 0 表示失败 |
msg | string | 错误描述 |
data | list | - |
∟message_id | string | 消息id |
∟root_id | string | 根消息id |
∟parent_id | string | 父消息的id |
∟msg_type | string | 消息类型 包括:image、 compressive_card、 rich_text、text等 |
∟create_time | string | 消息生成的时间戳(毫秒) |
∟update_time | string | 消息更新的时间戳(毫秒) |
∟deleted | boolean | 消息是否被撤回 |
∟updated | boolean | 消息是否被更新 |
∟chat_id | string | 所属的群 |
∟sender | sender | 发送者,可以是用户或应用 |
∟ ∟id | string | 该字段标识发送者的id |
∟ ∟id_type | string | 该字段标识发送者的id类型 |
∟ ∟sender_type | string | 该字段标识发送者的类型 |
∟body | message_body | 消息内容 |
∟ ∟content | string | 消息内容,json结构序列化后的字符串。不同msg_type对应不同内容。消息类型 包括:image、 system_card、 rich_text、text等) ; 注意: 当消息类型为消息卡片(compressive_card)时,返回的消息内容为"" |
∟mentions | mention[] | 被@的用户或机器人的id列表 |
∟ ∟id | string | 被@的用户或者机器人的open_id |
∟ ∟id_type | string | 被@的用户或机器人 id 类型,目前仅支持 open_id |
∟upper_message_id | string | 合并转发消息中,上一层级的消息id message_id |
# 响应体示例
{
"code": 0,
"traceId": "_Ao59UOIBLPCeAAu",
"success": true,
"data": [{
"message_id": "c909a40e9ed292b31kEWDPHnxajTLa0~",
"root_id": "07b5df7e131fbe2e1w~~",
"parent_id": "07b5df7e131fbe2e1w~~",
"msg_type": "text",
"create_time": "1680593068000",
"update_time": "1680593068000",
"deleted": false,
"updated": false,
"chat_id": null,
"sender": {
"id": null,
"idType": null,
"senderType": "IM机器人",
"tenantKey": "327ab1e8160c0b783kUZ"
},
"body": {
"content": "{\"atIdList\":[\"-1\",\"ou_d30ebbab92f41742a20ac0969476857f\",\"ou_464a93783034963bfb77ad3bce3354d9\"],\"text\":\" @所有人 @娄修俊 @陈世伟 test\"}"
},
"mentions": [
{
"id": "-1",
"id_type": "open_id",
"tenant_key": "327ab1e8160c0b783kUZ"
},
{
"id": "ou_d30ebbab92f41742a20ac0969476857f",
"id_type": "open_id",
"tenant_key": "327ab1e8160c0b783kUZ"
},
{
"id": "ou_464a93783034963bfb77ad3bce3354d9",
"id_type": "open_id",
"tenant_key": "327ab1e8160c0b783kUZ"
}
],
"upper_message_id": null
}],
"msg": "操作成功"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44