Skip to content

Build 24/7 automation empire with production-ready Telegram bots, AI agents, and workflow integrations. Example of simple media downloading to complex business automation - complete blueprint with deployment guides, monetization strategies, and advanced integrations (N8N, MCP, analytics). Transform from manual worker to automation architect.

Notifications You must be signed in to change notification settings

yomazini/telegram-automation-bot-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Automation Empire: 24/7 Bot Factory - Automation Toolkit for Developers

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.

Python Telegram Bot API Docker License: MIT Deploy


๐Ÿ“‹ Table of Contents


๐Ÿšง 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.


๐ŸŽฏ Why This Bot Matters

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

โœจ Features

Core Functionality Of This Bot Example;

  • ๐Ÿ“บ 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

Advanced Features

  • ๐Ÿ‘ฅ 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

Business Features

  • ๐Ÿ’ฐ 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

๐Ÿ—๏ธ Architecture

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
Loading

Bot Workflow

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
Loading

๐Ÿš€ Quick Start

Manual Setup

# 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

Docker (Production Ready)

# 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

๐Ÿ’ป Local Development

Prerequisites

  • Python 3.8+ - Core runtime
  • Git - Version control
  • FFmpeg - (Optional, for simple_bot.py) for converting audio to MP3.

Installing FFmpeg

Windows (using Chocolatey):

choco install ffmpeg

macOS (using Homebrew):

brew install ffmpeg

Linux (Debian/Ubuntu):

sudo apt update && sudo apt install ffmpeg

Development Setup

# 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/

Development Workflow

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
Loading

๐Ÿค– Bot Versions

This repository contains multiple bots for different purposes:

  1. 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 /test command for diagnostics, and settings optimized for PythonAnywhere's restrictive environment. See the note below about potential issues.
  2. simple_bot.py

    • Best for: Local development or servers where you have ffmpeg installed.
    • Features: Downloads videos and converts audio to MP3 format.
    • Requires: ffmpeg to be installed on the system.
  3. simple_bot_without_ffmpeg.py

    • Best for: Environments where ffmpeg is 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.

โ˜๏ธ Cloud Deployment

๐Ÿฅ‡ PythonAnywhere (Recommended - Free Forever)

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.py

โš ๏ธ Important Note on PythonAnywhere: Free accounts on PythonAnywhere have very strict network restrictions. While this bot includes all known workarounds, you may still experience errors (403 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.

๐Ÿš‚ Railway (Easiest Git-Based Deployment)

# 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 (Free with Sleep Mode)

# 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: free

โ˜๏ธ Oracle Cloud (Most Powerful - Free Forever)

Oracle Cloud provides a powerful free tier. You can follow standard Linux deployment steps, and choose whichever bot script you prefer.

๐Ÿ“Š Deployment Comparison

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


๐Ÿ”ง Configuration

Basic Configuration (.env)

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 mode

Getting Your Credentials

1. Bot Token (from @BotFather)

flowchart 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
Loading

2. User IDs (from @userinfobot)

# 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

๐Ÿ“ฑ Usage Guide

Bot Commands

Command Description Example
/start Initialize bot and show welcome /start
/help Show help and available commands /help

Supported Platforms

Video Platforms

  • ๐ŸŽฌ 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

Audio Platforms

  • ๐ŸŽต SoundCloud - Tracks and playlists
  • ๐ŸŽผ Bandcamp - Albums and tracks
  • ๐Ÿ“ป Mixcloud - DJ sets and radio shows

And 1000+ more via yt-dlp!

Quality Options

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
Loading

User Interface Flow

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

๐Ÿค– Bot Collection

Inspired by: Awesome Telegram Bots

A curated list of useful Telegram bots can be found in the original repository.


๐Ÿ”— Integrations

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.


๐Ÿ› ๏ธ Troubleshooting

Common Issues and Solutions

๐Ÿšซ Authorization Errors

Problem: "You are not authorized to use this bot."

Solution:

  1. Send a message to @userinfobot to get your numeric user ID.
  2. Add your ID to the AUTHORIZED_USER variable in your .env file.
  3. Restart the bot.

๐ŸŽต FFmpeg Not Found

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.

๐ŸŒ Network/Hosting Issues on PythonAnywhere

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 /test command 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.

๐Ÿงช Testing

Unit Tests

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/

Manual Testing Checklist

  • Bot starts without errors
  • /start command works
  • User authorization works
  • URL validation works
  • Quality selection appears
  • Download completes successfully
  • File upload to Telegram works
  • Error handling is graceful

๐Ÿ” Security Best Practices

Environment Variables

Never commit your .env file to Git. It contains sensitive credentials. The .gitignore file is already configured to ignore it.

Input Validation

The bot performs basic URL validation. For production systems, consider more robust validation against a list of allowed domains.


๐Ÿ“š Resources and Learning

Essential Reading


โญ Star this repo if it helped you!

GitHub stars Twitter Follow

Share the knowledge โ€ข Build together โ€ข Automate everything

About

Build 24/7 automation empire with production-ready Telegram bots, AI agents, and workflow integrations. Example of simple media downloading to complex business automation - complete blueprint with deployment guides, monetization strategies, and advanced integrations (N8N, MCP, analytics). Transform from manual worker to automation architect.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published