Copy a Telegram chat’s full history into another chat as new messages (not forwards), then mirror live posts. Built for channels that block forwarding or when you want a clean destination feed.
Run: python3 -u telegram_mirror.py -i · Configure: .env.example
| Section | What it covers |
|---|---|
| Quick start | Install, .env, first run |
Interactive menu (-i) |
Terminal prompts in order |
| Features | Behaviour summary |
| CLI flags | Command-line options |
| Environment variables | TG_* and related |
| Diagnostics | diagnose.py |
| Security & legal | Secrets and ToS |
From the telegram-chat-mirror project directory:
pip install -r requirements.txt
cp .env.example .env
# Edit .env — required keys are listed inside the file
python3 -u telegram_mirror.py -itelegram_mirror.py loads .env from the same folder if present (it does not override variables already set in your shell).
Pass -i or --interactive on a real terminal (TTY). You will see English prompts in this order:
| Step | Prompt | What to do |
|---|---|---|
| A | Source chat ID (TG_SOURCE_CHAT…) only if IDs missing from .env |
Paste numeric ID (often -100…) |
| B | Target chat ID… only if missing |
Same |
| C | Change source/target IDs? [y/N]: only if both were already in .env |
n = keep |
| D | 1) Standard 2) Reset all history 3) Live only 4) Re-login then Choice [1]: |
Pick mode |
| E | After 4) Re-login, maybe Also reset copy progress? [y/N]: |
Optional |
Then Telegram may send a login code to TG_PHONE.
No TTY (cron / systemd):
TG_NON_INTERACTIVE=1 python3 -u telegram_mirror.pyflowchart LR
A[Run with -i] --> B{IDs in .env?}
B -->|No| C[Prompt source & target]
B -->|Yes| D[Optional: change IDs?]
C --> E[Pick mode 1-4]
D --> E
E --> F[Connect & backfill / listen]
- Backfill then live listener; progress in
last_id.txtnext to the session file - Interactive English menu + CLI flags for automation
- Media caption and text length limits (1024 / 4096) handled
- Optional
TG_FOOTERsuffix per message - No API secrets in source — use
.env(see.env.example)
| Flag | Meaning |
|---|---|
-i, --interactive |
Menu (needs TTY) |
--reset-progress |
Copy full history again |
--skip-history |
Only new messages after connect |
--relogin |
Delete session files before login |
--source ID / --target ID |
Override chats for this run |
| Variable | Required | Purpose |
|---|---|---|
TG_API_ID |
yes | my.telegram.org |
TG_API_HASH |
yes | Same |
TG_PHONE |
yes | E.164 |
TG_SOURCE_CHAT |
yes* | Source chat ID |
TG_TARGET_CHAT |
yes* | Target chat ID |
TG_FOOTER |
no | Suffix; unset = none |
TG_SESSION_DIR |
no | Session + last_id.txt directory |
TG_NON_INTERACTIVE |
no | 1 / true / yes = no prompts |
RESET_PROGRESS / SKIP_HISTORY / FORCE_NEW_LOGIN |
no | Same as matching flags |
*Or --source / --target, or -i and enter IDs when asked.
Use user-client IDs (e.g. @RawDataBot). Supergroups/channels are usually -100…. Your account must join the target and be allowed to post.
python3 diagnose.py- Never commit
.env,*.session, orlast_id.txt. See SECURITY.md. - Respect Telegram ToS, channel rules, and copyright. You are responsible for how you use this tool.
See CONTRIBUTING.md.