Observer is used for filtering and handling different events. That is part of internal API with some public methods and is recommended to don’t use methods is not listed here.
In aiogram framework is available two variants of observer:
- class aiogram.dispatcher.event.event.EventObserver[source]#
Simple events observer
Is used for managing events is not related with Telegram (For example startup/shutdown processes)
Handlers can be registered via decorator or method
@<observer>() async def my_handler(*args, **kwargs): ...
- async trigger(*args: Any, **kwargs: Any) None [source]#
Propagate event to handlers. Handler will be called when all its filters is pass.
- class aiogram.dispatcher.event.telegram.TelegramEventObserver(router: Router, event_name: str)[source]#
Event observer for Telegram events
Here you can register handler with filter. This observer will stop event propagation when first handler is pass.
- register(callback: Callable[[...], Any], *filters: Callable[[...], Any], flags: Optional[Dict[str, Any]] = None, **kwargs: Any) Callable[[...], Any] [source]#
Register event handler
- async trigger(event: TelegramObject, **kwargs: Any) Any [source]#
Propagate event to handlers and stops propagation on first match. Handler will be called when all its filters is pass.