Skip to content

About

Telegram-MRG — the easiest way to mass-delete Telegram messages. Scan any chat, group or channel, preview what you found (media included), filter by date and sender, and delete with one click. Runs locally in your browser or as a CLI.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Telegram-MRG — Telegram Messages Remove GUI

Mass-delete messages from any Telegram chat, group, supergroup or channel — via a modern web interface that runs locally on your machine. Cross-platform: Windows, macOS, Linux (Python 3.8+).

It uses the official Telegram MTProto API through Telethon — the same API the official apps use. Messages are deleted for real, exactly as if you deleted them one by one in the app.

What you get

  • Web UI (app.py) — a polished dark interface: sign-in with phone or bot, searchable chat picker, date-range and last-N scan filters, live scan progress, full review list with per-message checkboxes, media previews and select-all, automatic admin detection, delete scopes (my / others' / for everyone), confirmation dialog, real-time delete progress with a media/text result summary.
  • CLI (telegram_mass_delete.py) — the same functionality from the terminal, scriptable with flags for power users.
  • One-click launchers for every OS — no manual Python setup needed (see below).

Quick start

  1. Install Python 3.8+ from https://python.org (Windows: tick "Add Python to PATH" during install)
  2. Get free API credentials:
    • Go to https://my.telegram.org/apps
    • Log in with your phone number
    • Click API development tools and create an app
    • Copy the api_id and api_hash you get
  3. Launch the app — pick your platform:
Platform Web UI CLI
Windows double-click start.bat double-click cli.bat
Windows (PowerShell) .\start.ps1 .\cli.ps1
Linux / macOS ./start.sh ./cli.sh

Launchers create a virtual environment (.venv/) and install dependencies automatically on first run. The web UI opens your browser at http://127.0.0.1:8765.

Credentials — three ways

Credentials are resolved in this order:

  1. .env file — copy .env.example to .env and fill in the values:
    TG_API_ID=1234567
    TG_API_HASH=0123456789abcdef0123456789abcdef
  2. Environment variables — set TG_API_ID and TG_API_HASH in your shell (used by both the web UI and the CLI).
  3. Web UI setup screen — enter them once; they are saved to telegram_config.txt in the project folder.

The web UI saves credentials to telegram_config.txt when you submit the setup form; .env/env vars take precedence only when no config file exists.

Usage — web interface

The app walks you through five steps, and every screen shows a short instruction box at the top explaining what to do:

  1. Credentials — see above
  2. Sign in — phone number + verification code (two-step password supported), or a bot token from @BotFather. The country/prefix selector picks your country automatically from the browser language; change it if needed.
  3. Chat — searchable list of your chats; click to select. The filter text is kept when you return via the home button — the same filter is applied immediately on the reloaded list.
  4. Scan options — shows the selected chat with its total message count, then lets you pick the period: "Scan all messages from all periods" (default) or a From/To range with separate date + time pickers (clicking a day selects it and closes the calendar); optionally limit to the last N messages. The scan always stops at the From boundary, even for member accounts that can only see their own messages.
  5. Result — live scan progress with percentage (estimated against the selected period, not the whole chat), selected period summary, and every found message listed in a scrollable window with a checkbox each — text is shown with a media icon and a small thumbnail preview for photos/videos/GIFs, plus "mine/other" tags. The admin/member check runs before the scan: for members (and private chats) only your own messages are collected, with a note explaining it; admins get everything. The app also shows your role (green = admin, amber = member, blue = private chat) and, next to the messages, the delete options:
    • Delete my messages — only messages you sent (auto-checked for members/private chats).
    • Also delete others' messages — admin-only; greyed out for regular members and in private chats.
    • Delete for everyone — removes messages for all participants (admin rights are needed to delete others' messages; if off, messages disappear only for you). Select all picks everything at once (it unchecks automatically when any message is unselected); you can delete only the checked ones. A confirmation dialog always appears first. Stop scanning (amber, highly visible) keeps what was found so far and Stop deleting halts the deletion; while a stop is in progress an amber banner shows "Stopping scan / deletion — keeping the messages found/deleted so far…" and the button switches to a disabled "Stopping…". Deleted messages stay visible in the list with reduced opacity. When finished, a summary shows how many messages were removed, split into media vs text. Scan again returns to the scan options with the same chat selected.

Manual run / extra flags:

python app.py                       # default port 8765, opens browser
python app.py --port 9000           # different port
python app.py --no-open             # don't auto-open the browser

Usage — CLI

python telegram_mass_delete.py                          # interactive (picker + prompts)
python telegram_mass_delete.py --chat "@mygroup" --mine-only --yes
python telegram_mass_delete.py --chat 123456789 --limit 500
python telegram_mass_delete.py --chat "@mygroup" --after 2024-01-01 --before 2024-06-30

PowerShell users can pass single-dash flags: .\cli.ps1 -Chat @mygroup -MineOnly -Yes.

Option Meaning
--chat Target a username, @username, or numeric chat ID (skips the picker)
--mine-only Only delete messages you sent
--limit N Only process the last N messages
--after YYYY-MM-DD Only delete messages newer than the date (inclusive to today if --before unset)
--before YYYY-MM-DD Only delete messages older than the date (inclusive from the start if --after unset)
--yes Skip confirmation prompts (be careful)

Period semantics: a one-sided range is inclusive — --after alone selects everything from that date to now; --before alone selects everything up to that date. In the web UI, "Scan all messages from all periods" (default) disables the From/To filters entirely.

Project structure

telegram-remove-message/
├── app.py                    # FastAPI backend (web UI)
├── telegram_mass_delete.py   # CLI tool
├── static/                   # Web UI frontend (HTML/CSS/JS, no build step)
├── requirements.txt          # Python dependencies
├── start.bat / start.ps1 / start.sh    # web UI launchers
├── cli.bat / cli.ps1 / cli.sh          # CLI launchers
├── .env.example              # environment variable template
├── telegram_config.txt       # created on first use (secrets — never commit)
├── telegram_session.session  # created after login (secrets — never commit)
└── .venv/                    # created by launchers (never commit)

Important limits (set by Telegram)

  • You can only delete other people's messages if you are a group/channel admin — or in private chats, where only your own messages can be deleted (unless you administer the bot). The web UI detects your role before the scan starts: members (and private chats) get only their own messages collected, and the "others' messages" option stays greyed out for them.
  • In megagroups and channels messages can only be deleted for everyone.
  • Deletion is done in batches of 100 with built-in rate-limit handling; very large chats take a while — the progress bar keeps you informed.
  • Message counts are fetched on demand: the total shown on the scan options screen is requested from Telegram only for the chat you select. The chat list itself shows no per-chat counts — Telegram's API has no bulk way to get them, and reading the count for every chat would need one request per chat, which Telegram rate-limits (FLOOD_WAIT, a few requests/second per account) and would make the list crawl or stall on accounts with many chats.
  • Deleted messages cannot be recovered.

Troubleshooting

Symptom Fix
start.bat says Python not found Install Python from python.org; on Windows re-run the installer and tick Add Python to PATH
pip install fails on a dependency Retry — or upgrade pip: python -m pip install --upgrade pip
Stuck logged in as the wrong account Click Sign out in the web UI (deletes the session), or delete telegram_session.session
Asked for the verification code again after a restart Should not happen anymore — the saved session is detected on startup. If it still does, your session file may be corrupted: sign out, delete telegram_session.session, and sign in again
FloodWaitError / "please wait" You hit Telegram's rate limit; the app waits and retries automatically — just leave it running
Deletion is slow Normal for big chats: 100 messages per request, ~0.3 s between batches by design
Port 8765 is busy python app.py --port 9000 (or .\start.ps1 -Port 9000)

Security notes

  • api_hash, telegram_config.txt, telegram_session.session and .env are secrets — never commit or share them (they are git-ignored).
  • The session file stores your login; the Sign out button in the UI forces re-login.
  • Telegram may flag accounts that mass-delete aggressively; use responsibly.
  • The server binds to 127.0.0.1 only — nothing leaves your machine.

License & changelog

  • Licensed under the MIT License.
  • Changelog is kept locally only (see CHANGELOG.md on disk, not tracked by git).

About

Telegram-MRG — the easiest way to mass-delete Telegram messages. Scan any chat, group or channel, preview what you found (media included), filter by date and sender, and delete with one click. Runs locally in your browser or as a CLI.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages