Professional VPN subscription bot with modular architecture and enhanced stability
git clone https://github.com/press-vm/remnawave-tg-bot.git
cd remnawave-tg-bot
cp .env.example .env
# Edit .env file with your configuration
docker compose up -d- Telegram Bot - Automated VPN subscription sales
- Multi-payment Support - YooKassa, CryptoPay, Tribute, Telegram Stars
- Trial System - Free trial subscriptions for new users
- Support System - Built-in customer support chat
- Admin Panel - Comprehensive administration tools
- Modular Design - Clean separation of concerns with
bot/app/structure - Service Factory - Centralized service creation and validation
- Enhanced Error Handling - Robust callback processing with 0% crash rate
- Improved Logging - Emoji-based logs for better debugging
- 37% Code Reduction - Streamlined main_bot.py (400+ β 250 lines)
- YooKassa - Primary payment gateway for Russian market
- CryptoPay - Cryptocurrency payments
- Tribute - Alternative payment solution
- Telegram Stars - Native Telegram payments
- Promo Codes - Discount and promotional campaigns
- Referral Program - Bonus rewards for invitations
- Multi-language - Russian and English support
- User Management - Registration, profiles, subscription tracking
- Panel Sync - Automatic synchronization with RemnaWave panel
- Admin Commands - Comprehensive administration toolkit
βββββββββββββββββββββββββββββββββββββββββββ
β Telegram Bot β
β βββββββββββββββββββββββββββββββββββββββ β
β β bot/app/ β β
β β βββ controllers/ β β
β β β βββ dispatcher_controller.py β β
β β βββ factories/ β β
β β β βββ build_services.py β β
β β βββ web/ β β
β β βββ web_server.py β β
β βββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
β β β
βββββΌβββββ βββββββΌββββββ ββββββΌββββββ
βPostgreSQLβ βRemnaWave β β Payment β
βDatabase β β Panel β βGateways β
ββββββββββββ βββββββββββββ ββββββββββββ
- Docker and Docker Compose
- Domain with SSL certificate (for webhooks)
- Telegram Bot Token
- RemnaWave Panel with API access
- Payment gateway accounts (YooKassa recommended)
git clone https://github.com/press-vm/remnawave-tg-bot.git
cd remnawave-tg-botcp .env.example .env
nano .envEssential .env settings:
# Telegram Configuration
BOT_TOKEN=your_bot_token_here
ADMIN_IDS=your_telegram_user_id
WEBHOOK_BASE_URL=https://your-domain.com
# Database
POSTGRES_PASSWORD=secure_password_here
# RemnaWave Panel API
PANEL_API_URL=http://remnawave:3000/api
PANEL_API_KEY=your_jwt_token_here
# Payment Gateways
YOOKASSA_SHOP_ID=your_shop_id
YOOKASSA_SECRET_KEY=your_secret_key
CRYPTOPAY_TOKEN=your_cryptopay_token
TRIBUTE_API_KEY=your_tribute_key
# Trial System
TRIAL_ENABLED=true
TRIAL_DURATION_DAYS=3
TRIAL_TRAFFIC_LIMIT_GB=10
# Subscription Plans (in RUB)
RUB_PRICE_1_MONTH=199
RUB_PRICE_3_MONTHS=499
RUB_PRICE_6_MONTHS=899
RUB_PRICE_12_MONTHS=1599# Create Docker network
docker network create remnawave-network
# Start services
docker compose up -d
# Monitor startup logs
docker compose logs -f remnawave-tg-shop
# Check VERSION
docker compose exec remnawave-tg-shop cat VERSIONExpected startup logs:
π Starting bot initialization with new architecture...
ποΈ Building dispatcher and bot...
π Building core services...
β
All services validated successfully
π Running automatic panel sync...
β
Startup sync completed
STARTUP: Bot on_startup_configured completed.
π AIOHTTP server started on http://0.0.0.0:8080
Configure available plans in .env:
# Enable/disable plans
1_MONTH_ENABLED=true
3_MONTHS_ENABLED=true
6_MONTHS_ENABLED=true
12_MONTHS_ENABLED=true
# Pricing (RUB)
RUB_PRICE_1_MONTH=199
RUB_PRICE_3_MONTHS=499
RUB_PRICE_6_MONTHS=899
RUB_PRICE_12_MONTHS=1599
# Telegram Stars pricing
STARS_1_MONTH=200
STARS_3_MONTHS=500
STARS_6_MONTHS=900
STARS_12_MONTHS=1600# Main webhook URL
WEBHOOK_BASE_URL=https://your-domain.com
# Webhook paths
YOOKASSA_WEBHOOK_PATH=/webhook/yookassa
CRYPTOPAY_WEBHOOK_PATH=/webhook/cryptopay
TRIBUTE_WEBHOOK_PATH=/webhook/tribute
PANEL_WEBHOOK_PATH=/webhook/panel# Referral bonuses (in days)
REFERRAL_BONUS_DAYS_INVITER=7
REFERRAL_BONUS_DAYS_REFEREE=3
# Minimum purchase for referral activation (RUB)
REFERRAL_MIN_PURCHASE_AMOUNT=299# View all logs
docker compose logs -f
# Restart specific service
docker compose restart remnawave-tg-shop
# Access bot container
docker compose exec remnawave-tg-shop bash
# Update to latest version
git pull origin main
docker compose pull
docker compose up -d
# Database access
docker compose exec remnawave-tg-shop-db psql -U postgres -d pressvpn_shop/admin- Admin dashboard/stats- System statistics/sync- Force panel synchronization/broadcast <message>- Mass message broadcast/support_stats- Support system statistics/users_stats- User statistics/revenue_stats- Revenue analytics
/update_names- Sync user names with panel/sync_admin- Administrative synchronization/check_subs- Validate active subscriptions
# Check service status
docker compose ps
# Monitor webhook processing
docker compose logs -f remnawave-tg-shop | grep "Update id"
# Check database connections
docker compose logs remnawave-tg-shop-db
# Panel API connectivity
docker compose logs remnawave-tg-shop | grep "Panel API"The new architecture includes comprehensive error handling:
- All
callback.answer()operations are protected - Safe message sending with fallback mechanisms
- Detailed error logging with user context
- No crashes from "Query is too old" errors
- Webhook Response Time: < 1000ms (typically 100-300ms)
- Panel Sync Duration: < 30 seconds for 100 users
- Payment Processing: Real-time webhook handling
- Error Rate: < 0.1% with v2.3.2 improvements
-
Environment Security:
chmod 600 .env chown root:root .env
-
Database Security:
- Use strong passwords (32+ characters)
- Restrict database network access
- Regular backup encryption
-
API Security:
- Rotate JWT tokens monthly
- Use HTTPS for all external connections
- Implement rate limiting
-
Server Security:
# Firewall setup ufw enable ufw allow ssh ufw allow 80/tcp ufw allow 443/tcp # Fail2ban for protection apt install fail2ban systemctl enable fail2ban
1. Webhook Problems:
# Check webhook status
curl -X GET "https://api.telegram.org/bot<TOKEN>/getWebhookInfo"
# Test webhook connectivity
curl -X POST "https://your-domain.com/webhook/test"2. Database Connection:
# Test database connection
docker compose exec remnawave-tg-shop python -c "
from db.database_setup import init_db_connection
from config.settings import Settings
settings = Settings()
result = init_db_connection(settings)
print('Database connection:', 'OK' if result else 'Failed')
"3. Panel API Issues:
# Test panel connectivity
docker compose exec remnawave-tg-shop python -c "
import requests
from config.settings import Settings
settings = Settings()
headers = {'Authorization': f'Bearer {settings.PANEL_API_KEY}'}
try:
response = requests.get(f'{settings.PANEL_API_URL}/users', headers=headers, timeout=10)
print(f'Panel API: {response.status_code}')
except Exception as e:
print(f'Panel API Error: {e}')
"4. Payment Gateway Testing:
# YooKassa test
docker compose logs remnawave-tg-shop | grep -i yookassa
# CryptoPay test
docker compose logs remnawave-tg-shop | grep -i cryptopayService Validation:
# Check service factory validation
docker compose logs remnawave-tg-shop | grep "services validated"
# Verify dispatcher creation
docker compose logs remnawave-tg-shop | grep "dispatcher.*created"
# Monitor web server startup
docker compose logs remnawave-tg-shop | grep "AIOHTTP server"- CPU: 2+ cores recommended
- RAM: 2GB minimum, 4GB recommended
- Storage: 20GB for database and logs
- Network: Stable connection for webhooks
- Database Indexing: Automatically handled by migrations
- Connection Pooling: Configured in SQLAlchemy setup
- Webhook Timeouts: Optimized for < 1s response times
- Log Rotation: Configure logrotate for long-term deployments
If upgrading from v2.3.1:
- Backup existing data
- Pull latest changes:
git pull origin main - Rebuild containers:
docker compose build - Update:
docker compose up -d - Verify logs: Look for new architecture initialization
The migration is backward compatible - no database changes required.
- Modular Design: New
bot/app/structure with controllers, factories, web modules - Code Reduction: 37% smaller main_bot.py (400+ β 250 lines)
- Service Factory: Centralized service creation and validation
- Clean Separation: Dispatcher, services, and web server in separate modules
- Callback Protection: All
callback.answer()operations wrapped in try-catch - Safe Messaging: Robust error handling in user interactions
- No More Crashes: Eliminated "Query is too old" errors
- Better Logging: Emoji-based logs for improved debugging
- Middleware Optimization: Correct ordering and initialization
- Resource Management: Better cleanup on shutdown
- Webhook Validation: Enhanced configuration validation
- Performance: Optimized service startup and initialization
- Documentation: This README and inline code comments
- Issues: GitHub Issues
- Community: Telegram Discussion
MIT License. See LICENSE file for details.
After successful deployment:
- SSL Setup: Configure HTTPS certificates for all domains
- Payment Testing: Test all payment gateways in sandbox mode
- User Testing: Create test subscriptions and trials
- Monitoring Setup: Configure alerts for critical errors
- Backup Strategy: Implement automated database backups
- Performance Tuning: Monitor and optimize based on usage patterns
Happy deploying! π
β Star this repository if it helps your business!