High-performance Telegram File to Link Bot
About • ✨ Features • 🔍 How It Works • 📋 Prerequisites • Configuration • 📦 Deployment • 📱 Usage • ⌨️ Commands
Thunder is a powerful, high-performance Telegram bot that transforms media files into streamable direct links. Share and access files via HTTP(S) links instead of downloading from Telegram, for a seamless media experience.
Perfect for:
- 🚀 Download Telegram media at high speed.
- ☁️ Leveraging free unlimited cloud storage with high-speed links.
- 🎬 Content creators sharing media files.
- 👥 Communities distributing resources.
- 🎓 Educational platforms sharing materials.
- 🌍 Anyone needing to share Telegram media.
- Generate Direct Links: Convert Telegram media files into direct streaming links.
- Permanent Links: Links remain active as long as the file exists in the storage channel.
- Multi-Client Support: Distribute workload across multiple Telegram clients for high traffic.
- Browser Streaming: Stream media files directly in the browser without downloading.
- Broadcast Messages: Send messages to all users.
- Channel and Group Support: Works in private chats, groups, and channels.
- MongoDB Integration: Store user data and info with advanced database capabilities.
- HTTP/HTTPS Streaming: Stream media with custom player support for all devices and browsers.
- Flood Wait Handling: Centralized handling for Telegram flood waits.
- Token Authentication: Secure access with optional token-based authentication.
- URL Shortening: URL shortening for links.
- Batch Processing: Generate links for multiple files in a group chat.
- User Authentication: Require users to join channels before generating links.
- Admin Commands: Manage users and control bot behavior.
- Custom Domain Support: Use your own domain for streaming links.
- Customizable Templates: Personalize HTML templates for download pages.
- Data Center Info: Get data center information for users and files.
- Auto Set Commands: Automatically set bot commands on startup.
- Asynchronous Architecture: Built with aiohttp and asyncio for high concurrency.
- Media Info Display: Show file size, duration, format, and more.
- Multiple File Types: Supports videos, audio, documents, images, stickers, and more.
- Caching System: Reduce Telegram API calls and improve responsiveness.
- Customizable Messages: Personalize messages sent to users.
- Upload: User sends a media file to the bot. The bot forwards it to a storage channel and stores metadata.
- Link Generation: A unique, secure link is generated and sent to the user.
- Streaming: When the link is opened, the server authenticates, retrieves the file from Telegram, and streams it directly to the browser.
- Load Balancing: Multiple Telegram clients distribute workload, with automatic switching and smart queuing for high traffic.
- 🐍 Python 3.13 or higher
- 🍃 MongoDB
- 🔑 Telegram API ID and Hash (my.telegram.org/apps)
- 🤖 Bot Token from @BotFather
- 🌐 Server with public IP or domain
- 📦 Telegram storage channel
Rename config_sample.env
to config.env
and edit the following variables:
Variable | Description | Example |
---|---|---|
API_ID |
Telegram API ID from my.telegram.org | 12345 |
API_HASH |
Telegram API Hash from my.telegram.org | abc123def456 |
BOT_TOKEN |
Bot token from @BotFather | 123456789:ABCdefGHIjklMNOpqrsTUVwxyz |
BIN_CHANNEL |
Channel ID for storing files (add bot as admin) | -1001234567890 |
OWNER_ID |
Your Telegram user ID(s) (space-separated) | 12345678 87654321 |
DATABASE_URL |
MongoDB connection string | mongodb+srv://user:pass@host/db |
OWNER_USERNAME |
Your Telegram username (without @) | yourusername |
FQDN |
Your domain name or server IP | files.yourdomain.com |
HAS_SSL |
Set to "True" if using HTTPS | True or False |
PORT |
Web server port | 8080 |
NO_PORT |
Hide port in URLs | True or False |
Variable | Description | Default | Example |
---|---|---|---|
MULTI_BOT_TOKENS |
Additional bot tokens for load balancing | (empty) | MULTI_TOKEN1= |
FORCE_CHANNEL_ID |
Channel ID users must join | (empty) | -1001234567890 |
BANNED_CHANNELS |
Space-separated banned channel IDs | (empty) | -1001234567890 -100987654321 |
SLEEP_THRESHOLD |
Threshold for client switching | 300 |
600 |
WORKERS |
Number of async workers | 8 |
200 |
NAME |
Bot application name | ThunderF2L |
MyFileBot |
BIND_ADDRESS |
Address to bind web server | 0.0.0.0 |
127.0.0.1 |
PING_INTERVAL |
Ping interval in seconds | 840 |
1200 |
CACHE_SIZE |
Cache size in MB | 100 |
200 |
TOKEN_ENABLED |
Enable token authentication system | False |
True |
SHORTEN_ENABLED |
Enable URL shortening for tokens | False |
True |
SHORTEN_MEDIA_LINKS |
Enable URL shortening for media links | False |
True |
URL_SHORTENER_API_KEY |
API key for URL shortening service | "" |
"abc123def456" |
URL_SHORTENER_SITE |
URL shortening service to use | "" |
"example.com" |
SET_COMMANDS |
Automatically set bot commands on startup | True |
False |
ℹ️ For all options, see
config_sample.env
.
# Ensure you have configured config.env as per the Configuration section
# Build and run with Docker
docker build -t Thunder .
docker run -d --name Thunder -p 8080:8080 Thunder
# Ensure you have completed the "Getting Started" and "Configuration" sections
# Run the bot
python -m Thunder
- Use multiple bot instances.
- Increase
WORKERS
inconfig.env
based on your server's capabilities.
- Start: Send
/start
to your bot. - Authenticate: Join required channels if configured by the admin.
- Token Authentication: If token system is enabled, you'll need a valid token to use the bot. When you try to use a feature requiring authorization, the bot will automatically generate a token for you with an activation link.
- Upload: Send any media file to the bot.
- Get Link: Receive a direct streaming link.
- Share: Anyone with the link can stream or download the file.
- Batch Processing: Use /link with a number to generate links for multiple files in a group chat (e.g.,
/link 5
). - Data Center Info: Use
/dc
to get the data center of a user or file. - Ping Bot: Use
/ping
to check if the bot is online and measure response time. - Admin Commands: If you are the bot owner, use admin commands like
/status
,/broadcast
,/stats
, etc., to manage the bot and users.
Command | Description |
---|---|
/start |
Start the bot and get a welcome message. Also used for token activation. |
/link |
Generate a direct link for a file in a group. Supports batch files by replying to the first file in a group (e.g., /link 5 ). |
/dc |
Get the data center (DC) of a user or file. Use /dc id , or reply to a file or user. Works in both groups and private chats. |
/ping |
Check if the bot is online and measure response time. |
/about |
Get information about the bot. |
/help |
Show help and usage instructions. |
Command | Description |
---|---|
/status |
Check bot status, uptime, and resource usage. |
/broadcast |
Send a message to all users (supports text, media, buttons). |
/stats |
View usage statistics and analytics. |
/ban |
Ban a user (reply to message or use user ID). |
/unban |
Unban a user. |
/log |
Send bot logs. |
/restart |
Restart the bot. |
/shell |
Execute a shell command (Use with extreme caution!). |
/users |
Show total number of users. |
/authorize |
Permanently authorize a user to use the bot (bypasses token system). |
/deauthorize |
Remove permanent authorization from a user. |
/listauth |
List all permanently authorized users. |
If
SET_COMMANDS
is set toTrue
in your configuration, the bot will automatically configure these commands.
Paste the following into the BotFather "Edit Commands" section for your bot.
start - Start the bot and get a welcome message
link - (Group) Generate a direct link for a file or batch
dc - Retrieve the data center (DC) information of a user or file
ping - Check the bot's status and response time
about - Get information about the bot
help - Show help and usage instructions
status - (Admin) View bot details and current workload
stats - (Admin) View usage statistics and resource consumption
broadcast - (Admin) Send a message to all users
ban - (Admin) Ban a user
unban - (Admin) Unban a user
log - (Admin) Send bot logs
restart - (Admin) Restart the bot
shell - (Admin) Execute a shell command
users - (Admin) Show the total number of users
authorize - (Admin) Grant permanent access to a user
deauthorize - (Admin) Remove permanent access from a user
listauth - (Admin) List all authorized users
Thunder Bot includes an optional token-based access control system that allows admins to control who can use the bot.
- Enable the token system by setting
TOKEN_ENABLED=True
in your config. - Users without a valid token will receive an "Access Denied" message when trying to use the bot
- Admins can authorize users permanently, or users receive automatically generated tokens When a user sends a media to the bot, the bot will automatically shorten the link.
Thunder Bot supports URL shortening for both media links and token activation links.
- Provide a valid URL shortener API key and site in
URL_SHORTENER_API_KEY
andURL_SHORTENER_SITE
. - Enable URL shortening in token activation links by setting
SHORTEN_ENABLED=True
in your config. - Enable URL shortening in media links links by setting
SHORTEN_MEDIA_LINKS=True
in your config.
Reverse Proxy with Cloudflare SSL
This guide will help you set up a secure reverse proxy using NGINX for your file streaming bot with Cloudflare SSL protection.
- A VPS or server running Ubuntu/Debian with NGINX installed
- Your file streaming bot running on a local port (e.g.,
5063
) - A subdomain (e.g.,
dl.yoursite.com
) set up in Cloudflare - Cloudflare Origin Certificate files:
cert.pem
(Certificate file)key.key
(Private key file)
Set up DNS:
- Go to your domain in Cloudflare Dashboard
- Navigate to DNS → Add an
A
record:- Name:
dl
(or your preferred subdomain) - Content: Your server's IP address
- Proxy Status: Proxied (orange cloud)
- Name:
Configure SSL:
- Go to SSL/TLS → Overview
- Set encryption mode to Full (strict)
- Create your Origin Certificate if you haven't already
Create a folder for your SSL certificates:
sudo mkdir -p /etc/ssl/cloudflare/dl.yoursite.com
If you have the certificate files already:
sudo mv cert.pem key.key /etc/ssl/cloudflare/dl.yoursite.com/
If you need to create them:
# Create certificate file
sudo nano /etc/ssl/cloudflare/dl.yoursite.com/cert.pem
# Paste your Origin Certificate here and save
# Create private key file
sudo nano /etc/ssl/cloudflare/dl.yoursite.com/key.key
# Paste your Private Key here and save
Make the files secure:
sudo chmod 600 /etc/ssl/cloudflare/dl.yoursite.com/key.key
sudo chmod 644 /etc/ssl/cloudflare/dl.yoursite.com/cert.pem
Create a new configuration file:
sudo nano /etc/nginx/sites-available/dl.yoursite.conf
Paste this configuration (replace dl.yoursite.com
and 5063
with your values):
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name dl.yoursite.com;
# SSL Configuration
ssl_certificate /etc/ssl/cloudflare/dl.yoursite.com/cert.pem;
ssl_certificate_key /etc/ssl/cloudflare/dl.yoursite.com/key.key;
# Basic security
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
# Logging
access_log /var/log/nginx/dl.yoursite.com.access.log;
error_log /var/log/nginx/dl.yoursite.com.error.log;
location / {
# Forward requests to your bot
proxy_pass http://localhost:5063;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Settings for file streaming
proxy_buffering off;
proxy_request_buffering off;
# Allow large files
client_max_body_size 0;
}
}
# Redirect HTTP to HTTPS
server {
listen 80;
listen [::]:80;
server_name dl.yoursite.com;
return 301 https://$host$request_uri;
}
Enable the configuration:
sudo ln -s /etc/nginx/sites-available/dl.yoursite.conf /etc/nginx/sites-enabled/
Check if configuration is correct:
sudo nginx -t
If no errors, restart NGINX:
sudo systemctl reload nginx
Test if your site is working:
curl -I https://dl.yoursite.com
Test a file download:
curl -I https://dl.yoursite.com/dl/<your_file_id>
Your reverse proxy is now securely streaming files behind Cloudflare, powered by NGINX!
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature
). - Commit your changes (
git commit -m 'Add some AmazingFeature'
). - Push to the branch (
git push origin feature/AmazingFeature
). - Open a Pull Request.
This repository is unlicensed and provided as-is without any warranty. No permission is granted to use, copy, modify, or distribute this software for any purpose.
- Kurigram – Telegram MTProto API Client Library
- AIOHTTP – Async HTTP client/server framework
- Motor – Async MongoDB driver
- TgCrypto – Fast cryptography library for Telegram
- All contributors who have helped improve the project.
This project is not affiliated with Telegram. Use at your own risk and responsibility. Comply with Telegram's Terms of Service and your local regulations regarding content distribution.
⭐ Like this project? Give it a star! ⭐
🐛 Found a bug or have a feature request? Open an issue