Skip to content

frnwot/telegram-bot-codespace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Here's a complete, all-in-one README.md with installation, usage, customization, and deployment instructions - ready to copy/paste into your repository:

🤖 24/7 Telegram Bot in GitHub Codespaces

GitHub Codespaces Python License

A complete template for deploying any Telegram bot with 24/7 uptime using GitHub Codespaces. Includes auto-keepalive, health monitoring, and modular handlers.

Bot Architecture Diagram

🚀 1-Click Deployment

Method A: GitHub Template

Use Template

Method B: Manual Setup

# 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

🔧 Configuration

📝 .env Setup

# REQUIRED
TELEGRAM_BOT_TOKEN="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"

# OPTIONAL
LOG_LEVEL="DEBUG"  # DEBUG/INFO/WARNING/ERROR
PORT=8080          # Health check port

🐳 Codespaces Customization

Edit .devcontainer/devcontainer.json to:

  • Change Python version
  • Add VS Code extensions
  • Modify timeout settings

🛠️ Bot Development

📂 Project Structure

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

Adding Features

1. New Command

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

2. Message Filter

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

3. Add Database

  1. Install package:
    echo "psycopg2-binary==2.9.5" >> src/requirements.txt
  2. Create src/utils/database.py:
    import psycopg2
    conn = psycopg2.connect(os.getenv("DB_URL"))

24/7 Uptime System

🔄 How Keepalive Works

  1. Internal Pinging: Every 4 minutes via keepalive.py
  2. Health Endpoint: GET /health returns bot status
  3. GitHub Actions: Scheduled checks every 6 hours

📊 Monitoring

# View real-time logs
tail -f /tmp/bot.log

# Test health endpoint
curl http://localhost:8080/health
# Expected: {"status":"healthy","service":"telegram-bot"}

🚨 Troubleshooting Guide

Symptom Solution
Bot not responding 1. Check .env token
2. 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

📜 License

MIT License - See LICENSE file

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

🌟 Stargazers

Stargazers


💡 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?

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •