Here's a complete, all-in-one README.md with installation, usage, customization, and deployment instructions - ready to copy/paste into your repository:
A complete template for deploying any Telegram bot with 24/7 uptime using GitHub Codespaces. Includes auto-keepalive, health monitoring, and modular handlers.
# Clone the repository
git clone https://github.com/frnwot/telegram-bot-codespace.git
cd telegram-bot-template
# Set up environment
cp .env.sample .env
nano .env # Add your bot token
# REQUIRED
TELEGRAM_BOT_TOKEN="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
# OPTIONAL
LOG_LEVEL="DEBUG" # DEBUG/INFO/WARNING/ERROR
PORT=8080 # Health check port
Edit .devcontainer/devcontainer.json
to:
- Change Python version
- Add VS Code extensions
- Modify timeout settings
telegram-bot-template/
├── src/
│ ├── bot/ # Main bot logic
│ │ ├── handlers/ # Command/message handlers
│ │ └── main.py # Bot entry point
│ ├── services/ # 24/7 services
│ └── utils/ # Utilities
└── .devcontainer/ # Codespace config
# src/bot/handlers/commands.py
async def joke(update: Update, context):
await update.message.reply_text("Why don't scientists trust atoms? Because they make up everything!")
def register_commands(app):
app.add_handler(CommandHandler("joke", joke))
# src/bot/handlers/messages.py
async def handle_voice(update: Update, context):
await update.message.reply_text("🎤 Voice message received!")
def register_messages(app):
app.add_handler(MessageHandler(filters.VOICE, handle_voice))
- Install package:
echo "psycopg2-binary==2.9.5" >> src/requirements.txt
- Create
src/utils/database.py
:import psycopg2 conn = psycopg2.connect(os.getenv("DB_URL"))
- Internal Pinging: Every 4 minutes via
keepalive.py
- Health Endpoint:
GET /health
returns bot status - GitHub Actions: Scheduled checks every 6 hours
# View real-time logs
tail -f /tmp/bot.log
# Test health endpoint
curl http://localhost:8080/health
# Expected: {"status":"healthy","service":"telegram-bot"}
Symptom | Solution |
---|---|
Bot not responding | 1. Check .env token2. Run python -m src.bot.main for errors |
Codespace sleeping | 1. Verify keepalive.py is running 2. Reduce ping interval |
Port conflicts | Change PORT in .env and health_api.py |
MIT License - See LICENSE file
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
💡 Pro Tip: For true 24/7 hosting, consider deploying to Render or Railway after testing in Codespaces!
### Key Features of This README:
1. **Visual Badges** - Quick project status
2. **1-Click Setup** - Template and manual options
3. **Complete Configuration Guide** - From `.env` to Codespaces
4. **Modular Development** - Clear examples for extending
5. **Uptime System Docs** - How the 24/7 magic works
6. **Troubleshooting Table** - Common issues solved
7. **Mobile-Friendly** - Clean Markdown formatting
### How to Use:
1. Copy this entire content
2. Paste into a new `README.md` file in your repo
3. Replace `yourusername` with your GitHub username
4. Add your own screenshots/diagrams if available
Would you like me to add any specific:
- Deployment guides for other platforms?
- Example bots (AI, crypto, etc.)?
- Video tutorial links?