获取会话历史消息
获取指定会话(包括单聊、群组)内的历史消息(即聊天记录):
- 获取单聊消息时,仅能是该应用的单聊
- 获取群聊消息时,机器人必须在被查询的群组中
请求说明
请求地址 | https://openapi.wps.cn/v7/chats/{chat_id}/messages |
---|---|
请求方法 | GET |
签名方式 | KSO-1 |
权限要求 | 查询和管理会话消息(应用授权) kso.chat_message.readwrite |
请求头(Header)
Header 名称 | 参数类型 | 是否必填 | 说明 |
---|---|---|---|
Content-Type | string | 是 | 使用:application/json |
X-Kso-Date | string | 是 | RFC1123 格式的日期,例: Wed, 23 Jan 2013 06:43:08 GMT |
X-Kso-Authorization | string | 是 | KSO-1 签名值,详见《签名方法》 |
Authorization | string | 是 | 授权凭证,格式为:Bearer {access_token} |
路径参数(Path)
名称 | 参数类型 | 是否必填 | 说明 |
---|---|---|---|
chat_id | string | 是 | 会话 id |
查询参数(Query)
名称 | 参数类型 | 是否必填 | 说明 |
---|---|---|---|
start_time | int | 否 | 查询历史消息的起始时间(秒级时间戳) |
end_time | int | 否 | 查询历史消息的结束时间(秒级时间戳) |
page_token | string | 否 | 分页token |
page_size | int | 否 | 分页大小 |
请求地址示例
[GET] https://openapi.wps.cn/v7/chats/{chat_id}/messages?start_time=11235666&end_time=145643222&page_token=string&page_size=10
1
响应体
名称 | 参数类型 | 说明 |
---|---|---|
code | integer | 响应代码。非 0 表示失败,参照《状态码说明》 |
msg | string | 响应信息 |
data | object | 数据信息 |
∟ next_page_token | string | 分页标记 |
∟ items | array | 消息数据 |
∟ ∟ id | string | 消息id |
∟ ∟ type | string | 消息类型:"text-文本" "rich_text-富文本" "image-图片" "file-文件" "audio-音频" "video-视频" "card-卡片" |
∟ ∟ ctime | int | 消息生成的时间戳 |
∟ ∟ quote_msg_id | string | 被引用的消息ID |
∟ ∟ position | int | 会话消息位置索引,严格连续递增 |
∟ ∟ content | object | 消息内容 |
∟ ∟ ∟ text | object | 文本消息,见【发送消息接口】中详细描述 |
∟ ∟ ∟ rich_text | object | 富文本消息,见【发送消息接口】中详细描述 |
∟ ∟ ∟ image | object | 图片消息,见【发送消息接口】中详细描述 |
∟ ∟ ∟ file | object | 文件消息,见【发送消息接口】中详细描述 |
∟ ∟ ∟ audio | object | 音频消息,见【发送消息接口】中详细描述 |
∟ ∟ ∟ video | object | 视频消息,见【发送消息接口】中详细描述 |
∟ ∟ ∟ card | object | 卡片消息,见【发送消息接口】中详细描述 |
∟ ∟ sender | object | 发送者 |
∟ ∟ ∟ type | string | 发送者类型:user-用户,sp-应用服务主体 |
∟ ∟ ∟ id | string | 发送者的 ID,当发送者类型为user时返回user_id,当发送者类型为sp时返回spid(与应用appid不相同) |
∟ ∟ ∟ app_id | string | 应用id,只在type为sp时有值 |
∟ ∟ ∟ company_id | string | 发送者所属企业 |
∟ ∟ mentions | array | 消息@人列表 |
∟ ∟ ∟ type | string | at 操作对象类型 all :所有人;user :用户 |
∟ ∟ ∟ id | string | 指定聊天消息中at操作的实体索引ID。与消息正文中相应 标记中的 {index} 值匹配 |
∟ ∟ ∟ identity | object | 被 at 的用户信息,当 at 所有人时该值为空 |
∟ ∟ ∟ ∟ company_id | string | 被 at 的用户所属企业id |
∟ ∟ ∟ ∟ id | string | 被 at 的用户id |
∟ ∟ ∟ ∟ type | string | 被 at 的用户类型:user-用户,sp-应用服务主体 |
响应体示例
json
{
"code": 0,
"data": {
"items": [
{
"chat_id": "8417257",
"content": {
"text": {
"content": "<at id=\"1\">所有人</at> 111"
}
},
"ctime": 1744703397150,
"id": "W8imikTwSVt9TbfA",
"mentions": [],
"position": 26,
"sender": {
"app_id": "",
"company_id": "648112656",
"id": "9J8dODn2",
"type": "user"
},
"type": "text"
},
{
"chat_id": "8417257",
"content": {
"text": {
"content": "<at id=\"1\">lqjtest</at> "
}
},
"ctime": 1744703316293,
"id": "Z2iyikTWSLt8SjTA",
"mentions": [
{
"id": "1",
"identity": {
"avatar": "",
"company_id": "0",
"id": "qYVxvAa",
"name": "lqjtest",
"type": "sp"
},
"type": "user"
}
],
"position": 25,
"sender": {
"app_id": "",
"company_id": "648112656",
"id": "9J8dODn2",
"type": "user"
},
"type": "text"
},
{
"chat_id": "8417257",
"content": {
"text": {
"content": "<at id=\"1\">所有人</at> "
}
},
"ctime": 1744703256966,
"id": "Vdi4idTySBtDSpTl",
"mentions": [],
"position": 24,
"sender": {
"app_id": "",
"company_id": "648112656",
"id": "9J8dODn2",
"type": "user"
},
"type": "text"
},
{
"chat_id": "8417257",
"content": {
"rich_text": {
"elements": [
{
"elements": [
{
"style_text_content": {
"style": {
"bold": false,
"color": "#e2651a",
"italic": false
},
"text": "111"
},
"type": "text"
}
],
"type": "nl"
}
]
}
},
"ctime": 1744703175590,
"id": "2migikTMSRtlSMHD",
"mentions": [],
"position": 23,
"sender": {
"app_id": "",
"company_id": "648112656",
"id": "9J8dODn2",
"type": "user"
},
"type": "rich_text"
},
{
"chat_id": "8417257",
"content": {
"text": {
"content": "hel",
"type": "plain"
}
},
"ctime": 1744703111850,
"id": "Q3iOi5TYS6tBSgS1",
"mentions": [],
"position": 22,
"sender": {
"app_id": "",
"company_id": "648112656",
"id": "9J8dODn2",
"type": "user"
},
"type": "text"
}
],
"next_page_token": "MTc0NDcwMzExMTg1MDY3NDU5Nw"
},
"msg": "success"
}
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135