如何通过Rocket.chat中的Rest API获取未读消息 [英] How to get unread message via rest api in Rocket.chat

查看:173
本文介绍了如何通过Rocket.chat中的Rest API获取未读消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我已经使用过 https://rocket.chat/docs/developer-guides/rest-api/im/history 通过Rest API获取未读消息.

Hello I have used this https://rocket.chat/docs/developer-guides/rest-api/im/history for get unread message via rest API.

示例呼叫

1)( https://rcserver .rocket.chat/api/v1/im.history?roomId = ByehQjC44FwMeiLbX?& unreads = true )

2)( https://rcserver. rocket.chat/api/v1/im.history?roomId=ByehQjC44FwMeiLbX?&unreads= " +真)

代码

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(Constants.CONST_SITEURL);
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("X-Auth-Token", authToken);
client.DefaultRequestHeaders.Add("X-User-Id", userRcId);
HttpResponseMessage msgHistory = client.GetAsync(Constants.CONST_CHATHISTORY + userDetail.RC_RoomID + "&count=20&unreads=true").Result;
     if (msgHistory.IsSuccessStatusCode)
         {
           using (HttpContent content = msgHistory.Content)
                   {
                      var result = content.ReadAsStringAsync();
                      value = JObject.Parse(result.Result);
                    }
           directChatWindow = JsonConvert.DeserializeObject<DirectChatWindowBO>(value.ToString());
         }

我已经尝试了上面的链接和代码,但结果中没有任何未读的属性

I have try to above link and code but it will not give any unread property in result

示例结果

{
"messages": [
 {
  "_id": "7e6691fc-16sdfd3-ecbfsd8-317a-4076bb307e5dfsfd-4564",
  "rid": "CBsDHB7M8fsdfsdfN8G4X2BjsBDt5khnkenENacLN",
  "msg": "hittti",
  "ts": "2017-08-16T11:08:21.011Z",
  "u": {
    "_id": "CBsDHsdadsaB7M8N8G4X2Bj",
    "username": "xyz",
    "name": "xyz21"
  },
  "mentions": [],
  "channels": [],
  "_updatedAt": "2017-08-16T11:08:21.013Z"
},
{
  "_id": "eaf75056-bcxcvxcv40c-4a68-0128-c40503289d60",
  "rid": "CBsDHxcvB7M8cvxvxcvN8G4X2BjsBDt5kxcvhnkenENacLN",
  "msg": "hi",
  "ts": "2017-08-16T11:07:53.579Z",
  "u": {
    "_id": "CBsDHB7M8N8G4X2Bj",
    "username": "Abc",
    "name": "Abc123 "
  },
  "mentions": [],
  "channels": [],
  "_updatedAt": "2017-08-16T11:07:53.583Z"
}]
}

请帮帮我. 谢谢.

Please help me out. Thank You.

推荐答案

作为Rocket.Chat REST API的维护者,您实际上已经引起我们的注意,该错误已经存在很长时间了(因为我们是从coffeescript转换而来的) ).我已经提交了拉动请求,该问题已解决,但未得到解决出现它确实需要更改您使用im.history端点的方式.

As maintainer of the Rocket.Chat REST API, you actually brought to our attention a bug which has been present for a long time now (since we converted from coffeescript). I have submitted a pull request which fixes this issue, however to get the unreads to appear it does require changing how you use the im.history endpoint.

要显示未读内容,您还必须传递oldest的查询参数,该参数是可以成功转换为JavaScript Date对象的字符串,请参见Date.parse()

To get the unreads to appear you must also pass in the query parameter of oldest which is a string that can successfully be converted to a JavaScript Date object, see the Date.parse() documentation for details.

查询网址示例如下:

http://localhost:3000/api/v1/channels.history?roomName=general&unreads=true&oldest=2017-01-01

然后,包含未读信息的成功响应将如下所示:

Then a successful response which includes the unread information will look like the following:

{
    "messages": [
        {
            "_id": "pwiJmc7ZfEwebMEKP",
            "alias": "",
            "msg": "hello ;) ;)",
            "attachments": null,
            "parseUrls": true,
            "bot": null,
            "groupable": false,
            "ts": "2017-08-18T08:27:26.746Z",
            "u": {
                "_id": "HL2hEQSGask47a82K",
                "username": "graywolf336",
                "name": "graywolf336"
            },
            "rid": "GENERAL",
            "mentions": [],
            "channels": [],
            "_updatedAt": "2017-08-18T08:27:26.749Z"
        },
        {
            "_id": "YRch8iRsur7L6WF5B",
            "alias": "",
            "msg": "hello world",
            "attachments": null,
            "parseUrls": true,
            "bot": null,
            "groupable": false,
            "ts": "2017-08-18T08:21:50.072Z",
            "u": {
                "_id": "HL2hEQSGask47a82K",
                "username": "graywolf336",
                "name": "graywolf336"
            },
            "rid": "GENERAL",
            "mentions": [],
            "channels": [],
            "_updatedAt": "2017-08-18T08:21:50.073Z"
        }
    ],
    "firstUnread": {
        "_id": "3gJZbwLia6tuznPTk",
        "t": "uj",
        "rid": "GENERAL",
        "ts": "2017-07-31T22:53:20.579Z",
        "msg": "graywolf336",
        "u": {
            "_id": "HL2hEQSGask47a82K",
            "username": "graywolf336"
        },
        "groupable": false,
        "_updatedAt": "2017-07-31T22:53:20.579Z"
    },
    "unreadNotLoaded": 259,
    "success": true
}

自2017年8月8日起,在合并拉取请求之前,此功能将不起作用.但是,在合并之后,它将与开发版本一起使用,一旦Rocket.Chat版本0.59发布,您就可以更新服务器并使用它.

As of August 8, 2017, this will not work until the pull request is merged. However after it is merged then this will work with development builds and once version 0.59 of Rocket.Chat is released then you can update your server and make usage of it.

希望这会有所帮助,如果您有任何疑问,请告诉我,我会更新我的答案.

Hopefully this helps, let me know if you have any questions and I will update my answer.

免责声明:我是Rocket.Chat的雇员,并且确实维护REST API代码.

这篇关于如何通过Rocket.chat中的Rest API获取未读消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆