peyk.dispatcher¶
- class peyk.dispatcher.Dispatcher(*, name: str | None = None, storage: BaseStorage | None = None, fsm_strategy: FSMStrategy | str = FSMStrategy.USER_IN_CHAT, events_isolation: BaseEventIsolation | None = None, **workflow_data: object)[source]¶
Bases:
RouterRoot router that feeds normalized updates from one or more bots.
The dispatcher owns polling tasks but deliberately delegates event matching to
Router; Phase 3 does not alter router matching semantics.- async feed_raw_update(bot: Bot[object], raw_update: object) object[source]¶
Normalize one raw update, inject dispatcher context, and propagate it.
- resolve_used_update_types() list[str][source]¶
Return the Telegram update types this dispatcher should receive.
Telegram remembers the
allowed_updateslast sent for a bot token, whether it came fromgetUpdates, fromsetWebhookor from a completely different program that used the same token earlier. If a new run does not send the parameter, the old filter silently stays in effect, so e.g.callback_queryandinline_queryupdates never arrive even though the handlers are registered. Peyk therefore always sends an explicit list.The list contains every update type Peyk can parse, except the three opt-in types Telegram does not deliver by default (
chat_member,message_reactionandmessage_reaction_count); those are added only when a router in the tree has a handler that needs them.- Returns:
Update type names in Telegram’s
allowed_updatesspelling.
- run_polling(*bots: Bot[object], **kwargs: object) None[source]¶
Run
start_polling()throughasyncio.run.
- run_webhook(*bots: Bot[object], **kwargs: object) None[source]¶
Run
start_webhook()throughasyncio.runfor Windows-safe automation.
- async start_polling(*bots: Bot[object], polling_timeout: int = 30, allowed_updates: Sequence[str] | None = None, skip_updates: bool = False, handle_signals: bool = True, close_bots: bool = True, handle_as_tasks: bool = False, max_concurrent_updates: int = 100) None[source]¶
Poll all supplied bots concurrently until stopped or cancelled.
- async start_webhook(*bots: Bot[object], base_url: str, host: str = '0.0.0.0', port: int = 8080, path_prefix: str = '/webhook', secrets: Sequence[str] | None = None, ssl_context: object | None = None, allowed_updates: Sequence[str] | None = None, drop_pending_updates: bool = False, manage_registration: bool = True, delete_on_shutdown: bool = False, max_connections: int | None = None, handle_in_background: bool = True) None[source]¶
Serve Telegram, Bale and Rubika webhooks from one aiohttp app.
Each bot receives a non-token URL of
{path_prefix}/{platform}/{secret}. Rubika’s confirmed inline endpoint is registered at the additional/inlinepath.
- class peyk.dispatcher.Router(*, name: str | None = None)[source]¶
Bases:
objectAiogram-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 onRouter,Dispatcherand (throughBot.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): ...
- 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.
- 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.
- async propagate_event(event: object, **data: object) object[source]¶
Dispatch one event using first-match-wins semantics.
- async propagate_platform_event(update: object, *, platform: str, **data: object) object[source]¶
Dispatch a native platform update and its named Telegram field observer.
platform_eventreceives the complete native update object. For Telegram, a named observer receives the native model stored in the correspondingUpdatefield; other platforms currently have no named-native observer surface.
- class peyk.dispatcher.ErrorEvent(event: object, exception: Exception)[source]¶
Bases:
objectAn exception raised while processing a normalized event.
- event: object¶
- exception: Exception¶
- exception peyk.dispatcher.SkipHandler[source]¶
Bases:
ExceptionSignal that the current handler did not handle the event.
Modules