Verifying signatures
Check that a webhook delivery really came from DialerDay and wasn't changed or replayed, with Node and Python code.
Your webhook URL is public, so anyone who finds it can send it requests. Every DialerDay delivery is signed with your webhook's secret; checking the signature proves the request came from DialerDay and that the body wasn't changed on the way.
Verify every delivery before you act on it.
The signing scheme
Each delivery has an X-Webhook-Signature header:
X-Webhook-Signature: t=1791473584,v1=b9d0f42b8d3f37a224fc597caa34ab217c330a715ce3349a8cb390e788928c10tis when the request was signed, in Unix seconds.v1is the HMAC-SHA256 of the string<t>.<body>, keyed with your webhook secret, as lowercase hex.
<body> is the raw request body, byte for byte, exactly as it arrived. The secret is the whole string you were given, including its whsec_ prefix.
It is the same idea as Stripe's webhook signatures, so libraries and habits from there carry over.
To verify:
- Split the header on
,and each part on the first=, to gettandv1. - Build the string
t + "." + raw body. - Compute HMAC-SHA256 of it with your secret, and hex-encode it.
- Compare it with
v1using a constant-time comparison. - Check that
tis recent (for example within 5 minutes) to refuse old requests someone replays.
Warning
Use the raw body. If your framework parses the JSON first and you serialise it again, spacing, key order or escaping can change and the signature won't match. Read the body as bytes, verify, then parse it.
Where to find the secret
- Webhooks added in the app: the secret is shown when you click Add webhook, and again any time with Show secret under Settings → Webhooks.
- Webhooks added with
POST /v1/hooks: the secret is in the response ("secret": "whsec_…"). Store it then; the API doesn't return it again (a manager can still use Show secret in the app).
Each webhook has its own secret. If you have several webhooks pointing at one URL, look up the secret by which webhook the URL belongs to, or give each webhook its own path.
Node.js
Works with Node 18 and later, no dependencies beyond express for the server part.
import crypto from "node:crypto";
import express from "express";
const SECRET = process.env.DIALERDAY_WEBHOOK_SECRET; // "whsec_…"
const TOLERANCE_SECONDS = 5 * 60;
/**
* True when `header` (X-Webhook-Signature) is a valid DialerDay signature
* of `rawBody` (a Buffer with the exact bytes received).
*/
export function verifyDialerDaySignature(rawBody, header, secret, toleranceSeconds = TOLERANCE_SECONDS) {
if (typeof header !== "string" || !header) return false;
const parts = {};
for (const part of header.split(",")) {
const i = part.indexOf("=");
if (i > 0) parts[part.slice(0, i).trim()] = part.slice(i + 1).trim();
}
const t = Number(parts.t);
const v1 = parts.v1;
if (!Number.isInteger(t) || !v1) return false;
// Refuse requests signed too long ago (or too far in the future).
if (Math.abs(Math.floor(Date.now() / 1000) - t) > toleranceSeconds) return false;
const expected = crypto
.createHmac("sha256", secret)
.update(`${t}.`)
.update(rawBody)
.digest();
const given = Buffer.from(v1, "hex");
return given.length === expected.length && crypto.timingSafeEqual(given, expected);
}
const app = express();
// express.raw keeps the body as a Buffer; don't use express.json() on this route.
app.post("/dialerday/webhooks", express.raw({ type: "application/json" }), (req, res) => {
if (!verifyDialerDaySignature(req.body, req.get("X-Webhook-Signature"), SECRET)) {
return res.status(401).send("Invalid signature");
}
const delivery = JSON.parse(req.body.toString("utf8"));
// delivery = { id, event, created_at, company_id, data }
// Answer fast, then process (store it or put it on a queue first).
res.sendStatus(200);
handleEvent(delivery).catch((err) => console.error("webhook failed", delivery.id, err));
});
async function handleEvent(delivery) {
switch (delivery.event) {
case "call.completed":
console.log("Call", delivery.data.id, "ended with", delivery.data.disposition);
break;
case "sms.received":
console.log("Text from", delivery.data.conversation.contact_phone, ":", delivery.data.message.body);
break;
case "ping":
break;
}
}
app.listen(3000);In other Node frameworks, get the raw body the same way: in Next.js route handlers use Buffer.from(await request.arrayBuffer()); in Fastify add a content type parser with parseAs: "buffer".
Python
Uses only the standard library for verification; the example server uses Flask.
import hashlib
import hmac
import json
import os
import time
from flask import Flask, abort, request
SECRET = os.environ["DIALERDAY_WEBHOOK_SECRET"] # "whsec_…"
TOLERANCE_SECONDS = 5 * 60
def verify_dialerday_signature(raw_body: bytes, header: str | None, secret: str,
tolerance_seconds: int = TOLERANCE_SECONDS) -> bool:
"""True when `header` (X-Webhook-Signature) is a valid signature of `raw_body`."""
if not header:
return False
parts = {}
for part in header.split(","):
key, sep, value = part.partition("=")
if sep:
parts[key.strip()] = value.strip()
try:
t = int(parts["t"])
v1 = parts["v1"]
except (KeyError, ValueError):
return False
# Refuse requests signed too long ago (or too far in the future).
if abs(int(time.time()) - t) > tolerance_seconds:
return False
expected = hmac.new(secret.encode("utf-8"), f"{t}.".encode("ascii") + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected.encode(), v1.encode())
app = Flask(__name__)
@app.post("/dialerday/webhooks")
def dialerday_webhook():
raw = request.get_data() # the exact bytes received; call this before request.json
if not verify_dialerday_signature(raw, request.headers.get("X-Webhook-Signature"), SECRET):
abort(401)
delivery = json.loads(raw)
# delivery = {"id", "event", "created_at", "company_id", "data"}
if delivery["event"] == "call.completed":
print("Call", delivery["data"]["id"], "ended with", delivery["data"]["disposition"])
elif delivery["event"] == "sms.received":
print("Text from", delivery["data"]["conversation"]["contact_phone"])
return "", 200In Django use request.body; in FastAPI use await request.body(). Both are the raw bytes.
Test your code
Run your verification function against this known delivery. With the tolerance check turned off (the timestamp is in the past), it must return true:
| Secret | whsec_0123456789abcdef0123456789abcdef0123456789abcdef |
| Body | {"id":"8f14e45f-ceea-4c6b-9a7e-2a1f0e6d3b21","event":"ping","created_at":"2026-10-07T15:33:04.000Z","company_id":1,"data":{}} |
| Header | t=1791473584,v1=b9d0f42b8d3f37a224fc597caa34ab217c330a715ce3349a8cb390e788928c10 |
const body = Buffer.from('{"id":"8f14e45f-ceea-4c6b-9a7e-2a1f0e6d3b21","event":"ping","created_at":"2026-10-07T15:33:04.000Z","company_id":1,"data":{}}');
const header = "t=1791473584,v1=b9d0f42b8d3f37a224fc597caa34ab217c330a715ce3349a8cb390e788928c10";
const secret = "whsec_0123456789abcdef0123456789abcdef0123456789abcdef";
console.log(verifyDialerDaySignature(body, header, secret, Infinity)); // truebody = b'{"id":"8f14e45f-ceea-4c6b-9a7e-2a1f0e6d3b21","event":"ping","created_at":"2026-10-07T15:33:04.000Z","company_id":1,"data":{}}'
header = "t=1791473584,v1=b9d0f42b8d3f37a224fc597caa34ab217c330a715ce3349a8cb390e788928c10"
secret = "whsec_0123456789abcdef0123456789abcdef0123456789abcdef"
print(verify_dialerday_signature(body, header, secret, tolerance_seconds=10**12)) # TrueThen click Send test on your webhook in Settings → Webhooks: the ping it sends is signed like every real event.
Troubleshooting
- The signature never matches. You're almost certainly hashing a re-serialised body. Log the raw bytes you hash and compare them with what arrived. Also check the secret is complete, with its
whsec_prefix, and has no trailing newline or spaces. - It matches locally but not in production. A proxy or middleware may be decoding, re-encoding or decompressing the body before your code sees it. Verify as close to the raw request as you can.
- Timestamps are rejected. Your server's clock is off; sync it with NTP. Retries are signed again when they are sent, so a delivery retried an hour later still carries a fresh
t. - You rotated nothing but signatures broke. Each webhook has its own secret. If you deleted the webhook and added it again, it has a new secret.
Note
There is no way to change a webhook's secret in place. To rotate it, add a new webhook with the same URL and events, update your server to accept either secret, then delete the old webhook. While both exist, each event arrives twice with the same id, so skip the repeat by id.