4.7 KiB
Telegram Deployment Bot Setup Guide
This bot allows you to deploy your MQL5 Trading Automation to Fly.io, Render, and Railway via Telegram commands.
Bot API Reference: https://core.telegram.org/bots/api
🚀 Quick Start
1. Configure the Bot Credentials
This repository supports Telegram bot integration for deployment automation. To use it:
- Create your own bot using @BotFather on Telegram
- Get your bot token from @BotFather
- Get your Telegram user ID from @userinfobot
- Add credentials to your vault.json file (see config/vault.json.example)
2. Set Environment Variables
Windows (PowerShell):
$env:TELEGRAM_BOT_TOKEN = "your_bot_token_here"
$env:TELEGRAM_ALLOWED_USER_IDS = "123456789,987654321" # Required: restrict to specific user IDs
Windows (CMD):
set TELEGRAM_BOT_TOKEN=your_bot_token_here
set TELEGRAM_ALLOWED_USER_IDS=123456789,987654321
Linux/WSL:
export TELEGRAM_BOT_TOKEN="your_bot_token_here"
export TELEGRAM_ALLOWED_USER_IDS="123456789,987654321"
Permanent (Windows):
[System.Environment]::SetEnvironmentVariable('TELEGRAM_BOT_TOKEN', 'your_bot_token_here', 'User')
[System.Environment]::SetEnvironmentVariable('TELEGRAM_ALLOWED_USER_IDS', '123456789', 'User')
3. Install Dependencies
pip install -r scripts/requirements_bot.txt
4. Run the Bot
From repository root:
cd C:\Users\USER\Documents\repos\MQL5-Google-Onedrive
python scripts/telegram_deploy_bot.py
Or from scripts directory:
cd scripts
python telegram_deploy_bot.py
📱 Bot Commands
Once the bot is running, open your bot on Telegram and send:
/start- Initialize the bot and see welcome message/help- Show all available commands/deploy_flyio- Deploy to Fly.io cloud platform/deploy_render- Deploy to Render.com/deploy_railway- Deploy to Railway.app/deploy_docker- Build Docker image locally/status- Check Fly.io app deployment status
🔒 Security
Restrict Access by User ID
-
Get your Telegram user ID:
- Send a message to @userinfobot on Telegram
- It will reply with your user ID
-
Set
TELEGRAM_ALLOWED_USER_IDSenvironment variable with your user ID(s):$env:TELEGRAM_ALLOWED_USER_IDS = "123456789"
If TELEGRAM_ALLOWED_USER_IDS is not set, the bot will deny all users for security.
🐳 Running as a Service
Windows (Task Scheduler)
-
Create a PowerShell script
start_bot.ps1:$env:TELEGRAM_BOT_TOKEN = "your_token" cd C:\Users\USER\Documents\repos\MQL5-Google-Onedrive python scripts/telegram_deploy_bot.py -
Open Task Scheduler → Create Basic Task
-
Set trigger (e.g., "At startup")
-
Action: Start a program →
powershell.exe -
Arguments:
-ExecutionPolicy Bypass -File "C:\path\to\start_bot.ps1"
Linux/WSL (systemd)
Create /etc/systemd/system/telegram-deploy-bot.service:
[Unit]
Description=Telegram Deployment Bot
After=network.target
[Service]
Type=simple
User=your_username
WorkingDirectory=/path/to/MQL5-Google-Onedrive
Environment="TELEGRAM_BOT_TOKEN=your_token"
Environment="TELEGRAM_ALLOWED_USER_IDS=123456789"
ExecStart=/usr/bin/python3 scripts/telegram_deploy_bot.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl enable telegram-deploy-bot
sudo systemctl start telegram-deploy-bot
sudo systemctl status telegram-deploy-bot
🚀 Deploying the Bot Itself to Fly.io
You can also deploy this bot to Fly.io so it runs in the cloud:
-
Create a separate Fly.io app for the bot:
flyctl launch --name telegram-deploy-bot -
Set secrets:
flyctl secrets set TELEGRAM_BOT_TOKEN=your_token flyctl secrets set TELEGRAM_ALLOWED_USER_IDS=123456789 -
Update fly.toml to run the bot:
[build] [env] PYTHONUNBUFFERED = "1" # No HTTP services needed for polling bot -
Deploy:
flyctl deploy
📝 Notes
- The bot uses long polling (not webhooks), so it works on any server
- Deployments run in background and may take several minutes
- Make sure
flyctlis in your PATH for Fly.io deployments - Check logs if deployments fail:
flyctl logsor bot console output
🆘 Troubleshooting
Bot doesn't respond:
- Check if bot token is correct
- Verify bot is running (check console output)
- Make sure you're messaging the correct bot
Deployment fails:
- Check if flyctl/railway CLI is installed and authenticated
- Verify repository has necessary config files (fly.toml, etc.)
- Check bot logs for detailed error messages
Permission denied:
- Verify your user ID is in
TELEGRAM_ALLOWED_USER_IDS