Before you start
- Use Node.js 22.13 or later (node:sqlite) and Bash. Start in an empty directory with port 8139 available.
- For the local exercise, generate a disposable signing secret. Project API keys and webhook signing secrets serve different purposes.
1. Save the receiver
The receiver verifies the HMAC-SHA256 signature of the timestamp, a period and the original body bytes. It accepts timestamps within five minutes and acknowledges after writing the event. A SQLite primary key deduplicates a retried delivery across restarts.
import { createServer } from "node:http";
import { createHmac, timingSafeEqual } from "node:crypto";
import { DatabaseSync } from "node:sqlite";
const secret = process.env.VELOSYLL_WEBHOOK_SECRET;
if (!secret) throw new Error("Set VELOSYLL_WEBHOOK_SECRET first.");
const db = new DatabaseSync("deliveries.sqlite");
db.exec(
"CREATE TABLE IF NOT EXISTS deliveries (id TEXT PRIMARY KEY, event TEXT NOT NULL, recording_id TEXT NOT NULL)",
);
const record = db.prepare(
"INSERT OR IGNORE INTO deliveries (id, event, recording_id) VALUES (?, ?, ?)",
);
function signatureMatches(request, body) {
const timestamp = request.headers["velosyll-timestamp"];
const signature = request.headers["velosyll-signature"];
if (typeof timestamp !== "string" || !/^\d+$/.test(timestamp)) return false;
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
if (typeof signature !== "string" || !/^[0-9a-f]{64}$/.test(signature))
return false;
const expected = createHmac("sha256", secret)
.update(timestamp + ".")
.update(body)
.digest();
return timingSafeEqual(expected, Buffer.from(signature, "hex"));
}
createServer(async (request, response) => {
const finish = (status) => {
response.writeHead(status);
response.end();
};
if (request.method !== "POST" || request.url !== "/events")
return finish(404);
try {
const chunks = [];
let size = 0;
for await (const chunk of request) {
size += chunk.length;
if (size > 16384) return finish(413);
chunks.push(chunk);
}
const body = Buffer.concat(chunks);
if (!signatureMatches(request, body)) return finish(401);
let data;
try {
data = JSON.parse(body.toString("utf8"));
} catch {
return finish(400);
}
if (
!data ||
typeof data.id !== "string" ||
typeof data.recording_id !== "string" ||
!["transcript.completed", "transcript.failed"].includes(data.event)
)
return finish(422);
const result = record.run(data.id, data.event, data.recording_id);
console.log(result.changes ? "Recorded" : "Already received", data.id);
return finish(204);
} catch {
return finish(500);
}
}).listen(8139, "127.0.0.1", () =>
console.log("Listening on http://127.0.0.1:8139/events"),
);
2. Start the receiver and send a signed fixture
Save both files together. In Bash, run the receiver in the background, then run the sender after the listening message appears. Both inherit the same temporary secret. The sender deliberately submits the same signed event twice.
import { createHmac, randomUUID } from "node:crypto";
const secret = process.env.VELOSYLL_WEBHOOK_SECRET;
if (!secret)
throw new Error("Set the same VELOSYLL_WEBHOOK_SECRET in both terminals.");
const body = JSON.stringify({
id: randomUUID(),
event: "transcript.completed",
recording_id: "local-fixture",
});
const timestamp = Math.floor(Date.now() / 1000).toString();
const signature = createHmac("sha256", secret)
.update(timestamp + "." + body)
.digest("hex");
for (let delivery = 1; delivery <= 2; delivery++) {
const response = await fetch("http://127.0.0.1:8139/events", {
method: "POST",
body,
headers: {
"Content-Type": "application/json",
"Velosyll-Timestamp": timestamp,
"Velosyll-Signature": signature,
},
signal: AbortSignal.timeout(5000),
});
console.log("Delivery", delivery, response.status);
if (response.status !== 204) process.exitCode = 1;
}
export VELOSYLL_WEBHOOK_SECRET="$(node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))")"
node webhook.mjs &
receiver_pid=$!
# After the listening message appears:
node local-delivery.mjs
kill "$receiver_pid"
unset VELOSYLL_WEBHOOK_SECRET3. Connect a deployed HTTPS receiver
For actual service delivery, an owner opens Transcription webhooks in the developer console, enters the receiver’s public HTTPS URL on port 443 and chooses Add endpoint. Configure the signing secret shown once on that receiver. The local fixture works independently of registration. The service sends transcript.completed and transcript.failed; fetch the recording with a project key and the payload’s recording_id. Configure up to five endpoints per project.
Expected result
The fixture returns HTTP 204 twice. The receiver prints Recorded once, then Already received for the same ID. The local deliveries.sqlite database contains one row for this pair.
Troubleshooting
- Signature verification returns 401.
- Check that both processes loaded the same secret, the clock is accurate, and the raw body reached verification before any JSON reserialization.
- Real callbacks remain pending.
- Check the destination’s HTTPS reachability and response code. The service retries non-2xx and network failures, up to five attempts. An owner can inspect delivery states and last_code with GET /console/webhooks.