Skip to main content
This receiver verifies each request’s signature, skips duplicate event IDs, answers before Checkfu’s 10-second timeout, and finishes its bounded processing before acknowledging the event.

The receiver

receiver.ts
server.ts
The example logs the latest recorded idle event. A delayed notification can arrive after the Session has moved to another turn. For completion work, track the relevant turn in the Session history and use the Session ID and turn to deduplicate it. Use the private registration example, then load its receipt before starting the receiver. Use an API key for the deployment saved in that receipt.

How the signature works

Checkfu computes HMAC-SHA256 over <webhook-id>.<webhook-timestamp>.<raw body>, keyed with the base64-decoded bytes after whsec_. Always verify the exact raw bytes you received; parsing and re-serializing JSON changes them. For a wildcard subscription, use the receiver above or call the SDK’s verifyWebhookSignature on the raw body before parsing it. Acknowledge a verified, well-formed event you do not handle with 204. Return the normal error response when verification, parsing, or processing fails. For a subscription to specific event types, you can use the SDK’s unwrapWebhookEvent. It verifies the signature and timestamp, then decodes the payload against the event types known to that SDK version. A valid signature can accompany a type the decoder does not recognize.

Rules for a reliable receiver

  • Answer within 10 seconds. This example accepts at most 64 KiB on POST /checkfu and allows two seconds to read the request. It returns 413 for a larger body and 408 when the read deadline expires. Concurrent deliveries share one processing result. A success, completed duplicate, or ignored event returns 204. A processing failure or timeout returns 503 so delivery can retry.
  • Never redirect. A 3xx disables the Webhook immediately.
  • Expect each event more than once. Retries and manual redeliveries reuse the same webhook-id.
  • Do not rely on order. Fetch the resource from the API to read its current state.
  • Commit long-running work before acknowledging it. Insert the verified event into a durable inbox keyed by its event ID, acknowledge once the insert commits, and retry work from the inbox. The example only makes idempotent reads. Its in-memory cache holds up to 2,048 completed IDs for 14 days and is empty after a restart.

Test it

Checkfu delivers only to public HTTPS URLs and skips outbound delivery under bun run dev. Use a deployed stage and a tunnel such as cloudflared tunnel --url http://127.0.0.1:3000. Set CHECKFU_WEBHOOK_URL to the public HTTPS tunnel URL with /checkfu appended when you register the webhook. Once the receiver is running with its signing secret, test the webhook ID from the same receipt:
If every request fails verification, you are likely verifying parsed JSON instead of the raw body, using the wrong secret, or running with a server clock more than 5 minutes off. Intermittent failures usually mean your clock is drifting near the 5-minute replay window or a delivery was delayed in transit. See Create a webhook for webhook options.