简体   繁体   English

如何通过 Node.js 的 Telegram 数据库库(TDLib)请求用户的所有聊天/群组

[英]How to request all chats/groups of the user through Telegram Database Library(TDLib) for Node.js

The official example from telegram explains that in order to use getChats() command, one needs to set two parameters ' offset_order ' and ' offset_chat_id '.电报的官方例子解释说,为了使用getChats()命令,需要设置两个参数“ offset_order ”和“ offset_chat_id ”。 I'm using this node.js wrapper for the TDLib .我正在为 TDLib使用这个node.js 包装器 So when I use getChats() with the following params:因此,当我使用带有以下参数的getChats()时:

'offset_order': '9223372036854775807',
'offset_chat_id': 0,
'limit': 100

just like it is explained in the official docs :就像官方文档中解释的那样:

For example, to get a list of chats from the beginning, the offset_order should be equal to 2^63 - 1例如,要从开头获取聊天列表,offset_order 应等于 2^63 - 1

as a result I get 100 chats from the top of the user's list.结果,我从用户列表的顶部获得了 100 个聊天记录。

What I can't understand is how do I iterate through that list?我不明白的是如何遍历该列表? How do I use the API pagination?如何使用 API 分页?

When I try to enter a legitimate chat_id from the middle of the first 100, I still get the same first 100, so it seems like it makes no difference.当我尝试从前 100 个中间输入合法的 chat_id 时,我仍然得到相同的前 100 个,因此似乎没有区别。

If I change that offset_order to ANY other number, I get an empty list of chats in return...如果我将该 offset_order 更改为任何其他数字,我会得到一个空的聊天列表作为回报......

Completely lost here, as every singleexample I found says the same thing as the official docs, ie how to get the first 100.在这里完全迷失了,因为我发现的一个例子都和官方文档说的一样,即如何获得前 100 个。

Had the same problem, have tried different approaches and re-read documentation for a long time, and here is a decision:遇到同样的问题,尝试了不同的方法并重新阅读文档很长一段时间,这里是一个决定:

  1. do getChats as you do with '9223372036854775807' offset_order parametergetChats就如同使用'9223372036854775807' offset_order参数
  2. do getChat request with id of the last chat you have got.使用您获得的最后一次聊天的 ID 执行getChat请求。 It's an offline request, just to tdlib.这是一个离线请求,只是给 tdlib。
  3. here you get a chat object with positions property - get a position from here, looks like this:在这里你会得到一个带有 position 属性的聊天对象 - 从这里获取一个位置,看起来像这样:
  positions: [
    {
      _: 'chatPosition',
      list: [Object],
      order: '6910658003385450706',
      is_pinned: false
    }
  ],
  1. next request - getChats - use the positions[0].order from (3) as offset_order下一个请求 - getChats - 使用 (3) 中的positions[0].order offset_order作为offset_order
  2. goto (2) if there are more chats goto (2) 如果有更多聊天

It wasn't easy to come to this, so would be glad if it helps anybody who came from google like me :)做到这一点并不容易,所以如果它可以帮助像我这样来自谷歌的人,我会很高兴:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM