Telegram Bot API Integration & BotCommand Dynamic Loading
Decrypting gateway/platforms/telegram.py message receive loop and MarkdownV2 escape details
๐ Figure 5-2-1: Multi-tenant gateway distribution, multi-channel adapter bus, and standard message send/receive flow
๐ 1. Polling Receive Loop & Webhook Bridge Distribution
In gateway/platforms/telegram.py, the system provides dual polling pumps: Webhook trigger and Long Polling. After receiving Telegram's JSON payload, the system uniformly deserializes it into a standard GatewayEvent containing the user's text and its unique Telegram File ID.
๐ Figure 5-2-2: Gateway concurrent dedup, Telegram message fingerprint hashing, and re-entry determination flow
โ๏ธ 2. MarkdownV2 Escaping & Command Injection
Telegram MarkdownV2 requires mandatory escaping of a very wide range of special characters (e.g., _ * [ ] ( ) ~ ` > # + - = | { } . !), otherwise it returns 400 Bad Request. The adapter has a built-in escape_markdown_v2() automatic escape function to solve this problem.