43 - Telegram Bot Configuration
Overview
Architecture Diagram
┌──────────────────────────────────────────────────────────────────────────────┐
│ Telegram Bot Architecture │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ Telegram Cloud │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ User's │ │ Bot Father │ │
│ │ Telegram App │ │ @BotFather │ │
│ └────────┬────────┘ └────────┬────────┘ │
│ │ │ │
│ │ Messages/Commands │ Create Bot Token │
│ │ │ │
│ └────────────────┬───────────────┘ │
│ │ │
│ Bot API Gateway │
│ │ │
└────────────────────────────┼────────────────────────────────────────────────┘
│
│ Webhook / Long Polling
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ OpenAlgo Backend │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ Telegram Blueprint │ │
│ │ /telegram/* │ │
│ │ │ │
│ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │
│ │ │ /settings │ │ /webhook │ │ /test │ │ │
│ │ │ Configure │ │ Receive │ │ Send test │ │ │
│ │ │ bot token │ │ updates │ │ message │ │ │
│ │ └──────────────┘ └──────────────┘ └──────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ Telegram Service │ │
│ │ │ │
│ │ ┌──────────────────────────────────────────────────────────────┐ │ │
│ │ │ Command Handler │ │ │
│ │ │ │ │ │
│ │ │ /start - Initialize bot │ │ │
│ │ │ /help - Show commands │ │ │
│ │ │ /funds - Account balance │ │ │
│ │ │ /positions- Open positions │ │ │
│ │ │ /orders - Order book │ │ │
│ │ │ /holdings - Portfolio holdings │ │ │
│ │ │ /trades - Trade book │ │ │
│ │ │ /pnl - P&L summary │ │ │
│ │ │ /quote - Get LTP │ │ │
│ │ │ /status - Connection status │ │ │
│ │ │ /alerts - Toggle alerts │ │ │
│ │ │ /settings - Preferences │ │ │
│ │ │ /logout - Disconnect │ │ │
│ │ └──────────────────────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ Database Layer │ │
│ │ │ │
│ │ telegram_users │ bot_config │ command_log │ notification_queue │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘Database Schema
telegram_users Table
bot_config Table
notification_queue Table
user_preferences Table
Bot Commands
Command Reference
Command
Description
Example
Configuration Flow
Service Implementation
Bot Token Security
Command Handler
Notification Service
API Endpoints
Save Configuration
Test Connection
Webhook Endpoint
Notification Types
Order Notifications
Position Alerts
P&L Summary
Error Handling
Rate Limiting
Retry Logic
Key Files Reference
File
Purpose
Last updated