Webhook API¶
- class peyk.webhook.IPFilter(networks: Sequence[str], *, trust_forwarded_for: bool = False)[source]¶
Bases:
objectAllow webhook requests only when their source IP is in configured networks.
trust_forwarded_foris deliberately opt-in. When disabled, only the transport peer address is considered, so an untrusted client cannot choose its own address throughX-Forwarded-For.
- class peyk.webhook.WebhookOptions(allowed_updates: list[str] | None = None, drop_pending_updates: bool = False, max_connections: int | None = None)[source]¶
Bases:
objectPlatform-neutral webhook registration options.
- allowed_updates: list[str] | None = None¶
- drop_pending_updates: bool = False¶
- max_connections: int | None = None¶
- class peyk.webhook.WebhookProcessor(dispatcher: object, *, secret: str | None = None, max_body_size: int = MAX_DEFAULT_BODY_SIZE, handle_in_background: bool = True, endpoint_type: str | None = None, max_concurrent_updates: int | Semaphore | None = None, update_timeout: float | None = None, max_queue_wait: float | None = None, max_pending: int | None = None)[source]¶
Bases:
objectParse and dispatch webhook requests without depending on an HTTP server.
- __init__(dispatcher: object, *, secret: str | None = None, max_body_size: int = MAX_DEFAULT_BODY_SIZE, handle_in_background: bool = True, endpoint_type: str | None = None, max_concurrent_updates: int | Semaphore | None = None, update_timeout: float | None = None, max_queue_wait: float | None = None, max_pending: int | None = None) None[source]¶
max_queue_wait(seconds, default off) drops an update that waited longer than that for a free slot: under overload a message handled minutes late is worth less than keeping up with the new ones.max_pending(default off) answers503once that many updates are already waiting or running, so the platform retries later instead of the bot piling up tasks (and memory) without limit.max_concurrent_updates(a number, or a semaphore shared by several processors) bounds the updates handled at the same time andupdate_timeout(seconds) cancels one update that hangs, so a handler stuck on a single message can neither freeze the others nor hold a slot forever. Both are off (unbounded) by default.
- async handle(bot: Bot[object], body: bytes, headers: Mapping[str, str]) WebhookResult[source]¶
Verify, parse and dispatch one webhook request.
Malformed JSON and oversized bodies are rejected. Authentication failures return the same 404 used by route failures so callers cannot distinguish a secret oracle from an absent endpoint.
- class peyk.webhook.WebhookRegistrar(*args, **kwargs)[source]¶
Bases:
ProtocolRegister and remove a webhook for one platform.
- async install(bot: Bot[object], url: str, secret: str, options: WebhookOptions) None[source]¶
Provides the install operation for the peyk integration.
- Parameters:
bot – Value used by this operation.
url – Value used by this operation.
secret – Value used by this operation.
options – Value used by this operation.
- class peyk.webhook.WebhookResult(status: int, body: bytes | None = None)[source]¶
Bases:
objectHTTP result returned by a webhook processor.
- body: bytes | None = None¶
- status: int¶
- peyk.webhook.constant_time_compare(a: str | None, b: str | None) bool[source]¶
Compare two non-empty strings without ordinary early-exit timing.
- peyk.webhook.registrar_for(bot: Bot[object]) WebhookRegistrar[source]¶
Return the audited registrar for
bot.platform.