Skip to content

feat: support multiple Telegram bots in a single gateway instance#228

Open
yibie wants to merge 4 commits into
bubbuild:mainfrom
yibie:feat/multi-telegram-bot
Open

feat: support multiple Telegram bots in a single gateway instance#228
yibie wants to merge 4 commits into
bubbuild:mainfrom
yibie:feat/multi-telegram-bot

Conversation

@yibie

@yibie yibie commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Feature

A single bub gateway instance can now run multiple Telegram bots simultaneously, with full isolation between them.

Usage

Backward compatible (single bot):

BUB_TELEGRAM_TOKEN=123:abc

Multi-bot mode:

BUB_TELEGRAM_BOTS='[{"name":"personal","token":"111:aaa","allow_users":"123"},{"name":"community","token":"222:bbb","allow_chats":"456"}]'

Changes

  • New BotConfig pydantic model for per-bot configuration (token, allow_users, allow_chats, proxy)
  • TelegramSettings.bots field accepts a JSON array for multi-bot mode
  • TelegramSettings.bot_configs() returns list[BotConfig] (unified path for single and multi-bot)
  • TelegramChannel.name is now dynamic: telegram-{name} or default telegram
  • provide_channels creates one TelegramChannel per BotConfig

Isolation

Dimension Mechanism
Channel routing Unique name per bot
Conversation history session_id includes channel name
Access control Per-bot allow_users / allow_chats
Proxy Per-bot proxy config

Verification

uv run pytest -q
187 passed

yibie added 3 commits June 7, 2026 01:20
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
@yibie yibie force-pushed the feat/multi-telegram-bot branch from 6616fcf to 4c48621 Compare June 10, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant