Files
export-telegram-group-members/specs/001-export-telegram-members/research.md
T
2025-12-06 17:30:37 +07:00

2.9 KiB

Research Summary: Telegram Group Members Export

Technology Research

Go Telegram Libraries

  • celestix/gotgproto: A high-level Telegram client library for Go based on MTProto. Provides session management, authentication, and high-level API abstractions.
  • xelaj/mtproto: Lower-level MTProto implementation that gotgproto is built on. Handles the protocol communication with Telegram's servers.
  • go-telegram/bot: Alternative library but focuses on bot API rather than user accounts, which is not suitable for this use case.

Alternative Libraries Comparison

  • Telethon (Python): The current Python implementation uses Telethon which provides easy access to Telegram's user API.
  • go-telegram-bot-api: Only supports bot API, not suitable for accessing group members.
  • gotd/td: Another Go MTProto client library, but more complex to use than gotgproto.

Decision: Use celestix/gotgproto as it provides the highest level of abstraction while still supporting user account authentication and group member access.

Authentication Flow

The authentication flow in gotgproto requires:

  1. Initial connection with API ID and hash
  2. Sending authentication code request to phone number
  3. User input of received code
  4. Optional 2FA password if enabled

Group Access by ID

  • Telegram groups can be accessed directly by their numeric group ID (chat ID)
  • This is more reliable than group names which can change
  • Group IDs can be positive or negative numbers (negative for supergroups/channels)

Data Model Research

Member Information Fields

Based on the Python implementation, the following member fields are accessible:

  • id: Unique user identifier (int64)
  • username: User's username (string, may be empty)
  • first_name: User's first name (string)
  • last_name: User's last name (string, may be empty)

File Output Format

  • JSON output format is required per specification
  • Output directory should be "out" in current working directory
  • Filename format: {groupname}_members_{YYYYMMDD}.json
  • Since we're using group ID instead of name, the filename will use the group ID

Error Handling Patterns

Common Error Scenarios

  • Authentication failures (invalid API credentials, incorrect code)
  • Rate limiting by Telegram
  • Permission errors (insufficient privileges to access group)
  • Network connectivity issues
  • Invalid group ID

Error Handling Strategy

  • Implement proper error wrapping with context
  • Provide user-friendly error messages
  • Graceful degradation where possible

Performance Considerations

Large Group Handling

  • For groups with many members, pagination will be handled automatically by the library
  • Progress indicators needed for large exports
  • Memory management for large datasets

Best Practices from Python Implementation

  • Sort members by ID for consistent output
  • Handle special characters in group names for file paths
  • Create output directory if it doesn't exist