lily_website

๐Ÿ“„ Router Discovery

โฌ…๏ธ Back ๐Ÿ  Docs Root

The Router Discovery system provides a centralized way to collect and assemble aiogram.Router instances from all installed features. This ensures that the botโ€™s main dispatcher is automatically updated when new features are added.

๐Ÿ› ๏ธ Functions

Located in: src/telegram_bot/core/routers.py

collect_feature_routers()

Scans the features listed in INSTALLED_FEATURES for aiogram routers.

build_main_router()

Assembles the root router for the entire application.

๐Ÿงฉ Integration

The main_router is typically included in the Dispatcher during the botโ€™s startup:

main_router = build_main_router()
dispatcher.include_router(main_router)

๐Ÿ“ Requirements for Features

For a featureโ€™s handlers to be automatically discovered, it must:

  1. Be listed in INSTALLED_FEATURES (in core/settings.py).
  2. Have a handlers.py (or handlers/__init__.py) file.
  3. Expose an aiogram.Router instance named router in that file.