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": [
        //        {"timestamp": 1592675204893, "senderId": "user001", "payload": "你好"},
        //        {"timestamp": 1592675239434, "senderId": "user002", "payload": "Hello"},
        //        {"timestamp": 1592675229331, "senderId": "user001", "payload": "很高兴和你聊天"},
        //        {"timestamp": 1592735748560, "senderId": "user002", "payload": "GoEasy聊天好爽"}
        //    ]
        //}
        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": [
        //         {"timestamp": 1592668142284, "senderId": "user001", "payload": "大家好啊,欢迎大家入群"},
        //         {"timestamp": 1592668424576, "senderId": "user002", "payload": "群主好啊"},
        //         {"timestamp": 1592668475546, "senderId": "user003", "payload": "群主威武"},
        //         {"timestamp": 1592668511831, "senderId": "user004", "payload": "我是最靓的仔"},
        //         {"timestamp": 1592668548628, "senderId": "user005", "payload": "看到大家好开心"},
        //         {"timestamp": 1592668675426, "senderId": "user006", "payload": "周末快乐啊"},
        //         {"timestamp": 1592797234240, "senderId": "user007", "payload": "哇,好多人呢,大家都在啊"}
        //     ]
        // }
        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 ""