Walkthroughs
Keep your CRM up to date with webhooks
Get changes pushed to your server instead of polling for them.
This walkthrough builds a receiver that updates your CRM when Valeron analyzes a call. It uses the same pattern for every event.
#1. Build the receiver
Your endpoint needs to:
- accept
POSTrequests over HTTPS, - verify the signature on the raw body,
- skip events it has already handled,
- answer
2xxwithin 10 seconds, and do the real work afterward.
import crypto from "node:crypto";
import express from "express";
const app = express();
const seen = new Set(); // use your database in production
app.post("/hooks/valeron", express.raw({ type: "application/json" }), async (req, res) => {
const rawBody = req.body.toString("utf8");
const header = req.get("Valeron-Signature") ?? "";
const parts = Object.fromEntries(header.split(",").map((part) => part.trim().split("=")));
const expected = crypto.createHmac("sha256", process.env.VALERON_WEBHOOK_SECRET)
.update(`${parts.t}.${rawBody}`).digest("hex");
const valid = parts.v1 && parts.v1.length === expected.length
&& crypto.timingSafeEqual(Buffer.from(parts.v1), Buffer.from(expected));
if (!valid) return res.status(400).send("Invalid signature");
const event = JSON.parse(rawBody);
if (seen.has(event.id)) return res.sendStatus(200); // a repeat
seen.add(event.id);
res.sendStatus(200);
if (event.type === "recording.analyzed") await saveAnalysis(event.data);
if (event.type === "contact.stage_changed") await updateContact(event.data);
});The full signature code, with Python, is in Verify signatures.
#2. Register the endpoint
Create it with POST /v1/webhook-endpoints, using the events you handle. Store the whsec_… secret from the response: it is shown once.
curl -X POST "https://api.valeron.io/v1/webhook-endpoints" \
-H "Authorization: Bearer $VALERON_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://crm.example.com/hooks/valeron","events":["recording.analyzed","contact.stage_changed"]}'#3. Send a test
Call POST /v1/webhook-endpoints/{endpoint_id}/test. Valeron sends a ping. Check that your receiver verifies it and answers 200.
#4. Handle ordering
Events can arrive out of order and more than once. Before you overwrite a record, compare its updated_at with the one you hold, and ignore the event if yours is newer. See Delivery and retries.
#5. Recover from outages
If your receiver is down, Valeron retries for about 24 hours. If every delivery fails for 3 days, the endpoint is switched off and the Owner is notified. After you fix the receiver:
- turn the endpoint back on with
PATCH /v1/webhook-endpoints/{endpoint_id}and{ "is_enabled": true }, - run an
updated_sincesync from the time it stopped, to catch what you missed. See Pagination and syncing.
You can see every attempt of the last 30 days with GET /v1/webhook-endpoints/{endpoint_id}/deliveries, and send a missed one again with POST /v1/webhook-deliveries/{delivery_id}/retry.
