Signed events
Verify the raw request body before trusting an event.
Send inbound messages, delivery changes and connection events back to your application through a signed, replay-safe webhook.
For developers designing the boundary between WhatsApp and an application backend.Verify the raw request body before trusting an event.
Deduplicate by workspace and event identifier.
Queue durable work and respond before downstream processing.
ChatRail posts inbound messages, delivery-state changes and connection events to the HTTPS endpoint configured for the workspace. Each event carries an identifier, timestamp, type and relevant resource data. Treat the payload as untrusted until its signature and timestamp are verified.
Use a dedicated HTTPS route for ChatRail rather than mixing it with browser actions or unrelated provider callbacks. Enforce a small request limit, a supported content type and a narrow method allow-list.
const digest = createHmac("sha256", process.env.WEBHOOK_SECRET)
.update(rawBody)
.digest("hex");
if (!safeEqual(receivedSignature, digest)) {
return response.status(401).end();
}Verify against the raw body—not a parsed and re-serialized object. Compare fixed-length values in constant time and reject stale timestamps to reduce replay exposure.
Authenticate the event, persist or durably enqueue it, then return success. Database joins, model calls and third-party requests should run outside the request path. This keeps latency predictable and reduces unnecessary webhook retries.
Assume the same event may arrive more than once. Insert the event ID behind a unique workspace-scoped constraint before producing side effects. Return success for an already processed event instead of repeating a customer action.
Inbound replies, message-state transitions and connection health serve different purposes. Route them to explicit handlers, tolerate unknown future event types and apply monotonic rules so a late delivered event cannot overwrite a later read state.
Record latency, event type, attempt count and a redacted error category. Avoid logging message content, authorization headers, QR material or full phone numbers.
Return a successful 2xx response after verification and durable acceptance.
Yes, when it can preserve the raw body or otherwise perform the required signature verification safely.
Acknowledge the webhook quickly, then send through the messaging API from a worker. Do not make delivery depend on a long synchronous response.
Retries protect against network and server failures. Idempotent processing turns that delivery model into predictable application behavior.
Prefer event IDs, types and redacted diagnostics. Message bodies and phone numbers may contain sensitive data.
Prove the operational loop before increasing traffic or automation.
Start free