Verify FaceTime webhook signatures and handle retries
A webhook can arrive twice. If call.ended closes a support case or triggers a follow-up, both deliveries must lead to the same result. With Chert, verify that a signed delivery came from the integration, then use event_id to recognize repeats. The incoming accept-or-decline event has its own time limit. FaceTime webhook reference.
Verify the exact bytes in the request
New Chert integrations default to unsigned delivery. Enable signing and store the integration’s signing secret separately from the project API key. For a signed integration, X-Chert-Signature contains sha256= followed by the HMAC-SHA256 of the raw body in hex. Obtain the body before a JSON parser changes its representation. In a Node handler using the Fetch API, Buffer.from(await request.arrayBuffer()) preserves those bytes. Signature format.
import { createHmac, timingSafeEqual } from "node:crypto";
export function verifyChert(rawBody, signature, secret) {
if (signature?.length !== 71 || !/^sha256=[0-9a-fA-F]{64}$/.test(signature)) {
return false;
}
const received = Buffer.from(signature.slice(7), "hex");
const expected = createHmac("sha256", secret)
.update(rawBody)
.digest();
return timingSafeEqual(received, expected);
}
Reject a failed verification before parsing or processing the payload. In a unit test, sign a JSON fixture with a test secret and pass those same bytes. Change one whitespace character and expect verification to fail. Re-serializing parsed JSON can likewise change which bytes are signed. Node’s constant-time comparison reference.
Acknowledge lifecycle events after a durable write
Chert delivers at least once and retries non-2xx responses with backoff. For events such as call.ended, insert a queue job under a unique event_id before returning 2xx. If the same delivery arrives again and that job already exists durably, return 2xx for the duplicate. Give downstream actions their own idempotency key when you can. For example, a follow-up email job can use the terminal event ID as its unique key. Delivery semantics.
Reply to incoming calls before the deadline
On a customer_decides line, a 2xx acknowledgment alone does not answer call.incoming. Return a valid accept or decline body within the five-second decision window. Retries stop at the deadline and the call fails closed. Use the call ID to reuse setup work for a repeated delivery while the decision is still valid. Exercise duplicate delivery and an expired decision in local tests before connecting the line. Incoming decision contract.
Related guides
Build your first conversation.
Choose a plan, connect your agent, and test the complete flow.
Start building