peyk.dispatcher.router

Classes

Observer(router, name)

Handler collection for one event type, with filters and middleware.

Router(*[, name])

Aiogram-style first-match router with nested ordered subrouters.

class peyk.dispatcher.router.Observer(router: Router, name: str)[source]

Bases: object

Handler collection for one event type, with filters and middleware.

register(handler: Callable[[P], R], *filters: object) Callable[[P], R][source]

Performs the register operation for the dispatcher client.

Parameters:

handler – Value used by this operation.

Returns:

Result produced by the dispatcher operation.

filter(*filters: object) Observer[source]

Performs the filter operation for the dispatcher client.

Returns:

Result produced by the dispatcher operation.

middleware(middleware: BaseMiddleware) BaseMiddleware[source]

Performs the middleware operation for the dispatcher client.

Parameters:

middleware – Value used by this operation.

Returns:

Result produced by the dispatcher operation.

outer_middleware(middleware: BaseMiddleware) BaseMiddleware[source]

Performs the outer middleware operation for the dispatcher client.

Parameters:

middleware – Value used by this operation.

Returns:

Result produced by the dispatcher operation.

class peyk.dispatcher.router.Router(*, name: str | None = None)[source]

Bases: object

Aiogram-style first-match router with nested ordered subrouters.

command(*names: str, prefix: str = '/') Callable[[Callable[[P], R]], Callable[[P], R]][source]

Register a message handler for one or more bot commands.

This is shorthand for router.message(Command(name, prefix=prefix)) and is available on Router, Dispatcher and (through Bot.command()) on the bot’s own router. Each alias is registered independently, so all of them share the same Python callable:

@router.command("start", "help")
async def start(message): ...
include_router(router: Router) Router[source]

Performs the include router operation for the dispatcher client.

Parameters:

router – Value used by this operation.

Returns:

Result produced by the dispatcher operation.

middleware(middleware: BaseMiddleware) BaseMiddleware[source]

Register outer whole-subtree middleware, preserving the D3 API.

handler_middleware(middleware: BaseMiddleware) BaseMiddleware[source]

Register middleware that runs after handler flags have been injected.

has_handlers() bool[source]

Performs the has handlers operation for the dispatcher client.

Returns:

Result produced by the dispatcher operation.

async propagate_platform_event(update: object, *, platform: str, **data: object) object[source]

Dispatch a native platform update and its named Telegram field observer.

platform_event receives the complete native update object. For Telegram, a named observer receives the native model stored in the corresponding Update field; other platforms currently have no named-native observer surface.

async propagate_event(event: object, **data: object) object[source]

Dispatch one event using first-match-wins semantics.