Skip to content

HTTP Providers

HTTPProvider

Bases: ABC

Generic HTTP webhook delivery provider.

name property

name

Provider name.

send abstractmethod async

send(event, to)

Send an event via HTTP webhook.

Parameters:

Name Type Description Default
event RoomEvent

The room event to deliver.

required
to str

Target webhook URL.

required

Returns:

Type Description
ProviderResult

Result with provider-specific delivery metadata.

close async

close()

Release resources. Override in subclasses that hold connections.

MockHTTPProvider

MockHTTPProvider()

Bases: HTTPProvider

Records sent messages for verification in tests.

WebhookHTTPProvider

WebhookHTTPProvider(config, *, transport=None)

Bases: HTTPProvider

HTTP provider that POSTs JSON payloads to a webhook URL.

transport is handed to the provider's httpx.AsyncClient as it is. The config validates webhook_url once, when it is built, and the client resolves the name again at every send; a caller whose outbound policy must judge the address actually dialled (pin-on-connect, see :mod:roomkit.providers.url_safety) puts that policy here, and a test puts a MockTransport here instead of behind the network. None leaves httpx to build its default transport.

A subclass shapes what is sent by overriding :meth:build_payload (the JSON body: a Slack or Teams rendering, say) and :meth:build_headers (a signature scheme of its own), and reads its settings through :attr:config.

config property

config

The provider's configuration: the URL, the secret, the headers.

build_payload

build_payload(event, to, text)

The JSON body sent for event to to, text its extracted text.

RoomKit's envelope by default: recipient, channel, room, the text as content, and the event's metadata. Override it to send another shape.

build_headers

build_headers(body)

The request headers for body, the serialized payload.

Content-Type, the configured headers, and an X-RoomKit-Signature (HMAC-SHA256 of body) when a secret is set. Override it to sign another way.