Skip to content

Commit db87ad2

Browse files
antonskiterclaude
authored andcommitted
fix(groups): correct get_participants pagination
Two independent defects made every page beyond the first wrong: 1. TelegramClient.iter_participants takes no `offset` kwarg — its signature is (entity, limit=None, *, search, filter, aggressive) — so passing offset= raised TypeError for page > 1. 2. `limit` does not bound basic groups. _ParticipantsIter._init buffers the whole participant list and returns True, and RequestIter.__anext__ then sets `left` to the buffer length, discarding the requested limit. A page of a basic group therefore ran past page_size. Skip to the start of the requested page and stop once it is full. `limit` is still passed so channels, where it is honoured, do not over-fetch. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 7ea0adc commit db87ad2

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

telegram_mcp/tools/groups.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,13 @@ async def get_participants(
243243
cl = get_client(account)
244244
await ensure_connected(cl)
245245

246-
# Use iter_participants with offset to fetch only the needed slice,
247-
# avoiding O(N) fetching on later pages.
246+
# iter_participants takes no `offset`, and its `limit` is not honoured
247+
# for basic groups. Fetch through the page, then slice it out.
248248
offset = (page - 1) * page_size
249249
participants = []
250-
async for participant in cl.iter_participants(chat_id, limit=page_size, offset=offset):
250+
async for participant in cl.iter_participants(chat_id, limit=offset + page_size):
251251
participants.append(participant)
252+
participants = participants[offset : offset + page_size]
252253

253254
if not participants:
254255
return format_tool_result([])

0 commit comments

Comments
 (0)