GoEasyIM - 查询历史消息

开通

本特性为高级功能,默认不开通,付费应用,可以在我的应用->查看详情,高级功能里自助开通。

资费

根据每次返回的消息数,每返回10条消息,扣减1条消息数,不满10条,按10条计算。

历史消息保留规则

套餐 保留规则
免费应用 不保留
9.9元体验套餐 保留24小时内,每个群聊或者私聊对话的最后30条记录
99套餐 保留3天内,每个群聊或者私聊对话的最后100条记录
更高套餐 保留7天内,每个群聊或者私聊对话的最后300条记录

初始化GoEasyIM



    var options = {
            host:'hangzhou.goeasy.io', //应用所在的区域地址: [hangzhou.goeasy.io, 新加坡暂不支持IM,敬请期待]
            appkey: "my_appkey"            
    }

    //初始化
    var im = GoEasyIM.getInstance(options);


    //连接
    var user = {
        id:'user001'            
    }

    //连接GoEasyIM
    var promise = im.connect(user);

    promise.then(function () {
        console.log("Connection successfully.");
    }).catch(function (error) {
        console.log("Failed to connect GoEasy, code:" + error.code + " content:" + error.content);
    });

查询私聊历史消息

    var option = {
        friendId: "user001",  //对方userId
        lastTimestamp: Date.now(), //查询发送时间小于(不包含)该时间的历史消息,可用于分页和分批拉取聊天记录,默认为当前时间
        limit: 10 //可选项,返回的消息条数,默认为10条,最多30条
    }

    //查询
    var promise = im.history(option);

    promise.then(function (result) {
        //单聊历史消息result示例
        {
            "code": 200,
            "content": [
                {
                    "type": "text", "messageId": "8f0e27a0c7e111eab347b726da4416bd",
                    "timestamp": 1594958217087, "senderId": "3bb179af-bcc5-4fe0-9dac-c05688484649",
                    "payload": {"text": "Hello, GoEasyIM"}
                }, 
                {
                    "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,
                    }
                }, 
                {
                    "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,
                    }
                },
                {
                    "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"
                        }
                    },
                }
            ]
        }
        console.log("Query history successfully, result:\n " + JSON.stringify(result));
    }).catch(function (error) {
        console.log("Failed to query private message, code:" + error.code + " content:" + error.content);
    });

查询群聊历史消息

    var option = {
        groupId: "group001", //groupId
        lastTimestamp: Date.now(),  //查询发送时间小于(不包含)该时间的历史消息,可用于分页和分批拉取聊天记录,默认为当前时间
        limit: 10 //可选项,返回的消息条数,默认为10条,最多30条
    }

    //查询
    var promise = im.history(option);

    promise.then(function (result) {
        //群聊历史消息result示例
        {
            "code": 200,
            "content": [
                {
                    "type": "text", "messageId": "8f0e27a0c7e111eab347b726da4416bd",
                    "timestamp": 1594958217087, "senderId": "3bb179af-bcc5-4fe0-9dac-c05688484649",
                    "payload": {"text": "Hello, GoEasyIM"}
                }, 
                {
                    "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,
                    }
                }, 
                {
                    "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,
                    }
                },
                {
                    "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"
                        }
                    },
                }
            ]
        }
        console.log("Query group chat history successfully, result:\n " + JSON.stringify(result));
    }).catch(function (error) {
        console.log("Failed to query group message, code:" + error.code + " content:" + error.content);
    });

results matching ""

    No results matching ""