gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:43:39 41 4
gpt4 key购买 nike

你好,我已经使用这个 https://docs.rocket.chat/api/rest-api/methods/channels/history 通过 rest API 获取未读消息。
示例调用

  • ( https://rcserver.rocket.chat/api/v1/im.history?roomId=ByehQjC44FwMeiLbX?&unreads=true )
  • (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());
    }
    我尝试使用上面的链接和代码,但结果不会给出任何未读的属性
    示例结果
    {
    "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"
    }]
    }
    请帮帮我。
    谢谢你。

    最佳答案

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

    要显示未读,您还必须传入 oldest 的查询参数这是一个可以成功转换为 JavaScript Date 对象的字符串,参见 Date.parse() documentation for details .

    示例查询 url 如下所示:

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

    然后包含未读信息的成功响应将如下所示:
    {
    "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 日,在合并拉取请求之前,这将不起作用。然而,在合并之后,这将适用于开发版本,一旦版本 0.59 Rocket.Chat 已发布,然后您可以更新您的服务器并使用它。

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

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

    关于rocket.chat - 如何通过Rocket.chat中的rest api获取未读消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45730833/

    41 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com