peyk.dispatcher.dispatcher

Classes

Dispatcher(*[, name, storage, fsm_strategy, ...])

Root router that feeds normalized updates from one or more bots.

class peyk.dispatcher.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: Router

Root 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.

resolve_used_update_types() → list[str][source]

Return the Telegram update types this dispatcher should receive.

Telegram remembers the allowed_updates last sent for a bot token, whether it came from getUpdates, from setWebhook or 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_query and inline_query updates 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_reaction and message_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_updates spelling.

async feed_raw_update(bot: Bot[object], raw_update: object) → object[source]

Normalize one raw update, inject dispatcher context, and propagate it.

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, update_timeout: float | None = None, max_queue_wait: float | None = None, max_pending_updates: int | None = None) → None[source]

Poll all supplied bots concurrently until stopped or cancelled.

With handle_as_tasks every fetched update used to become a task at once, so a slow bot kept fetching and piled up thousands of waiting tasks (memory, GC time). max_pending_updates stops fetching while that many updates are waiting or running (the platform keeps the rest, nothing is lost) and max_queue_wait (seconds) drops an update that waited longer than that for a slot. Both are off by default.

update_timeout (seconds, default off) cancels one update whose handler hangs, so it cannot hold a concurrency slot (or, without handle_as_tasks, the whole polling loop) forever.

run_polling(*bots: Bot[object], **kwargs: object) → None[source]

Run start_polling() through asyncio.run.

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, handle_as_tasks: bool | None = None, max_concurrent_updates: int = 100, update_timeout: float | None = None, skip_updates: bool = False, max_queue_wait: float | None = None, max_pending_updates: int | None = None) → None[source]

Serve Telegram, Bale, Rubika and Splus 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 /inline path.

The polling options work here too: handle_as_tasks (alias of handle_in_background: answer HTTP at once and handle the update in a task), max_concurrent_updates (one limit shared by all bots), update_timeout (cancel an update whose handler hangs) and skip_updates (same as drop_pending_updates).

run_webhook(*bots: Bot[object], **kwargs: object) → None[source]

Run start_webhook() through asyncio.run for Windows-safe automation.

async stop_polling() → None[source]

Request graceful polling shutdown after the current batch.