mirror of
https://github.com/tiennm99/export-telegram-group-members.git
synced 2026-10-11 03:13:26 +00:00
f03099a18e83e7efd19e170b20e5878ace52162c
Replace the device-bound Telethon .session file and local CSV folders with Redis-backed storage so the tool runs on any device from just .env. - StringSession persisted at <prefix>:session:<phone> (no re-login per device) - each group export saved as one self-contained JSON key per run: <prefix>:run:<phone>:<yyyymmddhhmmss>:<group_id> - REDIS_PREFIX namespaces all keys; applied via a single key() helper - no cross-key references: deleting any key cannot corrupt another's state - list_exports() lists history, tolerant of deleted/corrupt keys
export-telegram-group-members
Export Telegram group members using Telethon — admin auth required for full member visibility. Session and export history are stored in Redis, so you can run the tool on any device from just a .env file (no re-login, no copying session/CSV files).
How to use
- Clone this repository:
git clone https://github.com/tiennm99/export-telegram-group-members.git
- Install requirements:
pip install -r requirements.txt
- Create a new Telegram app at https://my.telegram.org and get the
api_idandapi_hash. - Create a free Redis database (e.g. Upstash) and copy its
rediss://connection URL. - Copy
.env.exampleto.envand fill inAPI_ID,API_HASH,PHONE,GROUP_IDS, andREDIS_URL. - Run the script:
python main.py
The first run asks for the Telegram login code once, then stores the session in Redis. Any later run — on any device pointed at the same Redis — reuses that session and does not prompt again.
Configuration
| Variable | Description |
|---|---|
PHONE |
Telegram account phone (e.g. +1234567890) |
API_ID / API_HASH |
From my.telegram.org |
GROUP_IDS |
Comma-separated group IDs to export |
REDIS_URL |
Redis connection string (rediss://default:<password>@<host>:<port>) |
REDIS_PREFIX |
Key namespace (default telegram-export); isolates keys when sharing Redis with other projects |
How data is stored
All data lives in Redis under REDIS_PREFIX. No key references another, so deleting any key can never corrupt another's state:
<prefix>:session:<phone> -> StringSession string (login)
<prefix>:run:<phone>:<yyyymmddhhmmss>:<group_id> -> one group's export as JSON:
{ group_id, title, time,
members: [{ id, username, first_name, last_name }] }
Each group is written as its own key per run; all groups in one run share the same yyyymmddhhmmss timestamp. Read the history programmatically:
from common import list_exports
for rec in list_exports(): # sorted by (time, group_id)
print(rec['time'], rec['group_id'], rec['title'], len(rec['members']), 'members')
Rate limits and visibility notes
- Telegram limits how fast you can fetch participants; large groups may take longer.
- For supergroups, only admins can retrieve the full member list — regular members see a partial list or get an error.
- For private groups where you are not a member, access will be denied.
Security
- The session string grants full access to your Telegram account. It lives only in Redis (use a TLS
rediss://URL) and is never written to disk or committed to git. .envis git-ignored. Never commit yourREDIS_URLor session string.
License
Apache-2.0 — see LICENSE.
Description
Export Telegram group members to CSV using Telethon — admin auth required for full member visibility.
Readme
Apache-2.0
595 KiB
0 Stars
1 Watchers
0 Forks
Languages
Python
100%