| ⬅️ Back | 🏠 Docs Root |
The BotContainer is the Dependency Injection (DI) hub for the Telegram Bot. It initializes and holds references to settings, Redis clients, services, and feature orchestrators.
Located in: src/telegram_bot/core/container.py
def __init__(self, settings: BotSettings, redis_client: Redis)
During initialization, the container:
RedisService, StreamManager, and the bot-specific RedisContainer.RedisStreamProcessor to listen for events (e.g., notifications from the backend).FeatureDiscoveryService to automatically find and instantiate feature orchestrators.BotSettings.redis.asyncio client.aiogram.Bot instance (set after factory initialization).ViewSender service for smart message editing and sending.ARQ to enqueue background tasks for the worker.init_arq()Asynchronously initializes the ARQ pool using Redis settings from the configuration.
set_bot(bot: Bot)Injects the Bot instance into the container and links it with the ViewSender and BotRedisDispatcher. This is typically called during the bot’s startup sequence.
shutdown()Gracefully closes resources, including the stream processor, ARQ pool, and Redis client.
Features are accessible via the features dictionary or directly as attributes:
# Accessing the bot menu orchestrator
menu = container.bot_menu
# or
menu = container.features["bot_menu"]