Observer#

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:

EventObserver#

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>.register(my_handler)
@<observer>()
async def my_handler(*args, **kwargs): ...
register(callback: Callable[[...], Any]) None[source]#

Register callback with filters

async trigger(*args: Any, **kwargs: Any) None[source]#

Propagate event to handlers. Handler will be called when all its filters is pass.

__call__() Callable[[Callable[[...], Any]], Callable[[...], Any]][source]#

Decorator for registering event handlers

TelegramEventObserver#

class aiogram.dispatcher.event.telegram.TelegramEventObserver(router: Router, event_name: str)[source]#

Event observer for Telegram events

Here you can register handler with filters or bounded filters which can be used as keyword arguments instead of writing full references when you register new handlers. This observer will stop event propagation when first handler is pass.

bind_filter(bound_filter: Type[aiogram.filters.base.BaseFilter]) None[source]#

Register filter class in factory

Parameters

bound_filter

register(callback: Callable[[...], Any], *filters: Callable[[...], Any], flags: Optional[Dict[str, Any]] = None, _stacklevel: int = 2, **bound_filters: Any) Callable[[...], Any][source]#

Register event handler

async trigger(event: aiogram.types.base.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.

__call__(*args: Callable[[...], Any], flags: Optional[Dict[str, Any]] = None, _stacklevel: int = 2, **bound_filters: Any) Callable[[Callable[[...], Any]], Callable[[...], Any]][source]#

Decorator for registering event handlers