Skip to content
开发文档
能力中心
应用市场
WebOffice
开发者后台

获取会话历史消息

获取指定会话(包括单聊、群组)内的历史消息(即聊天记录):

  • 获取单聊消息时,仅能是该应用的单聊
  • 获取群聊消息时,机器人必须在被查询的群组中

请求说明

请求地址https://openapi.wps.cn/v7/chats/{chat_id}/messages
请求方法GET
签名方式KSO-1
权限要求查询和管理会话消息(应用授权) kso.chat_message.readwrite

请求头(Header)

Header 名称参数类型是否必填说明
Content-Typestring使用:application/json
X-Kso-DatestringRFC1123 格式的日期,例: Wed, 23 Jan 2013 06:43:08 GMT
X-Kso-AuthorizationstringKSO-1 签名值,详见《签名方法》
Authorizationstring授权凭证,格式为:Bearer {access_token}

路径参数(Path)

名称参数类型是否必填说明
chat_idstring会话 id

查询参数(Query)

名称参数类型是否必填说明
start_timeint查询历史消息的起始时间(秒级时间戳)
end_timeint查询历史消息的结束时间(秒级时间戳)
page_tokenstring分页token
page_sizeint分页大小

请求地址示例

[GET] https://openapi.wps.cn/v7/chats/{chat_id}/messages?start_time=11235666&end_time=145643222&page_token=string&page_size=10

响应体

名称参数类型说明
codeinteger响应代码。非 0 表示失败,参照《状态码说明》
msgstring响应信息
dataobject数据信息
∟ next_page_tokenstring分页标记
∟ itemsarray消息数据
∟ ∟ idstring消息id
∟ ∟ typestring消息类型:"text-文本" "rich_text-富文本" "image-图片" "file-文件" "audio-音频" "video-视频" "card-卡片"
∟ ∟ ctimeint消息生成的时间戳
∟ ∟ quote_msg_idstring被引用的消息ID
∟ ∟ positionint会话消息位置索引,严格连续递增
∟ ∟ contentobject消息内容
∟ ∟ ∟ textobject文本消息,见【发送消息接口】中详细描述
∟ ∟ ∟ rich_textobject富文本消息,见【发送消息接口】中详细描述
∟ ∟ ∟ imageobject图片消息,见【发送消息接口】中详细描述
∟ ∟ ∟ fileobject文件消息,见【发送消息接口】中详细描述
∟ ∟ ∟ audioobject音频消息,见【发送消息接口】中详细描述
∟ ∟ ∟ videoobject视频消息,见【发送消息接口】中详细描述
∟ ∟ ∟ cardobject卡片消息,见【发送消息接口】中详细描述
∟ ∟ senderobject发送者
∟ ∟ ∟ typestring发送者类型:user-用户,sp-应用服务主体
∟ ∟ ∟ idstring发送者的 ID,当发送者类型为user时返回user_id,当发送者类型为sp时返回spid(与应用appid不相同)
∟ ∟ ∟ app_idstring应用id,只在type为sp时有值
∟ ∟ ∟ company_idstring发送者所属企业
∟ ∟ mentionsarray消息@人列表
∟ ∟ ∟ typestringat 操作对象类型
all:所有人;user:用户
∟ ∟ ∟ idstring指定聊天消息中at操作的实体索引ID。与消息正文中相应 标记中的 {index} 值匹配
∟ ∟ ∟ identityobject被 at 的用户信息,当 at 所有人时该值为空
∟ ∟ ∟ ∟ company_idstring被 at 的用户所属企业id
∟ ∟ ∟ ∟ idstring被 at 的用户id
∟ ∟ ∟ ∟ typestring被 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"
}