feat: support multiple Telegram bots in a single gateway instance#228
Open
yibie wants to merge 4 commits into
Open
feat: support multiple Telegram bots in a single gateway instance#228yibie wants to merge 4 commits into
yibie wants to merge 4 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
6616fcf to
4c48621
Compare
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
A single
bub gatewayinstance can now run multiple Telegram bots simultaneously, with full isolation between them.Usage
Backward compatible (single bot):
Multi-bot mode:
BUB_TELEGRAM_BOTS='[{"name":"personal","token":"111:aaa","allow_users":"123"},{"name":"community","token":"222:bbb","allow_chats":"456"}]'Changes
BotConfigpydantic model for per-bot configuration (token, allow_users, allow_chats, proxy)TelegramSettings.botsfield accepts a JSON array for multi-bot modeTelegramSettings.bot_configs()returnslist[BotConfig](unified path for single and multi-bot)TelegramChannel.nameis now dynamic:telegram-{name}or defaulttelegramprovide_channelscreates oneTelegramChannelperBotConfigIsolation
nameper botsession_idincludes channel nameallow_users/allow_chatsproxyconfigVerification