Skip to content

Modify get_participants() in main.py with pagination and async generator for large groups #14

@chigwell

Description

@chigwell

User Story
As a user managing large Telegram groups,
I want paginated access to group participants
so that I can reliably retrieve complete membership lists without data loss.

Background
The current get_participants() implementation in main.py uses Telethon's default limit, risking incomplete data retrieval in groups with >200 members. This violates data completeness requirements and prevents analysis of large communities. The function currently:

  • Calls client.get_participants() without pagination parameters
  • Returns results as immediate list
  • Lacks control over batch sizes

Key risks:

  1. Telegram API limits (400 users per request default)
  2. Memory issues with large participant lists
  3. Timeouts in massive groups

Acceptance Criteria

  • Modify main.py's get_participants() tool implementation
  • Add page (1-indexed) and page_size (default 200) parameters
  • Implement pagination using Telethon's limit and offset parameters
  • Convert to async generator using client.iter_participants()
  • Add safety limit (max 1000 participants/page)
  • Preserve current text output format with pagination metadata

Validation:

  1. Test with group containing 1500 participants - verify 8 pages (7x200 + 1x100)
  2. Confirm no duplicate IDs across consecutive pages
  3. Verify error handling for invalid page numbers
  4. Check memory usage stays under 50MB for 1000-user batches

Implementation Note:
Leverage Telethon's async for participant in client.iter_participants() with limit and offset for efficient pagination while maintaining session state.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions