feat: support multiple Telegram bots in a single gateway instance#227
Closed
yibie wants to merge 2 commits into
Closed
feat: support multiple Telegram bots in a single gateway instance#227yibie wants to merge 2 commits into
yibie wants to merge 2 commits into
Conversation
Replace ContextVar.reset(token) with save/restore pattern to avoid 'Token was created in a different Context' ValueError when the async generator cleanup runs in a different asyncio Task (e.g. cancellation, TaskGroup exception propagation).
- Add BotConfig pydantic model for per-bot configuration
- Add TelegramSettings.bots field (JSON array) for multi-bot mode
- TelegramSettings.bot_configs() returns list of BotConfig
- Backward compatible: BUB_TELEGRAM_TOKEN still works for single bot
- TelegramChannel name is now dynamic: telegram-{name} or 'telegram'
- provide_channels creates one TelegramChannel per BotConfig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature
一个 实例现在可以同时运行多个 Telegram bot,彼此完全隔离。
用法
向后兼容(单 bot 不变):
多 bot 模式:
BUB_TELEGRAM_BOTS='[{"name":"personal","token":"111:aaa","allow_users":"123"},{"name":"community","token":"222:bbb","allow_chats":"456"}]'改动
BotConfigpydantic 模型,封装单个 bot 的完整配置(token、allow_users、allow_chats、proxy)TelegramSettings.bots字段支持 JSON 数组输入TelegramSettings.bot_configs()统一返回list[BotConfig](兼容单 bot 和多 bot)TelegramChannel名称动态化:telegram-{name}或默认telegramprovide_channels为每个BotConfig创建一个TelegramChannel隔离保证
验证