Skip to content

Latest commit

ย 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MirrioX Sync: Intelligent Telegram Backup & Sync Automation Bot

Intelligent Telegram Backup & Sync Automation

Copy entire Telegram channels (history, albums, media and all) across as many userbot accounts as you own.
Hebrew management bot. Crash-proof checkpoints. Real parallelism.


Quick Start Parallel Copying Architecture



Python Telethon SQLite asyncio Hebrew UI

Last commit Repo size Stars


๐Ÿ“‘ Table of Contents

Getting started

Copying

Operations


โœจ Features

๐Ÿค– Truly parallel

One runner per userbot account, all copying at once: across jobs, and inside a single job once two accounts can reach its channels.

๐Ÿงฉ Chunked & resumable

A job's ID range is split into ~200 chunks, each with its own checkpoint. Kill the process mid-copy; it resumes exactly where it stopped.

๐Ÿ›Ÿ Never copies twice

Every processed message ID is recorded. Stale checkpoints, crashes and reclaimed chunks can't produce a duplicate.

๐Ÿ“… Per-account quotas

Telegram limits are per account, so the daily cap is too. A spent account steps aside; the rest keep going at full speed.

๐Ÿ” Per-account access

One account may be in a channel while another isn't. Each probes for itself, and the UI reports exactly who can reach what.

๐Ÿ–ผ๏ธ Albums & protected sources

Media groups stay grouped. "No forwarding" channels fall back to download-and-reupload automatically.

๐Ÿ”„ Continuous sync

Copy the history, then keep listening for new messages in real time, with the same filters and dedup.

๐Ÿ” Duplicate scanner

Scan a channel for duplicated media, get a Telegraph report with links, and bulk-delete the waste.

๐Ÿ‡ฎ๐Ÿ‡ฑ Hebrew control panel

A single message, edited in place, never a wall of new ones. Jobs, sources, filters and settings, all inline.


๐Ÿง  Architecture

Two processes that share nothing but a SQLite file:

Component Library Role
๐Ÿค– Management bot Telethon (MTProto bot mode) Hebrew UI, job creation, configuration
๐Ÿ‘ท Userbot worker Telethon (MTProto user mode) Executes copy jobs, updates progress

Important

SQLite is the only IPC channel. Neither process ever calls the other directly.

graph TD
    subgraph BOT["๐Ÿค– Management Bot"]
        UI["๐Ÿ‡ฎ๐Ÿ‡ฑ Hebrew control panel"]
    end

    DB[("๐Ÿ—„๏ธ SQLite ยท WAL")]

    subgraph WORKER["๐Ÿ‘ท Userbot Worker"]
        M["๐ŸŽ› UserbotManager"]
        M --> R1["Runner ยท account 1"]
        M --> R2["Runner ยท account 2"]
        M --> R3["Runner ยท account N"]
    end

    UI <-->|"jobs, sources, settings"| DB
    DB <-->|"claim ยท checkpoint ยท progress"| M
    R1 --> TG(["๐Ÿ“ก Telegram"])
    R2 --> TG
    R3 --> TG

    style DB fill:#0D1117,stroke:#06B6D4,color:#fff
    style TG fill:#0088CC,stroke:#0088CC,color:#fff
Loading

The job lifecycle

stateDiagram-v2
    [*] --> draft
    draft --> pending: submit
    pending --> running: claimed by an account
    running --> completed: source exhausted
    running --> waiting_retry: FloodWait / error
    waiting_retry --> pending: next_retry_at passes
    running --> paused: user, or max retries
    paused --> pending: resume
    running --> failed: retries exhausted
    running --> cancelled: user
    completed --> [*]
    failed --> [*]
    cancelled --> [*]
Loading

๐Ÿš€ Quick Start

# 1 ยท install
pip install -r requirements.txt

# 2 ยท configure
cp example.env .env      # then fill it in (see below)

# 3 ยท authenticate the userbot (one time, asks for phone + code)
python main.py setup

# 4 ยท go
python main.py all
โš™๏ธ ย What goes in .env
Variable Where from
BOT_TOKEN @BotFather
TELETHON_API_ID my.telegram.org
TELETHON_API_HASH my.telegram.org
TELETHON_SESSION Path for the session file, e.g. sessions/userbot
ADMIN_IDS Comma-separated Telegram user IDs allowed to use the bot

The .env account is registered automatically as the default userbot on first run. Every account after that is added from the bot UI, with no .env edits needed.

๐Ÿƒ ย Run modes
Command What it starts
python main.py all Bot and worker in one process (simplest)
python main.py bot Management bot only
python main.py worker Userbot worker only
python main.py setup One-time session authentication

bot and worker can run as two separate processes instead; they coordinate through the database either way.

๐Ÿ“‹ ย Requirements
  • ๐Ÿ Python 3.11+
  • ๐Ÿ‘ค One or more Telegram accounts (for the userbots)
  • ๐Ÿค– A Telegram bot token
  • ๐Ÿ”‘ API credentials from my.telegram.org

๐ŸŽฎ Usage

graph LR
    A["๐Ÿš€ /start"] --> B["โž• Add source<br>and destination"]
    B --> C["๐Ÿค– Add accounts<br><i>optional</i>"]
    C --> D["๐Ÿ“ Create job"]
    D --> E["๐Ÿ“ค Submit"]
    E --> F["๐Ÿ“Š Watch it run"]

    style A fill:#06B6D4,stroke:#06B6D4,color:#fff
    style F fill:#D98324,stroke:#D98324,color:#fff
Loading
  1. ๐Ÿš€ Send /start to the management bot, and a Hebrew control panel appears
  2. โž• Add source and destination channels via the UI
  3. ๐Ÿค– (optional) Add more userbot accounts: โš™๏ธ ื”ื’ื“ืจื•ืช โ†’ ๐Ÿค– ื—ืฉื‘ื•ื ื•ืช ื™ื•ื–ืจื‘ื•ื˜
  4. ๐Ÿ“ Create a job (pick a copy mode and its parameters)
  5. ๐Ÿ“ค Submit, and the worker picks it up automatically
  6. ๐Ÿ“Š Watch progress in the job detail screen (press Refresh)

๐Ÿ“‹ Copy Modes

Mode Description
โ™พ๏ธ All messages Every accessible message in the source
๐Ÿ“… Date range Between two dates (DD/MM/YYYY HH:MM, Israel local time)
๐Ÿ”ข ID range Between two numeric message IDs
๐ŸŽฏ Single message One specific message, by ID
๐Ÿ”„ Continuous Copy the history, then keep listening for new messages

๐Ÿค– Multi-Account & Parallel Copying

Every active account gets its own runner: its own Telethon client, its own copy engine, its own claim loop. They all work at the same time.

graph TD
    Q["๐Ÿ“ฅ Queue"] -->|claim_next_job| L["๐Ÿค– Leader"]
    L --> S{"2+ accounts<br>reach both channels?"}
    S -->|"no"| ORD["โžก๏ธ One ordered pass<br><i>source order preserved</i>"]
    S -->|"yes"| C["๐Ÿงฉ Split into ~200 chunks"]
    C --> W1["๐Ÿค– Leader<br>works chunks"]
    C --> W2["๐Ÿค– Free account<br>joins"]
    C --> W3["๐Ÿค– Free account<br>joins"]
    W1 --> F["๐Ÿ Leader waits for<br>the stragglers, then<br>closes the job"]
    W2 --> F
    W3 --> F

    style S fill:#0D1117,stroke:#D98324,color:#fff
    style ORD fill:#06B6D4,stroke:#06B6D4,color:#fff
    style C fill:#D98324,stroke:#D98324,color:#fff
    style F fill:#0D1117,stroke:#06B6D4,color:#fff
Loading

How work is shared

  • Across jobs. Two queued jobs and two accounts mean each takes a whole job of its own. Always preferred: it is the fastest option and it preserves message order everywhere.
  • Within one job. When nothing new is left to claim, free accounts join a job already in progress. The account that claimed it (its leader) checks how many active accounts can reach both channels:
Accounts with access What happens
1 A single ascending pass, exactly how a single-account install behaves
2+ The source ID range is split into ~200 chunks; every free account claims chunks of its own

Chunks are claimed atomically, so no two accounts ever touch the same message. Throughput scales with the number of accounts, and so does the daily quota, since Telegram enforces its limits per account.

Warning

Order is the trade-off. Within a chunk the order is the source's, but chunks are copied concurrently and therefore interleave in the destination. This is inherent to splitting one job across accounts, not an implementation detail. If strict source order matters, run the job while only one account can reach the channels.

Per-account facts

Note

Almost everything Telegram enforces is per account, not per job. The design follows that boundary rather than fighting it.

  • Access is per account. One account may be a member of a channel while another is not. Each probes every channel for itself, and the channel detail screen reports exactly who can reach it.
  • The daily cap is per account. A spent account simply stops claiming while the others carry on. Only when every account is capped does the queue park until midnight (Israel time), and the admin is told.
  • Adding an account clears every job's exclusion list, since a new account may have access where the others didn't, so failed jobs get another chance.

๐Ÿ“ฆ Content Types

โœ… Supported

  • Text
  • Photos
  • Videos
  • Documents / files
  • Captions
  • Albums (media groups)

โŒ Not supported

  • Polls
  • Games
  • Invoices
  • Live locations

Each job picks which of text ยท image ยท video ยท file to copy. Protected ("no forwarding") sources are detected automatically and fall back to download-and-reupload.


๐Ÿ”’ Blocked Words

Configure a list of blocked words in the bot UI. Any message containing one, in text or caption, is skipped entirely. No editing, no partial removal: the whole message is skipped, and the count is tracked per job.


๐Ÿš‘ Restart Recovery

Built to survive process crashes:

Guarantee
๐Ÿ”„ Worker crash mid-job. On next startup the worker spots the running job and re-queues it as pending. Every account assignment and held chunk from the previous run is released.
๐Ÿ“ Resume from checkpoint. An unsharded job resumes from jobs.last_processed_id. A sharded job keeps a checkpoint per chunk, so only the unfinished part of an interrupted chunk is redone. Finished chunks are never revisited.
๐Ÿซ€ Abandoned chunks. A chunk whose owner has been silent for 30 minutes goes back to the queue. The window is deliberately generous: reclaiming too early would let two accounts copy the same messages.
๐Ÿ›Ÿ Duplicate prevention. copied_messages records every processed source message ID. Nothing there is ever re-sent, even if a checkpoint is stale.
๐Ÿ•’ FloodWait. The job moves to waiting_retry with a next_retry_at, which the poll loop honours across restarts. A flood wait on a helper account never stalls the job; the others keep going.

๐Ÿงฑ Project Structure

๐Ÿ“‚ ย Tree
app/
โ”œโ”€โ”€ ๐Ÿ“„ config.py                  # โš™๏ธ environment config
โ”œโ”€โ”€ ๐Ÿ“„ db.py                      # ๐Ÿ—„๏ธ SQLite connection, schema, migrations
โ”œโ”€โ”€ ๐Ÿ“„ models.py                  # ๐Ÿ“ฆ typed dataclasses
โ”œโ”€โ”€ ๐Ÿ“„ network_errors.py          # ๐Ÿ”Œ network-failure classification
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ repositories/              # ๐Ÿ—ƒ๏ธ Database access (one file per entity)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ job_repo.py            # job lifecycle, additive progress, atomic claiming
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ job_chunk_repo.py      # ๐Ÿงฉ chunk planning/claiming, parallel copying
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ userbot_repo.py        # userbot accounts, sessions, default account
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ channel_access_repo.py # per-account channel access results
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ dedup_repo.py          # global transferred-content registry
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ scan_repo.py           # duplicate scans and delete jobs
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ source_repo.py         # sources and destinations
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ filter_repo.py         # blocked words
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ admin_repo.py
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ state_repo.py          # worker state, heartbeat, app_settings
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ services/                  # ๐Ÿง  Business logic
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ job_service.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ userbot_auth_service.py # interactive sign-in (phone โ†’ code โ†’ 2FA)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ telegraph_service.py   # Telegraph reports for failed/skipped messages
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ validation_service.py
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ ui/                        # ๐ŸŽจ Interface building
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ texts.py               # ๐Ÿ‡ฎ๐Ÿ‡ฑ all Hebrew strings
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ keyboards.py
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ renderer.py
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ bot/                       # ๐Ÿค– Management Bot (Telethon MTProto)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ bot_main.py
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ state.py
โ”‚   โ””โ”€โ”€ ๐Ÿ“‚ handlers/
โ”‚
โ””โ”€โ”€ ๐Ÿ“‚ worker/                    # ๐Ÿ‘ท Userbot Worker
    โ”œโ”€โ”€ ๐Ÿ“„ worker_main.py         # ๐Ÿš‘ startup recovery, notifications, primary duties
    โ”œโ”€โ”€ ๐Ÿ“„ userbot_manager.py     # ๐Ÿค– one runner per account, claiming, parallelism
    โ”œโ”€โ”€ ๐Ÿ“„ copy_engine.py         # ๐Ÿง  Telethon copy logic + shard planning
    โ”œโ”€โ”€ ๐Ÿ“„ scan_engine.py         # ๐Ÿ” duplicate scanning and bulk delete
    โ”œโ”€โ”€ ๐Ÿ“„ rate_limiter.py        # โณ delays and batch pauses
    โ””โ”€โ”€ ๐Ÿ“„ telegram_utils.py      # ๐Ÿ”— entity resolution

๐Ÿ“„ main.py                        # ๐Ÿš€ entry point (all | bot | worker | setup)

๐Ÿšฆ Safety Defaults

Tip

Every one of these is adjustable from the Settings screen in the management bot.

Setting Default
โฑ๏ธ Delay between messages 2.0 โ€“ 5.0s random (doubled after an album)
๐Ÿงบ Batch pause 60 โ€“ 120s after every 50 โ€“ 100 messages
๐ŸŒŠ FloodWait buffer 5 โ€“ 10s extra, random
๐Ÿ”„ Max retries 5 before a job fails or pauses
๐Ÿ“… Daily limit 20,000 messages per account
โšก Concurrency One runner per active account, all working at once


Made with โค๏ธ by Omer

Contribute, improve, and make automation better.

GitHub

Releases

Contributors

Languages