routa.webhooks manages webhook endpoints and verifies the deliveries you receive. For the concepts, see Webhooks overview.
Create an endpoint
Register an HTTPS URL and store the signing secret. It is returned only once, on creation (and again on rotation).Manage endpoints
Verify a delivery with constructEvent
Routa signs each delivery in the Routa-Signature header. constructEvent verifies the signature and returns a typed event. It makes no network calls.
Pass the raw body exactly as received. Parsing and serializing it again changes the bytes, and the signature no longer matches.
constructEvent accepts the body as a string or Uint8Array and rejects signatures that are missing, malformed, invalid or with a timestamp outside the 5-minute tolerance, throwing RoutaSignatureVerificationError.
Secret rotation
During a rotation, pass both secrets to accept either one:Event types
From 0.3.0, the SDK knows 17 event types:
See the content of
data for each type in Event types. data is the API’s own JSON, in snake_case: a message.* event of a template send carries content.header_parameter and content.button_parameters, and a template.* event carries the examples in variables[].example.
A type introduced after your installed version is still parsed: it arrives as a generic event, with type typed as string and data as unknown, and it is safe to ignore.
Because the last member of the
RoutaEvent union has type: string, a switch (event.type) alone does not narrow the other fields. Check 'id' in event first to get the full envelope.The event envelope
Every known event has these fields, in camelCase:
A partner webhook endpoint receives the events of every project in the organization. Use
projectId and externalRef to tell which customer each event belongs to. To verify the signature of those deliveries, use partner.webhook.constructEvent(), which does the same as routa.webhooks.constructEvent().
Handle every type
With 17 types, it pays to handle the groups by prefix and ignore what you do not use:If your code uses an exhaustive
switch with a never check over EventType, it stops compiling on 0.3.0 until it handles the four new types. See Upgrade to 0.3.0.Deliveries and replay
routa.webhooks.deliveries queries the deliveries of an endpoint and replays the exhausted ones. See Retries and replay.
Missed events
If your endpoint was down,routa.events.list() returns what you did not receive. See Reconcile events.