Telegram Bot Setup Guide
NeuraTrade’s Telegram bot provides real-time notifications, trading status updates, and interactive command-based control of your autonomous trading system.Overview
The Telegram service integrates with NeuraTrade’s backend API to deliver:- Real-time notifications for trading events, risk alerts, and system status
- Interactive commands to control trading modes, check balances, and monitor positions
- Autonomous mode controls to start/pause trading and view AI reasoning
- Quest progress tracking for gamified trading achievements
- Wallet management for balance checks and position monitoring
Prerequisites
- Active Telegram account
- Running NeuraTrade backend (see Native Deployment)
- Access to create Telegram bots via @BotFather
Step 1: Create Telegram Bot
Create your bot using Telegram’s official BotFather.Open BotFather
Open Telegram and search for @BotFather or click the link to start a chat.
Set bot username
Choose a unique username (must end in ‘bot’):
The username must be unique across all Telegram bots. If taken, try adding numbers or your name.
Step 2: Configure Bot Settings
Optimize your bot’s appearance and behavior.Set Bot Description
Set Bot About Text
Set Bot Profile Picture
Configure Commands Menu
The Telegram service automatically registers commands with Telegram when it starts. You can also set them manually:Step 3: Configure NeuraTrade
Add your bot token to NeuraTrade’s configuration.Environment Variable Method
Export the token as an environment variable:Config File Method
Edit~/.neuratrade/config.json:
The config file supports both root-level
telegram and nested services.telegram for backwards compatibility.Step 4: Choose Deployment Mode
NeuraTrade supports two Telegram bot deployment modes.Polling Mode (Recommended for Development)
Polling mode is simpler and works behind firewalls/NAT. Configuration:config.json:
- No public IP or domain required
- Works behind NAT/firewalls
- Easier local development
- Simpler setup
- Higher latency (1-2 second polling interval)
- More resource usage (constant polling)
- Not recommended for production at scale
services/telegram-service/index.ts:194
Webhook Mode (Recommended for Production)
Webhook mode is more efficient and has lower latency. Requirements:- Public domain with HTTPS
- Valid SSL certificate
- Reverse proxy (nginx/Caddy)
config.json:
- Lower latency (instant updates)
- More efficient (no polling)
- Better for production scale
- Lower resource usage
- Requires public domain + HTTPS
- More complex setup
- Certificate management
services/telegram-service/index.ts:121
nginx Configuration Example
For webhook mode with nginx reverse proxy:Step 5: Start Telegram Service
Start the service and verify bot connectivity.Via Gateway CLI
Standalone Mode (Development)
For development, you can run the Telegram service directly:Verify Service Health
Step 6: Bind Your Chat ID
Link your Telegram account to NeuraTrade for personalized notifications.Get your chat ID
Start a conversation with your bot:
- Search for your bot username in Telegram
- Click “Start” or send
/start - Your chat ID will be in the welcome message
- Send any message to @userinfobot
- It replies with your user ID (this is your chat ID)
Generate binding code
Generate a one-time authentication code:Or via API:Response:The code is printed in the backend logs or returned in the response.
Binding codes expire after 15 minutes for security. Generate a new code if expired.
Step 7: Test Bot Commands
Verify your bot responds to commands.Basic Commands
- /start
- /help
- /status
Initializes the bot and shows welcome message:Bot Response:
Trading Commands
- /wallet
- /begin
- /pause
View account balance:Response:
Monitoring Commands
Troubleshooting
Bot Not Responding
Invalid bot token
Invalid bot token
Test your token:If invalid:Generate a new token from @BotFather:
Service not running
Service not running
Check service status:Look for:Check logs:
Polling vs Webhook conflict
Polling vs Webhook conflict
If webhook is set but you’re using polling mode:
Commands Return Errors
Chat ID not bound
Chat ID not bound
Bind your chat ID:
Backend API unreachable
Backend API unreachable
Verify backend is running:Check
TELEGRAM_API_BASE_URL:Permission errors
Permission errors
Check Telegram service needs this to call internal backend endpoints.
ADMIN_API_KEY is set:Webhook Issues
Webhook not receiving updates
Webhook not receiving updates
Check webhook status:Look for:If
pending_update_count is growing, Telegram can’t reach your webhook.SSL certificate errors
SSL certificate errors
Verify your SSL certificate:Telegram requires:
- Valid SSL certificate (Let’s Encrypt works)
- Certificate chain must be complete
- No self-signed certificates
Webhook secret mismatch
Webhook secret mismatch
The service checks Update webhook with correct secret:
X-Telegram-Bot-Api-Secret-Token header.If failing, check your secret:Configuration Reference
Complete Telegram configuration options:~/.neuratrade/config.json
Environment Variables
| Variable | Default | Description |
|---|---|---|
TELEGRAM_BOT_TOKEN | - | Required. Bot token from @BotFather |
TELEGRAM_USE_POLLING | true | Use polling mode (vs webhook) |
TELEGRAM_PORT | 3002 | Service HTTP port |
TELEGRAM_WEBHOOK_URL | - | Public webhook URL (webhook mode only) |
TELEGRAM_WEBHOOK_PATH | /telegram/webhook | Webhook endpoint path |
TELEGRAM_WEBHOOK_SECRET | - | Secret token for webhook validation |
TELEGRAM_API_BASE_URL | http://localhost:8080 | Backend API URL |
ADMIN_API_KEY | - | Admin API key for internal endpoints |
BIND_HOST | 0.0.0.0 | Service bind address |
Source Code Reference
Key implementation files:services/telegram-service/index.ts:1- Main service entry pointservices/telegram-service/config.ts:140- Configuration loaderservices/telegram-service/src/commands/- Command handlersservices/telegram-service/bot-handlers.ts- Bot event handlersservices/telegram-service/index.ts:56- Health endpointservices/telegram-service/index.ts:121- Webhook handler
Next Steps
Gateway CLI
Learn gateway commands
Monitoring
Monitor system health
Autonomous Trading
Start autonomous trading
API Reference
Telegram API endpoints