Skip to content

emreyn1/Telegram-Auto-mirror

Repository files navigation

Telegram Chat Mirror

License: MIT Python 3.9+ Telethon

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


Contents

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

Quick start

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 -i

telegram_mirror.py loads .env from the same folder if present (it does not override variables already set in your shell).


Interactive menu (-i)

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.py
flowchart 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]
Loading

Features

  • Backfill then live listener; progress in last_id.txt next to the session file
  • Interactive English menu + CLI flags for automation
  • Media caption and text length limits (1024 / 4096) handled
  • Optional TG_FOOTER suffix per message
  • No API secrets in source — use .env (see .env.example)

CLI flags

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

Environment variables

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.

Chat IDs

Use user-client IDs (e.g. @RawDataBot). Supergroups/channels are usually -100…. Your account must join the target and be allowed to post.


Diagnostics

python3 diagnose.py

Security & legal

  • Never commit .env, *.session, or last_id.txt. See SECURITY.md.
  • Respect Telegram ToS, channel rules, and copyright. You are responsible for how you use this tool.

Contributing

See CONTRIBUTING.md.

About

Telegram Auto Mirror: Copy full chat history as new messages (not forwards) + live mirroring. Perfect for channels that block forwarding or clean destination feeds.

Topics

Resources

License

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages