A minimal Heroku/Render-style platform for running multiple Telegram bots on a single Ubuntu VPS. Built with Docker, Python FastAPI, and a simple web dashboard.
This platform allows you to:
- Create and manage multiple bot applications
- Configure environment variables per bot
- Deploy bots via Git repository or ZIP upload
- Start, stop, and restart bot containers
- View real-time logs for each bot
- Track deployment history
- Backend: Python FastAPI with SQLAlchemy (SQLite database)
- Frontend: Server-rendered HTML with Jinja2 templates
- Container Runtime: Docker for bot isolation
- Authentication: Session-based login with bcrypt password hashing
- Bot Runtime: Each bot runs in its own Docker container (Python 3.11)
- Ubuntu VPS (tested on Ubuntu 20.04+)
- Docker and Docker Compose installed
- At least 2GB RAM recommended
- Root or sudo access
-
Clone this repository:
git clone https://github.com/mrrifat/Multi-Bot-Platform.git cd Multi-Bot-Platform -
Set up the environment (Optional but recommended):
# Generate a random secret key export SECRET_KEY=$(openssl rand -hex 32) # Or edit docker-compose.yml to set a permanent SECRET_KEY
-
Build and start the platform:
docker-compose up -d --build
-
Access the dashboard:
- Open your browser to:
http://your-vps-ip:8000 - Default credentials:
- Email:
admin@example.com - Password:
admin123
- Email:
β οΈ Change the default password immediately after first login!
- Open your browser to:
Check that the container is running:
docker psYou should see bot-platform-api running.
Check logs:
docker-compose logs -f-
Login to the dashboard
-
Click "+ Create New Bot"
-
Fill in the form:
- Bot Name: e.g.,
my-telegram-bot(lowercase, hyphens allowed) - Runtime: Python (currently only option)
- Start Command: e.g.,
python bot.py - Git Repository URL: Optional - provide your bot's Git repo URL
- Bot Name: e.g.,
-
Click "Create Bot"
- Navigate to your bot's detail page
- Scroll to "Environment Variables" section
- Add your bot's required env vars (e.g.,
BOT_TOKEN,ADMIN_ID, etc.) - Click "πΎ Save Environment Variables"
- Important: Restart the bot after updating env vars
You have two deployment options:
- Ensure your bot has a
repo_urlconfigured - Click "π Deploy from Git"
- The platform will:
- Clone or pull the latest code
- Build a Docker image
- Restart the bot container
- Click "π¦ Upload Code (ZIP)"
- Select your ZIP file containing:
bot.py(or your main bot file)requirements.txt(optional)- Any other required files
- Click "Upload & Deploy"
βΆοΈ Start: Start a stopped bot- βΉ Stop: Stop a running bot
- π Restart: Restart a running bot (useful after env var changes)
- π View Logs: See the last 200 lines of container logs
Your bot repository or ZIP should contain:
-
bot.py (or your specified start file):
# Example Telegram bot import os from telegram.ext import ApplicationBuilder BOT_TOKEN = os.getenv("BOT_TOKEN") app = ApplicationBuilder().token(BOT_TOKEN).build() # Add your handlers here app.run_polling()
-
requirements.txt (optional but recommended):
python-telegram-bot==20.7 # Add other dependencies -
Your bot should use polling mode (not webhooks in MVP)
Edit docker-compose.yml:
environment:
- SECRET_KEY=your-super-secret-random-key-hereThen restart:
docker-compose down
docker-compose up -dWhen creating a bot, you can specify custom start commands:
python main.pypython src/bot.pypython3 app.py
The SQLite database is stored at ./data/bot_platform.db. You can access it with:
sqlite3 data/bot_platform.db# Follow all logs
docker-compose logs -f
# View specific service
docker-compose logs -f bot-platform-api
# Last 100 lines
docker-compose logs --tail=100docker ps -a --filter "name=bot_"docker stop $(docker ps -q --filter "name=bot_")docker image prune -aVPS-Manager/
βββ docker-compose.yml # Main orchestration file
βββ data/ # SQLite database storage
β βββ bot_platform.db # Created automatically
βββ bots-data/ # Bot code storage (created automatically)
β βββ <bot-name>/ # Each bot has its own directory
βββ backend/
β βββ Dockerfile # Platform API container
β βββ main.py # FastAPI application
β βββ models.py # Database models
β βββ database.py # Database configuration
β βββ schemas.py # Pydantic schemas
β βββ auth.py # Authentication logic
β βββ docker_manager.py # Docker operations
β βββ requirements.txt # Python dependencies
β βββ BotDockerfile.template # Template for bot images
β βββ templates/ # Jinja2 HTML templates
β β βββ base.html
β β βββ login.html
β β βββ bots/
β β βββ list.html
β β βββ new.html
β β βββ detail.html
β β βββ upload.html
β β βββ logs.html
β βββ static/ # Static files (CSS/JS if needed)
Security measures to implement:
-
Change default password immediately after first login
-
Use a strong SECRET_KEY in production
-
Enable firewall and restrict port 8000 access:
sudo ufw allow from your-ip to any port 8000
-
Use HTTPS with a reverse proxy (Nginx/Caddy):
- Set up SSL certificates (Let's Encrypt)
- Proxy
https://yourdomain.comtohttp://localhost:8000
-
Regular backups of
./data/bot_platform.dband./bots-data/
-
Check if image was built:
docker images | grep bot_ -
Check deployment logs in the dashboard
-
Verify env vars are set correctly
-
Check bot logs for errors
# Check logs
docker-compose logs bot-platform-api
# Rebuild
docker-compose down
docker-compose up -d --build# Ensure correct ownership of bot storage directory
sudo chown -R $USER:$USER ./bots-data
sudo chmod -R 755 ./bots-dataAdd your user to the docker group:
sudo usermod -aG docker $USER
# Log out and back in- Support for Node.js runtime
- Webhook support for bots
- Resource limits (CPU/memory) per bot
- User management (multiple users)
- Email notifications for failed deployments
- Metrics and monitoring dashboard
- Automatic SSL with Caddy
- Bot scheduling (cron jobs)
- Database encryption for env vars
This is a personal project, but feel free to fork and customize for your needs!
MIT License - feel free to use and modify as needed.
For issues or questions:
- Check the logs:
docker-compose logs -f - Verify Docker is running:
docker ps - Check bot container logs via the dashboard
- Review the troubleshooting section above
Built with β€οΈ for managing Telegram bots efficiently