如何在Rocket.chat中通过rest api获取未读消息

use*_*487 5 rocket.chat

您好我使用此https://rocket.chat/docs/developer-guides/rest-api/im/history通过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= "+ true)

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());
         }
Run Code Online (Sandbox Code Playgroud)

我已尝试上面的链接和代码,但它不会在结果中提供任何未读的属性

示例结果

{
"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"
}]
}
Run Code Online (Sandbox Code Playgroud)

请帮帮我.谢谢.

bra*_*ton 8

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

要显示未读取的内容,您还必须传入查询参数,oldest该参数是可以成功转换为JavaScript Date对象的字符串,Date.parse() 有关详细信息,请参阅文档.

示例查询网址如下所示:

http://localhost:3000/api/v1/channels.history?roomName=general&unreads=true&oldest=2017-01-01
Run Code Online (Sandbox Code Playgroud)

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

{
    "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
}
Run Code Online (Sandbox Code Playgroud)

截至2017年8月8日,在拉出请求合并之前,这将无效.但是在它合并之后,这将适用于开发版本,并且一旦0.59Rocket.Chat 版本发布,那么您可以更新您的服务器并使用它.

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

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