Developer docs
Webhooks
Subscribe to Charigent events and verify each delivery before processing it.
Last verified:
Available events
conversation.startedA conversation has started.
conversation.endedA conversation has ended.
message.receivedA visitor message has been received.
message.sentA Charigent message has been sent.
lead.capturedLead details have been captured.
Verify the signature
Each delivery includes the signature, timestamp, and event headers. The signature is a lowercase hexadecimal HMAC-SHA256 of the exact request body prefixed by the timestamp and a period. Read the raw body before parsing JSON, compare signatures with a timing-safe function, and reject timestamps outside your replay window.
Headers: X-Webhook-Signature, X-Webhook-Timestamp, X-Webhook-Event, X-Webhook-Delivery-Id, X-Webhook-Attempt.
import { createHmac, timingSafeEqual } from 'node:crypto';
const secret = process.env.CHARIGENT_WEBHOOK_SECRET;
const rawBody = requestBody; // Preserve the exact bytes before JSON parsing.
const timestamp = request.headers.get('X-Webhook-Timestamp');
const provided = request.headers.get('X-Webhook-Signature');
if (!secret || !timestamp || !provided) throw new Error("Missing webhook signature material");
const timestampMs = Number(timestamp);
if (!Number.isSafeInteger(timestampMs) || Math.abs(Date.now() - timestampMs) > 300000) {
throw new Error("Webhook timestamp is outside the accepted window");
}
const expected = createHmac('sha256', secret)
.update(timestamp + '.' + rawBody)
.digest('hex');
const expectedBytes = Buffer.from(expected, "hex");
const providedBytes = Buffer.from(provided, "hex");
const valid = providedBytes.length === expectedBytes.length
&& timingSafeEqual(providedBytes, expectedBytes);
if (!valid) throw new Error("Invalid webhook signature");Retries and delivery identity
- A delivery has a maximum of 10 attempts. HTTP 408, 409, 425, 429, and 5xx responses can be retried. Other HTTP responses, including redirects, are terminal.
- Retries use exponential backoff starting at 2 seconds, capped at 1 hour. Retry-After can extend the wait to a 24-hour maximum.
- If no HTTP response is received, the delivery is marked for review instead of being sent again automatically because the receiver may already have processed it.
- The delivery ID remains stable across attempts. Use it to deduplicate a webhook you have already processed.