复制
询问AI
Telegram ──getUpdates──> ProxyManager (polling loop per bot)
│
├── Management: trackChat() / saveMessage() ──> SQLite
├── Proxy (push): POST update ──> Backend URL
│ │
│ └── webhook reply ──> Telegram API
│
├── Long Poll: enqueue ──> UpdateQueue (ring buffer)
│ │
│ Backend ──getUpdates──> /tgapi/ ──> dequeue
│
├── Routing: match rules ──> send via Target Bot ──> Telegram
│ │
│ └── save mapping ──> route_mappings (SQLite)
│
└── Reverse Route: check mappings ──> reply via Source Bot
(Source-NAT return)
Backend ──sendMessage──> /tgapi/ (API proxy) ──> Telegram API
│
└── capture response ──> saveMessage() ──> SQLite
Browser ──HTTP──> Server ──API──> Bot ──Bot API──> Telegram
│
└──queries──> SQLite (read)
ProxyManager
每个机器人运行独立的pollLoop goroutine。每个机器人支持双模式:
- 代理模式:将原始更新转发到后端 URL
- 管理模式:处理更新以进行聊天/消息追踪
UpdateQueue
内存环形缓冲区(每个机器人 1000 个更新),支持等待者通知模式。多个消费者可以同时轮询。机器人解析
API 端点通过回退链解析机器人:- 检查已注册的机器人映射
- 检查 ProxyManager 管理的机器人