A Pyrogram-based Telegram downloader/leech bot optimized for Heroku/Docker. It monitors source channels, renames and brands files, persists queue jobs, downloads direct links/torrents/magnets and uploads with suffix
- Auto-queue documents and videos from configured source channels.
- Bulk Telegram message import with
/addque. - Multi-backend leeching:
aria2cfor torrents/magnets,yt-dlpfor YouTube/Twitter(X)/Instagram/TikTok/Reddit/Facebook/SoundCloud/Vimeo and 100s of other sites, and a parallel-range HTTP downloader for plain direct links. - Telegram-origin files (queue jobs,
/leechreplies to.torrentfiles) are fetched by first minting a temporary stream link — the same mechanism/linkuses — then downloading that link over HTTP with parallel byte-range requests, instead of pulling the file straight through Pyrogram's MTProto download call. Falls back to a direct download automatically if the self-serve HTTP path is unavailable. - Rich
/startdashboard with callback buttons. - Automatic Telegram command registration on startup.
- Rename cleanup token system and MNTGX suffix branding.
- Optional video watermark in the center plus metadata text:
Join @MNTGX in Telegram. - Cover card generation before upload with the thumbnail placed in the top-right.
- Global thumbnail support.
- FloodWait-safe retries, progress bars, queue persistence in MongoDB, restart recovery, speed stats, ETA, and concurrency controls.
- Heroku-friendly health endpoint (
/health) and Procfile support.
| Command | Description |
|---|---|
/start |
Open the rich dashboard. |
/help |
Show command list. |
/mntgx |
Admin feature panel. |
/leech <url|magnet> |
Leech direct links, torrents, magnets, or YouTube/Twitter(X)/Instagram/TikTok/Reddit/Facebook/SoundCloud/... links via yt-dlp. Also accepts URLs containing torrent. |
/link |
Reply to Telegram media to create a temporary browser/FDM/1DM download link. |
/torrent / /magnet |
Aliases for leeching. |
/stats |
Queue, speed, and ETA stats. |
/addque <first_msg_url> <last_msg_url> |
Bulk import Telegram messages. |
/addsource, /removesource, /listsources |
Manage source channels. |
/addtarget, /removetarget, /listtargets |
Manage destination channels. |
/addremname, /listremname |
Manage filename cleanup tokens. |
/cleanque confirm |
Clear queued jobs. |
/requeue |
Resume jobs saved in MongoDB. |
/ping |
Health check. |
| Variable | Required | Default | Notes |
|---|---|---|---|
API_ID |
Yes | empty | Telegram API ID. |
API_HASH |
Yes | empty | Telegram API hash. |
BOT_TOKEN |
Yes | empty | Bot token from BotFather. |
BASE_URL |
Recommended | empty | Public app URL, e.g. https://your-app.herokuapp.com, used for /link, internal fetches, and default Heroku keep-alive pings. If unset, internal fetches fall back to http://127.0.0.1:$PORT, but public /link and anti-idle pings need a real public URL. |
KEEP_ALIVE |
No | 1 |
Enables the Heroku anti-idle health ping loop when BASE_URL or KEEP_ALIVE_URL is set. Use 0 to disable. |
KEEP_ALIVE_URL |
No | BASE_URL |
Public URL to ping for keeping a Heroku web dyno warm. Set this to your app URL if BASE_URL is used for another domain. |
KEEP_ALIVE_INTERVAL |
No | 600 |
Seconds between keep-alive pings. Minimum is 60 seconds; 600 seconds keeps traffic below Heroku sleep thresholds for web dynos. |
STREAM_LINK_TTL |
No | 21600 |
Temporary file-link lifetime in seconds. |
DB_URL |
Yes | empty | MongoDB connection string. |
DB_NAME |
No | Cluster0 |
Mongo database name. |
ADMIN |
No | 1892771262 |
Space-separated admin user IDs. |
LOG_CHANNEL |
No | configured ID | Channel for logs if used. |
GLOBAL_THUMBNAIL_URL |
No | bundled image | Used for upload thumbnails and cover cards. |
MAX_CONCURRENT_DOWNLOADS |
No | 2 |
Hard-capped at 5 workers; keep low on Heroku eco/basic dynos. |
MAX_CONCURRENT_UPLOADS |
No | 2 |
Hard-capped at 5 uploads; keep low on Heroku eco/basic dynos. |
MIN_TRANSFER_SPEED_MBPS |
No | 4 |
Progress warning threshold. |
MAX_UPLOAD_SIZE_GB |
No | 2 |
Maximum file size accepted by the bot. Set 4 only when PREMIUM_SESSION_STRING is a Telegram Premium user session and that user is admin/member in target channels. |
PREMIUM_SESSION_STRING |
No | empty | Pyrogram user session string used as a separate uploader for 2GB+ documents. Without it, uploads use the bot client and Telegram bot limits still apply. |
GOFILE_API_TOKEN |
Recommended for GoFile | empty | GoFile account API token used to resolve gofile.io/d/... share links without yt-dlp. Direct storage URLs from <source src> still work without it. |
ENABLE_MEDIA_BRANDING |
No | 0 |
Enable ffmpeg watermark/metadata. Disabled by default to avoid Heroku memory kills; turn on for bigger dynos. |
WATERMARK_TEXT |
No | @MNTGX |
Center watermark text. |
METADATA_TEXT |
No | Join @MNTGX in Telegram |
Metadata and cover brand text. |
SEND_COVER_BEFORE_UPLOAD |
No | 1 |
Send cover preview before each file. |
CLEAN_DOWNLOADS |
No | 1 |
Remove leech job files after completion. |
PYROGRAM_WORKERS |
No | 24 |
Bounded 8-64 to avoid high memory usage. |
ARIA2_SPLIT |
No | 6 |
Bounded 1-16 aria2c connections per torrent job. The parallel-range HTTP downloader and yt-dlp's fragment downloader read the same value but independently cap at 8 workers. |
FFMPEG_THREADS |
No | 1 |
Bounded 1-2 ffmpeg threads for watermarking. |
Heroku Eco/free-style web dynos can sleep when there is no web traffic. The bot now starts a background keep-alive loop after the /health web server is bound. Set BASE_URL (or KEEP_ALIVE_URL) to your public Heroku app URL, for example https://your-app.herokuapp.com; the bot will request /health every KEEP_ALIVE_INTERVAL seconds (default: 10 minutes). If you use a paid always-on dyno or an external uptime monitor, set KEEP_ALIVE=0 to disable the internal pinger.
Torrent and magnet support requires aria2c on the runtime image. The included Dockerfile installs aria2, ffmpeg, and fonts automatically. On Heroku, the bundled app.json now declares the heroku-community/apt buildpack before heroku/python, so one-click "Deploy to Heroku" installs Aptfile (aria2, ffmpeg, fonts-dejavu-core) automatically. If you deployed with an older version of this repo, open your app's Settings → Buildpacks and add heroku-community/apt above heroku/python manually, then redeploy once. If aria2c is still missing, direct HTTP links and yt-dlp-supported sites keep working, but torrent and magnet jobs need aria2 — there's no HTTP-only substitute for BitTorrent.
/leech recognizes links from YouTube, Twitter/X, Instagram, TikTok, Reddit, Facebook, SoundCloud, Vimeo, Dailymotion, Twitch, and many other sites and routes them through yt-dlp, which is already listed in requirements.txt. GoFile links are resolved by the bot without yt-dlp; it tries the optional gofile-dl CLI using its standard gofile-dl <url> guest-account flow, then the optional gofile-api library resolver, and then the built-in resolver. Set GOFILE_API_TOKEN for reliable gofile.io/d/... share-page resolution. If yt-dlp isn't installed on your deployment, those links fail with a clear message telling you to add it and redeploy; plain direct-file URLs and torrents/magnets are unaffected either way.
Plain direct-file URLs (and the internal Telegram-file-via-link fetch used by queue jobs) use a parallel-range HTTP downloader: for servers that advertise Accept-Ranges: bytes and files at least 8MB, the download is split into up to 8 concurrent byte-range requests (derived from ARIA2_SPLIT, capped independently of aria2's own connection count) instead of one sequential stream. Servers without range support fall back to the original single-stream download automatically.
Telegram Bot API uploads are usually limited to 2GB. When PREMIUM_SESSION_STRING is set, the bot starts a separate Pyrogram user uploader and uses it for send_document, allowing 2GB+ documents when the session belongs to an account that can upload that size (Telegram Premium for up to 4GB) and that account has permission to post in the destination chat/channel. Set MAX_UPLOAD_SIZE_GB=4 only with that Premium/user uploader; without it, keep MAX_UPLOAD_SIZE_GB=2.
- Create a bot with BotFather and collect
BOT_TOKEN. - Create Telegram API credentials at
my.telegram.org. - Provision MongoDB and set
DB_URL. - Install Python requirements and system packages:
ffmpeg,aria2c, and DejaVu fonts. If you deploy via the "Deploy to Heroku" button,app.jsonnow addsheroku-community/aptbeforeheroku/pythonautomatically. If you deploy viagit push heroku/ Heroku CLI instead, runheroku buildpacks:add --index 1 heroku-community/aptonce so it installs before the Python buildpack. SetBASE_URLto your Heroku app URL to enable/linkand the internal link-based Telegram fetch. - Start with
python bot.pyor deploy with the includedProcfile.