I’m trying to retrieve a list of dialogs from a specific offset in a Telegram channel using Telethon 1.36.0. To achieve this, I used the ID of the last message in the channel from which I want to start the offset. However, when I tried different methods like get_dialogs, iter_dialogs, and client(GetDialogsRequest(…)), I did not get the expected result. It seems that Telegram always considers offset_date, and if it is not passed, it returns the list starting from the beginning.
I examined the implementation of iter_dialogs and even used a debugger to set offset_peer to types.InputPeerEmpty() and offset_date to None, leaving only offset_id. Despite these adjustments, it still returned the list from the beginning, ignoring offset_id and offset_peer.
I tried several methods to achieve the desired result:
- Using get_dialogs method.
- Using iter_dialogs method.
- Using client(GetDialogsRequest(…)) with various parameters.
In all cases, Telegram seems to prioritize offset_date, and without it, the returned list starts from the beginning like no offset was provided at all. When I set offset_peer to types.InputPeerEmpty() and offset_date to None while leaving offset_id, it still ignored offset_id and offset_peer, returning the list from the beginning.
Steps to reproduce:
from telethon import TelegramClient
from typing import List
from telethon.tl.custom import Dialog
# sign in steps are omitted
with TelegramClient(...) as client:
# get first 20 dialogs
dialogs: List[Dialog] = await mgr.client.get_dialogs(limit=20)
# set offset_id to last message id and expect to get next dialogs
dialogs2 = await mgr.client.get_dialogs(limit=20, offset_id=dialogs[-1].dialog.top_message)
# here "dialogs" and "dialogs2" are the same
Am I misunderstanding something?
1 1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.