Karta. Webhooks. Postal
(Karta v1.0.0)
Webhook requests in Postal's format, for receivers written for Postal's webhooks. The body is a JSON object, as Postal sends it:
{"event": "MessageSent", "timestamp": 1796205600.25, "payload": {...}, "uuid": "..."}timestamp is when the event happened (seconds, with microseconds);
uuid is the delivery's id (one per event and webhook, the same on every
attempt and replay, as Postal's request id).
Signature. Three headers, as Postal sends them, with the key of the
organisation the request is for (Karta.Webhooks.PostalKey):
X-Postal-Signature-KID (the key's id in that organisation's JWK set),
X-Postal-Signature (the base64 RSA-SHA1 signature of the body) and
X-Postal-Signature-256 (RSA-SHA256). They sign the body only: no time,
no recipient, so a receiver cannot tell an old request sent again from a
new one. A request signed for one organisation does not verify with
another organisation's key (its id is not in that set). Karta's own
format (Standard Webhooks) does not have these limits. verify/3 is the
check a receiver makes.
Events (event), from Karta's types, with Postal's payloads:
message.delivered-MessageSent,message.deferred-MessageDelayed,message.bounced-MessageDeliveryFailed,message.suppressed-MessageHeld:message,status(Sent,SoftFail,HardFail,Held),details,output,sent_with_ssl,timestamp,time;message.opened-MessageLoaded:message,ip_address,user_agent;message.clicked-MessageLinkClicked:message,url,token,ip_address,user_agent;message.complained-MessageSpamComplaint:message,details,timestamp,time. Postal has no complaint event of its own: the name follows itsMessage...names and a receiver written for Postal ignores one it does not know. The address is now on the server's suppression list;domain.dns_failed-DomainDNSError:server(uuid,name,permalink,organization: the server's id, name and slug, its organisation's slug),domain,uuid(the domain's id),dns_checked_at, andspf_status,spf_error,dkim_status,dkim_error,mx_status,mx_error,return_path_status,return_path_error(OK,MissingorInvalidfrom Karta's checks, with what was found;nullfor a check without a result). Postal sends it after every hourly check while a problem lasts; Karta once, when a check turns to a problem.
message is Postal's message object: id, token, direction
(outgoing), message_id, to, from (the envelope sender),
subject, timestamp (when the message was accepted), spam_status
and tag. As in Karta's Postal API, a Postal message is one recipient:
id is the recipient's id (a UUID where Postal has a number) and
token the token that API returns for it. details and output are
what Karta's Postal API shows for the delivery (the server's reply, in
output only when the server answered). Karta does not have: the time a
delivery took (time is null), a spam check of outgoing mail
(spam_status is NotChecked), the client's full address (ip_address
is its network, as Karta keeps it), Postal's link token (token is
Karta's link id). Not sent: MessageBounced (Karta records the bounces
of its own outgoing mail itself; it does not pass a bounce message to the
application), SendLimitApproaching and
SendLimitExceeded (Karta's limits are per minute). webhook.test has
event webhook.test and the payload of Karta's test event.
Summary
Functions
The body of a request about event (a stored Karta.Webhooks.Event) for the delivery uuid.
Postal's name of an event type (webhook.test keeps its own).
The signature headers of body under the organisation's active key
(generated when there is none).
The base64 RSA-SHA1 and RSA-SHA256 signatures of body (PKCS #1 v1.5), as Postal's Signer makes them.
Karta's event types that have a Postal event.
A receiver's check of a request in Postal's format: keys is the JWK set
of the organisation the request is for (decoded) or the DNS record of
the key (v=DKIM1; ... p=...). With a JWK set, the key is the one named by
X-Postal-Signature-KID. X-Postal-Signature-256 (RSA-SHA256) is
checked when it is there, X-Postal-Signature (RSA-SHA1) otherwise, as
receivers of older Postal versions do. headers are the request's
(lower-case names).
Functions
The body of a request about event (a stored Karta.Webhooks.Event) for the delivery uuid.
Postal's name of an event type (webhook.test keeps its own).
@spec headers(Ecto.UUID.t(), iodata()) :: [{String.t(), String.t()}]
The signature headers of body under the organisation's active key
(generated when there is none).
@spec sign(Karta.Auth.DKIM.Key.t(), iodata()) :: {String.t(), String.t()}
The base64 RSA-SHA1 and RSA-SHA256 signatures of body (PKCS #1 v1.5), as Postal's Signer makes them.
@spec types() :: [String.t()]
Karta's event types that have a Postal event.
@spec verify(map() | String.t(), [{String.t(), String.t()}], iodata()) :: :ok | {:error, String.t()}
A receiver's check of a request in Postal's format: keys is the JWK set
of the organisation the request is for (decoded) or the DNS record of
the key (v=DKIM1; ... p=...). With a JWK set, the key is the one named by
X-Postal-Signature-KID. X-Postal-Signature-256 (RSA-SHA256) is
checked when it is there, X-Postal-Signature (RSA-SHA1) otherwise, as
receivers of older Postal versions do. headers are the request's
(lower-case names).