A comprehensive collection of Telegram bots demonstrating various bot functionalities including messaging, media sharing, and intelligent conversation capabilities.
- Simple Messaging: Basic text message sending
- Image Broadcasting: Automated image sharing from various sources
- Audio Broadcasting: Local audio file distribution
- Smart Replies: AI-powered conversational responses using Q&A datasets
- Message Monitoring: Real-time message reading and processing
- Motivational Messages: Automated inspirational quote broadcasting
- Python 3.11 or higher
- A Telegram Bot Token (from @BotFather)
- A Telegram Chat ID where messages will be sent
-
Clone or download this project
-
Install dependencies: The required packages are already installed in this Replit environment:
requests- For HTTP API callspandas- For data processingpython-dotenv- For environment variable management
-
Set up environment variables:
cp .env.example .env
Edit
.envfile with your actual values:TELEGRAM_BOT_TOKEN=your_bot_token_here TELEGRAM_CHAT_ID=your_chat_id_here MESSAGE_DELAY=3 UPDATE_LIMIT=10
-
Create a Bot:
- Message @BotFather on Telegram
- Send
/newbotand follow the instructions - Save the bot token provided
-
Get Chat ID:
- Add your bot to a group or start a private chat
- Send a message to the bot
- Visit:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Find the
chat.idin the response
File: bots/simple_message_bot.py
Sends a basic "Hello World" message to demonstrate fundamental messaging.
python bots/simple_message_bot.pyFile: bots/image_broadcaster.py
Automatically broadcasts images from various sources with captions in a continuous loop.
Features:
- Multiple image sources (Unsplash, Cloudinary)
- Custom captions for each image
- Configurable delay between images
- Error handling and retry logic
- Cycle counting and statistics
python bots/image_broadcaster.pyFile: bots/audio_broadcaster.py
Sends audio files from the assets/audio/ directory with captions.
Supported formats: .wav, .mp3, .ogg, .m4a
Features:
- Auto-discovers audio files from assets directory
- Generates friendly captions from filenames
- Validates file existence before sending
- Progress tracking and comprehensive error handling
python bots/audio_broadcaster.pyFile: bots/video_broadcaster.py
Sends video files from the assets/video/ directory with captions.
Supported formats: .mp4, .avi, .mkv, .mov, .webm
Features:
- Auto-discovers video files from assets directory
- Generates friendly captions from filenames
- Progress tracking and error handling
python bots/video_broadcaster.pyFile: bots/media_showcase.py
Demonstrates all media types by sending a sample from each category.
Features:
- Sends 3 images, 2 audio files, and 1 video
- Shows comprehensive media capabilities
- Perfect for testing all media types quickly
python bots/media_showcase.pyFile: bots/smart_reply_bot.py
Monitors incoming messages and provides intelligent responses using a Q&A dataset.
Features:
- Real-time message monitoring
- AI-powered responses using external dataset
- Exact and partial question matching
- Conversation logging
- Graceful fallback for unknown questions
- Reply-to-message functionality
python bots/smart_reply_bot.py.
├── assets/ # Media assets directory
│ ├── images/ # Image URLs and local image files
│ │ └── sample_images.txt # Curated image URL collection
│ ├── audio/ # Audio files (.wav, .mp3, .ogg, .m4a)
│ │ ├── ChillVibes.wav # Sample audio files
│ │ ├── HourTriumph.wav
│ │ └── FantasyHeart.wav
│ └── video/ # Video files (.mp4, .avi, .mkv, .mov, .webm)
├── bots/ # Modern bot implementations
│ ├── simple_message_bot.py # Basic messaging
│ ├── image_broadcaster.py # Image broadcasting from assets
│ ├── audio_broadcaster.py # Audio broadcasting from assets
│ ├── video_broadcaster.py # Video broadcasting from assets
│ ├── media_showcase.py # All media types demo
│ └── smart_reply_bot.py # Intelligent conversations
├── asset_manager.py # Media asset management
├── config.py # Configuration management
├── utils.py # Common utilities and base bot class
├── .env.example # Environment variables template
├── README.md # This file
├── SECURITY.md # Security guidelines
└── legacy_bots/ # Original bot implementations
├── bot-1.py # Basic update fetching
├── bot-2.py # Simple getUpdates
├── bot-3.py # Enhanced update fetching
├── bot-send-msg.py # Basic message sending
├── bot-img-send.py # Image broadcasting (legacy)
├── bot-music-send.py # Audio broadcasting (legacy)
├── bot-engage.py # Smart replies (legacy)
├── bot-read-reply.py # Message monitoring (legacy)
└── bot-auto-msg.py # Auto messaging (legacy)
All bots use the same configuration system via environment variables:
| Variable | Description | Default | Required |
|---|---|---|---|
TELEGRAM_BOT_TOKEN |
Your bot token from @BotFather | - | ✅ |
TELEGRAM_CHAT_ID |
Target chat ID for messages | - | ✅ |
MESSAGE_DELAY |
Delay between messages (seconds) | 3 | ❌ |
UPDATE_LIMIT |
Max updates to fetch at once | 10 | ❌ |
Use the TelegramBot base class from utils.py to create custom bots:
from utils import TelegramBot
class MyCustomBot(TelegramBot):
def __init__(self):
super().__init__()
def custom_functionality(self):
# Your custom bot logic here
result = self.send_message("Custom message")
return result
# Usage
bot = MyCustomBot()
bot.custom_functionality()All bots include comprehensive error handling:
- Network connectivity issues
- Invalid API responses
- Missing files (for audio bot)
- Configuration errors
- Rate limiting
Bots provide detailed console output including:
- Success/failure status with emojis
- Message counts and statistics
- Error descriptions
- Progress tracking
- Never commit your
.envfile - Contains sensitive tokens - Use environment variables - Keep credentials secure
- Validate input - All bots include input validation
- Rate limiting - Built-in delays prevent API abuse
- Error handling - Prevents token exposure in error messages
Test your configuration with the simple message bot:
python bots/simple_message_bot.pyIf successful, you'll see:
✅ Message sent successfully: Hello Code World! 🤖
-
Configuration Error:
❌ Configuration error: Invalid bot configurationSolution: Check your
.envfile and ensureTELEGRAM_BOT_TOKENandTELEGRAM_CHAT_IDare set correctly. -
Bot Token Invalid:
❌ Failed to send message: UnauthorizedSolution: Verify your bot token is correct and hasn't been revoked.
-
Chat ID Invalid:
❌ Failed to send message: Bad Request: chat not foundSolution: Ensure the chat ID is correct and the bot has been added to the chat/group.
-
Audio Files Missing:
❌ Missing audio files: ChillVibes.wav, HourTriumph.wav, FantasyHeart.wavSolution: Ensure all required audio files are in the project root directory.
- Check the console output for detailed error messages
- Verify your
.envconfiguration - Test with the simple message bot first
- Ensure your bot has proper permissions in the target chat
send_message(text, reply_to_message_id=None)- Send text messagesend_photo(photo_url, caption="")- Send image from URLsend_audio(audio_file_path, caption="")- Send local audio fileget_updates(offset=None)- Fetch new messageswait(seconds=None)- Wait with configurable delay
BotConfig.validate()- Validate configurationBotConfig.get_api_url(method)- Get API endpoint URL
- Follow the existing code structure
- Add proper error handling
- Include docstrings and comments
- Test your changes
- Update documentation
This project is provided as-is for educational and demonstration purposes.
- Telegram Bot API Documentation
- BotFather - Create New Bots
- Telegram Bot API - Getting Updates
- Python Requests Documentation
Made with ❤️ for the Telegram Bot Community