跳到主要内容

历史消息查询 - IM即时通讯

资费

所有增强型应用(包括免费应用),均可以免费调用IM历史消息查询接口,2021年11月起,IM历史消息查询接口不再单独扣除消息条数。

消息保留规则

免费保留规则

套餐保留规则
免费套餐免费保留1天
付费套餐免费保留10天

增值服务:付费延长保留资费

历史消息保留时间价格
延长至30天¥49/月
延长至90天¥99/月
延长至180天¥198/月
延长至360天¥297/月
延长至720天¥396/月

查询历史消息

    im.history({
id: 'user001/group001',//用户id或者群id
type: GoEasy.IM_SCENE.PRIVATE, //群聊:GoEasy.IM_SCENE.GROUP, 客服:GoEasy.IM_SCENE.CS,
lastTimestamp: lastMessage.timestamp, //上次查询结果里最后一条消息的时间戳,首次查询传入null即可
limit: 10, //可选项,返回的消息条数,默认为10条,最多30条
onSuccess: function (result) {
//单聊历史消息result示例
{
"code": 200,
"content": [
{
"type": "text", "messageId": "8f0e27a0c7e111eab347b726da4416bd",
"timestamp": 1594958217087, "senderId": "3bb179af-bcc5-4fe0-9dac-c05688484649",
"payload": {"text": "Hello, GoEasyIM"},
"read": false
},
{
"type": "audio", "messageId": "312c8900c7e211ea9744b7abe1fd7831",
"timestamp": 1594958490234, "senderId": "fdee46b0-4b01-4590-bdba-6586d7617f95",
"payload": {
"name": "20200717120129175.m4a", "contentType": "audio/m4a",
"url": "https://goeasy-hangzhou.oss-cn-hangzhou.aliyuncs.com/goeasy-im/20200717120129175.m4a",
"duration": 2.46, "size": 15220,
},
"read": true
},
{
"type": "image", "messageId": "9498cf40c7d711eab228bf40d56471fe",
"timestamp": 1594953936702, "senderId": "3bb179af-bcc5-4fe0-9dac-c05688484649",
"payload": {
"name": "04531220.jpg", "contentType": "image/jpeg",
"url": "https://goeasy-hangzhou.oss-cn-hangzhou.aliyuncs.com/goeasy-im/04531220.jpg",
"width": 1758, "height": 765, "size": 62988,
},
"read": false
},
{
"type": "video", "messageId": "373e36c0c7df11eab228bf40d56471fe",
"senderId": "3bb179af-bcc5-4fe0-9dac-c05688484649", "timestamp": 1594957262738,
"payload": {
"video": {
"name": "1593738719905558_20200717114010716.mp4", "contentType": "video/mp4",
"url": "https://goeasy-im.oss-cn-hangzhou.aliyuncs.com/goeasy-im/1593738719905558_20200717114010716.mp4",
"duration": 46.766667, "width": 544, "height": 960, "size": 7404683
},
"thumbnail": {
"width": 544, "height": 960, "contentType": "image/jpg",
"url": "https://goeasy-im.oss-cn-hangzhou.aliyuncs.com/goeasy-im/1593738719905558_20200717114010716.mp4?x-oss-process=video/snapshot,t_0000,f_jpg,w_544,m_fast"
}
},
"read": true
}
]
}
console.log("Query history successfully, result:\n " + JSON.stringify(result));
},
onFailed: function (error) { //获取失败
console.log("Failed to query private message, code:" + error.code + " content:" + error.content);
},
});



Webhook同步历史消息

通过启用消息历史的webhook功能,客户的服务器将可以实时接收GoEasy的消息发送记录

Webhook使用说明

详见GoEasy Webhook

同步IM聊天消息发送历史请求格式示例

POST  /yourUrlPath   HTTP/1.1
Host: http://xxxx.xxxx.com/xxxx 客户服务端接口
Content-Type: application/x-www-form-urlencoded
x-goeasy-signature: xxxxxxxxxxxxx //请求签名,用于验证请求的合法性,防止欺骗攻击

参数:

content: [
{
"type": "text", //消息类型
"messageId": "8f0e27a0c7e111eab347b726da4416bd", //每条消息唯一标识,可用于去重操作
"timestamp": 1594958217087, //发送的时间,可用于排序
"senderId": "3bb179af-bcc5-4fe0-9dac-c05688484649", //发送方userId
"receiverId": "3bb179af-bcc5-4fe0-9dac-c05688484649", //接收方userId
"payload": {"text": "Hello, GoEasyIM"} //消息体
},
{
"type": "audio", //消息类型
"messageId": "312c8900c7e211ea9744b7abe1fd7831", //每条消息唯一标识,可用于去重操作
"timestamp": 1594958490234, //发送的时间,可用于排序
"senderId": "fdee46b0-4b01-4590-bdba-6586d7617f95",//发送方userId
"senderData": '{"avatar":"/www/xxx.png","nickname":"Neo"}', //发送方Data,仅限群消息
"groupId": "fdee46b0-4b01-4590-bdba-6586d7617f95",//群消息的群id
"payload": { //消息体
"name": "20200717120129175.m4a", "contentType": "audio/m4a",
"url": "https://goeasy-hangzhou.oss-cn-hangzhou.aliyuncs.com/goeasy-im/20200717120129175.m4a",
"duration": 2.46, "size": 15220,
}
},
{
"type": "image", "messageId": "9498cf40c7d711eab228bf40d56471fe",
"timestamp": 1594953936702,
"senderId": "3bb179af-bcc5-4fe0-9dac-c05688484649", //发送方userId
"receiverId": "3bb179af-bcc5-4fe0-9dac-c05688484649", //接收方userId
"payload": {
"name": "04531220.jpg", "contentType": "image/jpeg",
"url": "https://goeasy-hangzhou.oss-cn-hangzhou.aliyuncs.com/goeasy-im/04531220.jpg",
"width": 1758, "height": 765, "size": 62988,
}
},
{
"type": "video", "messageId": "373e36c0c7df11eab228bf40d56471fe",
"timestamp": 1594957262738,
"senderId": "fdee46b0-4b01-4590-bdba-6586d7617f95",//发送方userId
"senderData": '{"avatar":"/www/xxx.png","nickname":"Neo"}', //发送方Data,仅限群消息
"groupId": "fdee46b0-4b01-4590-bdba-6586d7617f95",//群消息的群id
"payload": {
"video": {
"name": "1593738719905558_20200717114010716.mp4", "contentType": "video/mp4",
"url": "https://goeasy-im.oss-cn-hangzhou.aliyuncs.com/goeasy-im/1593738719905558_20200717114010716.mp4",
"duration": 46.766667, "width": 544, "height": 960, "size": 7404683
},
"thumbnail": {
"width": 544, "height": 960, "contentType": "image/jpg",
"url": "https://goeasy-im.oss-cn-hangzhou.aliyuncs.com/goeasy-im/1593738719905558_20200717114010716.mp4?x-oss-process=video/snapshot,t_0000,f_jpg,w_544,m_fast"
}
},
}
]