Build production-ready Telegram bots with AI agents, N8N workflows, and monetization strategies. Complete automation framework for developers transitioning from manual work to scalable systems. Includes deployment guides, business integrations, and real-world examples Of media Downloader.
- ๐ฏ Why This Bot Matters
- โจ Features
- ๐๏ธ Architecture
- ๐ Quick Start
- ๐ป Local Development
- ๐ค Bot Versions
- โ๏ธ Cloud Deployment
- ๐ง Configuration
- ๐ฑ Usage Guide
- ๐ค Bot Collection
- ๐ Integrations
- ๐ ๏ธ Troubleshooting
- ๐ค Contributing
๐ง This repository already includes the most essential files you need to get your bot up and running, and Iโll keep adding more advanced resources ๐ so you can fully understand and master the ins and outs of the entire system.
Read the complete journey: From Marketing Noob Hacks to Automation Empire
This isn't just another download bot. It's a gateway to automation mastery that bridges the gap between marketing tactics and technical implementation. Born from real-world experience in CPA marketing and evolved into a comprehensive automation solution.
What makes this different:
- ๐ง Psychology-Driven Design - Built with user behavior insights
- ๐ Business Model Ready - Supports affiliate integration and content lockers
- ๐๏ธ Quality Control - Multiple format and resolution options
- ๐ Multi-Platform - 1000+ supported sites via yt-dlp
- โก Performance Optimized - Handles high-volume downloads
- ๐ Security First - User authorization and rate limiting
- ๐ Scalable Architecture - From personal use to business deployment
- ๐บ Video Downloads - YouTube, Instagram, TikTok, Twitter, Facebook
- ๐ต Audio Extraction - MP3, M4A, WAV formats
- ๐๏ธ Quality Selection - 360p to 4K with size optimization
- โก Progress Tracking - Real-time download progress
- ๐ Format Options - Video, audio-only, video+audio separate
- ๐ Batch Processing - Multiple URLs support
- ๐พ Smart Caching - Redis-powered performance optimization
- ๐ฅ Multi-User Support - Authorized user management
- ๐ Usage Analytics - Download tracking and statistics
- ๐ฆ Rate Limiting - Configurable download limits
- ๐ก๏ธ Security - User authorization and admin controls
- ๐ Webhook Support - N8N and MCP integration ready
- ๐จ Custom Branding - Personalized bot responses
- ๐ฑ Mobile Optimized - Perfect for phone usage
- ๐ฐ Monetization Ready - Affiliate link integration
- ๐ฏ Marketing Funnel - Content locker capabilities
- ๐ Analytics Dashboard - User behavior insights
- ๐ Automation Workflows - N8N integration
- ๐ค AI Agents - MCP support for intelligent responses
graph TB
subgraph "User Interface"
A[Telegram Client]
B[Web Dashboard]
end
subgraph "Bot Layer"
C[Telegram Bot API]
D[Webhook Handler]
E[Command Processor]
end
subgraph "Processing Layer"
F[yt-dlp Engine]
G[FFmpeg Processor]
H[Format Converter]
end
subgraph "Storage Layer"
I[(Database)]
J[(Redis Cache)]
K[File Storage]
end
subgraph "Integration Layer"
L[N8N Workflows]
M[MCP Agents]
N[Analytics API]
end
A --> C
B --> D
C --> E
D --> E
E --> F
F --> G
G --> H
E --> I
E --> J
H --> K
E --> L
L --> M
E --> N
classDef userLayer fill:#e1f5fe
classDef botLayer fill:#f3e5f5
classDef processLayer fill:#e8f5e8
classDef storageLayer fill:#fff3e0
classDef integrationLayer fill:#fce4ec
class A,B userLayer
class C,D,E botLayer
class F,G,H processLayer
class I,J,K storageLayer
class L,M,N integrationLayer
sequenceDiagram
participant U as User
participant B as Bot
participant Y as yt-dlp
participant S as Storage
participant N as N8N
U->>B: Send URL
B->>B: Validate User
B->>Y: Extract Info
Y->>B: Video Metadata
B->>U: Quality Options
U->>B: Select Quality
B->>Y: Download Media
Y->>S: Save File
B->>U: Upload File
B->>N: Trigger Workflow (Optional)
B->>B: Log Analytics
# Clone the repository
git clone https://github.com/yomazini/telegram-automation-bot-framework.git
cd telegram-automation-bot-framework
# Install dependencies
pip install -r requirements.txt
# Copy configuration template
cp .env.example .env
# Edit configuration (see Configuration section)
nano .env
# Run the bot (choose one)
# With FFmpeg for MP3 conversion
python bots/simple_bot.py
# Without FFmpeg (sends original audio format)
python bots/simple_bot_without_ffmpeg.py# Clone and configure
git clone https://github.com/yomazini/telegram-automation-bot-framework.git
cd telegram-automation-bot-framework
cp .env.example .env
# Edit .env with your credentials
# Start with Docker Compose
docker-compose up -d
# Check logs
docker-compose logs -f bot- Python 3.8+ - Core runtime
- Git - Version control
- FFmpeg - (Optional, for
simple_bot.py) for converting audio to MP3.
Windows (using Chocolatey):
choco install ffmpegmacOS (using Homebrew):
brew install ffmpegLinux (Debian/Ubuntu):
sudo apt update && sudo apt install ffmpeg# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows
# Install development dependencies
pip install -r requirements.txt
# Run tests
python -m pytest tests/flowchart LR
A[Code Changes] --> B[Run Tests]
B --> C[Local Testing]
C --> D[Commit & Push]
D --> E[CI/CD Pipeline]
E --> F[Deploy to Staging]
F --> G[Production Deploy]
style A fill:#e3f2fd
style G fill:#e8f5e8
This repository contains multiple bots for different purposes:
-
pythonanywhere_bot.py(Recommended for PythonAnywhere)- Best for: A best-effort, robust bot for deploying on PythonAnywhere's free tier.
- Features: Includes all known proxy workarounds, a
/testcommand for diagnostics, and settings optimized for PythonAnywhere's restrictive environment. See the note below about potential issues.
-
simple_bot.py- Best for: Local development or servers where you have
ffmpeginstalled. - Features: Downloads videos and converts audio to MP3 format.
- Requires:
ffmpegto be installed on the system.
- Best for: Local development or servers where you have
-
simple_bot_without_ffmpeg.py- Best for: Environments where
ffmpegis not available or not needed. - Features: Downloads videos and audio. Audio is sent in its original downloaded format (e.g.,
.m4a,.webm), avoiding the need for conversion.
- Best for: Environments where
Why PythonAnywhere is Perfect:
- โ Free Forever - No credit card required
- โ 24/7 Uptime - Always-on consoles
- โ Python Optimized - Built for Python applications
- โ Easy Setup - Web-based IDE
- โ Telegram Friendly - Whitelisted API access
Deployment Steps:
# 1. Create free account at pythonanywhere.com
# 2. Open a new Bash console
# 3. Clone the repository
git clone https://github.com/yomazini/telegram-automation-bot-framework.git
cd telegram-automation-bot-framework
# 4. Set up your environment
cp .env.example .env
nano .env # Add your BOT_TOKEN and AUTHORIZED_USER
# 5. Run the PythonAnywhere bot
python bots/pythonanywhere_bot.py403 Forbidden, timeouts). This is a platform limitation, not a bug in the code. For guaranteed reliability, we recommend deploying on a different platform like Railway or Render, or upgrading to a paid PythonAnywhere account.
# 1. Push your code to GitHub
git push origin main
# 2. Connect to railway.app with GitHub
# 3. Select your repository
# 4. Add environment variables in Railway dashboard
# Automatic deployment on git push!Railway Template:
{
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "python bots/simple_bot_without_ffmpeg.py",
"restartPolicyType": "ON_FAILURE"
}
}# render.yaml
services:
- type: web
name: telegram-bot
env: python
buildCommand: pip install -r requirements.txt
startCommand: python bots/simple_bot_without_ffmpeg.py
plan: freeOracle Cloud provides a powerful free tier. You can follow standard Linux deployment steps, and choose whichever bot script you prefer.
| Platform | Cost | Uptime | Setup | Best For |
|---|---|---|---|---|
| PythonAnywhere | ๐ข Free | ๐ข 24/7 | ๐ข Easy | Personal Use |
| Railway | ๐ก $5/month | ๐ข 24/7 | ๐ข Easiest | Developers |
| Render | ๐ข Free* | ๐ก Sleeps | ๐ข Easy | Testing |
| Oracle Cloud | ๐ข Free | ๐ข 24/7 | ๐ด Complex | Power Users |
*Free tier sleeps after 15 minutes of inactivity
For More Details Check Detailed and Visual Article
# Telegram Bot Credentials (Required)
BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz # From @BotFather
# User Management (Required)
AUTHORIZED_USER=123456789,987654321 # Comma-separated user IDs
# Bot Settings
LOG_LEVEL=INFO # Logging level
DEBUG_MODE=False # Debug modeflowchart TD
A[Open Telegram] --> B[Search @BotFather]
B --> C[Send /newbot]
C --> D[Choose bot name]
D --> E[Choose username ending with 'bot']
E --> F[Get BOT_TOKEN]
F --> G[Save token securely]
style F fill:#4caf50
style G fill:#ff9800
# Method 1: @userinfobot
# Send any message to @userinfobot
# Bot replies with your numeric ID
# Method 2: Forward message to @RawDataBot
# Forward any message to @RawDataBot
# Shows detailed user information| Command | Description | Example |
|---|---|---|
/start |
Initialize bot and show welcome | /start |
/help |
Show help and available commands | /help |
- ๐ฌ YouTube - Videos, shorts, playlists, live streams
- ๐ฑ TikTok - Videos with/without watermarks
- ๐ธ Instagram - Posts, reels, stories, IGTV
- ๐ฆ Twitter - Videos, GIFs, embedded media
- ๐ฅ Facebook - Public videos and posts
- ๐ฎ Twitch - Clips and VODs
- ๐บ Vimeo - Videos and live streams
- ๐ต SoundCloud - Tracks and playlists
- ๐ผ Bandcamp - Albums and tracks
- ๐ป Mixcloud - DJ sets and radio shows
graph LR
A[User Sends URL] --> B{Bot Analysis}
B --> C[Show Quality Menu]
C --> D[๐ฅ Best 1080p]
C --> E[๐ฌ 720p HD]
C --> F[๐ฑ 480p]
C --> G[๐บ 360p]
C --> H[๐ต Audio]
style C fill:#e3f2fd
style D fill:#4caf50
style H fill:#ff9800
Expected Bot Interaction:
๐ค User: https://www.youtube.com/watch?v=dQw4w9WgXcQ
๐ค Bot:
๐น Rick Astley - Never Gonna Give You Up
๐ค Rick Astley
โฑ๏ธ Duration: 3:32
๐ Views: 1.4B
Choose quality:
[๐ฅ Best Quality] [๐ฌ 720p]
[๐ฑ 480p]
[๐ต Audio Only]
๐ค User: *clicks 720p HD*
๐ค Bot: โฌ๏ธ Downloading in 720p...
๐ Progress: โโโโโโโโ 45%
๐ค Bot: โฌ๏ธ Uploading to Telegram...
๐ค Bot: โ
Here's your video!
๐ Rick_Astley_Never_Gonna_Give_You_Up.mp4
๐พ Size: 15.3 MB
๐ฌ Quality: 720p
โฑ๏ธ Process time: 23 seconds
Inspired by: Awesome Telegram Bots
A curated list of useful Telegram bots can be found in the original repository.
This project is designed to be extensible. You can integrate it with automation tools like N8N or AI agent frameworks. For more ideas, check out the original repository's sections on N8N and MCP.
Problem: "You are not authorized to use this bot."
Solution:
- Send a message to @userinfobot to get your numeric user ID.
- Add your ID to the
AUTHORIZED_USERvariable in your.envfile. - Restart the bot.
Problem: The bot fails when trying to download audio with simple_bot.py.
Solution:
- Install FFmpeg using the instructions in the Local Development section.
- Alternatively, use
simple_bot_without_ffmpeg.py, which does not require FFmpeg.
Problem: The bot cannot download videos on PythonAnywhere, showing 403 Forbidden or other proxy errors.
Solution:
- This is a platform limitation of PythonAnywhere's free tier. The proxy blocks access to many video sites.
- Make sure you are running
bots/pythonanywhere_bot.py, which contains all possible workarounds. - Use the
/testcommand to diagnose the connection. If it fails, the platform's restrictions are likely the cause. - For better reliability, we strongly recommend deploying on Railway, Render, or upgrading to a paid PythonAnywhere account.
This project is set up for testing with pytest.
# Run all tests
python -m pytest tests/
# Run with coverage
python -m pytest tests/ --cov=bots/- Bot starts without errors
-
/startcommand works - User authorization works
- URL validation works
- Quality selection appears
- Download completes successfully
- File upload to Telegram works
- Error handling is graceful
Never commit your .env file to Git. It contains sensitive credentials. The .gitignore file is already configured to ignore it.
The bot performs basic URL validation. For production systems, consider more robust validation against a list of allowed domains.
- Bot Journey Article - The complete story behind this bot
- Telegram Bot API Documentation - Official API reference
- yt-dlp Documentation - Media download engine docs