From e5df84dbedcf87d62153c0fc5ca6d37b003f153a Mon Sep 17 00:00:00 2001 From: Lonami Date: Fri, 9 Jun 2017 16:25:55 +0200 Subject: [PATCH] Created Retrieving all dialogs (markdown) --- Retrieving-all-dialogs.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Retrieving-all-dialogs.md diff --git a/Retrieving-all-dialogs.md b/Retrieving-all-dialogs.md new file mode 100644 index 0000000..891b5a4 --- /dev/null +++ b/Retrieving-all-dialogs.md @@ -0,0 +1,26 @@ +There are several `offset_xyz=` parameters that have no effect at all, but there's not much one can do since this is something the server should handle. Currently, the only way to get all dialogs (open chats, conversations, etc.) is by using the `offset_date`: + +```python +from telethon.tl.functions.messages import GetDialogsRequest + + +dialogs = [] +users = [] +chats = [] + +last_date = None +chunk_size = 20 +while True: + result = client.invoke(GetDialogsRequest( + offset_date=last_date, + offset_id=0, + offset_peer=InputPeerEmpty(), + limit=chunk_size + )) + dialogs.extend(result.dialogs) + users.extend(result.users) + chats.extend(result.chats) + last_date = min(msg.date for msg in result.messages) + if not result.dialogs: + break +``` \ No newline at end of file