Skip to content
WAQR comes included with Emboxia, Zygore and AXEN. See how

Developers

Signed webhooks: how to receive WhatsApp events securely

How to verify WAQR webhook signatures in Node.js, avoid the usual mistakes, deduplicate events and rotate your secret without downtime.

Published
Reading time
5 min read
In this article
  1. 01 Why webhooks need signatures
  2. 02 Anatomy of a delivery
  3. 03 Verifying the signature step by step
  4. 04 Common verification mistakes
  5. 05 Idempotency, fast responses and retries
  6. 06 Rotating the secret and fetching content
  7. 07 Where to start

When a message reaches one of your numbers or a connection drops, WAQR tells your system with a webhook. This guide is for whoever builds the receiver. It covers what each delivery contains, how to confirm it really came from WAQR, and how to keep your integration solid through retries, clock drift and secret rotations.

Why webhooks need signatures

Your webhook endpoint is a public URL. Anyone who learns it can POST a JSON body claiming “a message arrived” or “the connection went down”. If your code acts on that without checking, a stranger could trigger jobs, pollute your data or probe your system for free.

Signatures close that gap. WAQR computes an HMAC-SHA256 over the delivery using a secret that only WAQR and you know. Change a single byte of the body, or replay an old delivery with a new date, and the signature no longer matches, so your server rejects it.

WAQR webhooks follow the Standard Webhooks v1 specification. You don’t have to invent anything: the header format and the algorithm are public, and the standardwebhooks library (on npm and PyPI) can do the verification for you. It still pays to understand what happens underneath, because most bugs hide in the details.

Anatomy of a delivery

Each delivery is an HTTPS POST with a JSON body and four custom headers. Here is a sample:

POST /webhooks/waqr HTTP/1.1
Host: your-app.example.com
Content-Type: application/json
webhook-id: evt_8f2c41d9a7
webhook-timestamp: 1792004400
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pcU=
waqr-attempt: 1

{"type":"connection.disconnected","timestamp":"2026-10-14T19:00:00.000Z","data":{"organizationId":"org_…","connectionId":"conn_…","label":"Sales","status":"logged_out","phoneE164":"+51987654321","reason":"logout_requested"}}

What each header means:

  • webhook-id: the event identifier. It stays the same across retries, which makes it your deduplication key.
  • webhook-timestamp: Unix seconds for the current attempt. It changes on every retry.
  • webhook-signature: one or more signatures in the form v1,<base64>. While a secret is being rotated you may get two, separated by a space.
  • waqr-attempt: the attempt number. Informational only; it is not part of the signature.

The type field names the event: connection.connected, connection.disconnected, message.received, message.status_updated, contact.merged and others. Your code should ignore types it doesn’t recognize, since new events can be added over time.

Verifying the signature step by step

The algorithm has five steps:

  1. Read the three headers: webhook-id, webhook-timestamp and webhook-signature. Reject if any is missing.
  2. Check that the timestamp is within 300 seconds of your current time, in either direction.
  3. Derive the key: strip the whsec_ prefix from the secret and base64-decode the rest.
  4. Compute HMAC-SHA256 over ${id}.${timestamp}.${rawBody} with that key.
  5. Compare the result, in constant time, against every v1 signature in the header. One match is enough.

Here it is in Node.js with no external dependencies:

import crypto from "node:crypto";
import http from "node:http";

const TOLERANCE_SECONDS = 300;

function verifyWebhook(rawBody, headers, secret) {
  const id = headers["webhook-id"];
  const timestamp = headers["webhook-timestamp"];
  const signatures = headers["webhook-signature"];
  if (!id || !timestamp || !signatures) throw new Error("missing headers");

  const ts = Number(timestamp);
  const now = Math.floor(Date.now() / 1000);
  if (!Number.isInteger(ts) || Math.abs(now - ts) > TOLERANCE_SECONDS) {
    throw new Error("timestamp out of tolerance");
  }

  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const expected = crypto
    .createHmac("sha256", key)
    .update(`${id}.${timestamp}.${rawBody}`)
    .digest();

  const ok = signatures.split(" ").some((entry) => {
    const [version, value] = entry.split(",");
    if (version !== "v1" || !value) return false;
    const received = Buffer.from(value, "base64");
    return received.length === expected.length &&
      crypto.timingSafeEqual(received, expected);
  });
  if (!ok) throw new Error("invalid signature");
  return JSON.parse(rawBody);
}

http.createServer((req, res) => {
  const chunks = [];
  req.on("data", (chunk) => chunks.push(chunk));
  req.on("end", () => {
    const rawBody = Buffer.concat(chunks).toString("utf8");
    let event;
    try {
      event = verifyWebhook(rawBody, req.headers, process.env.WAQR_WEBHOOK_SECRET);
    } catch {
      res.writeHead(401).end();
      return;
    }
    res.writeHead(204).end();
    enqueue(req.headers["webhook-id"], event); // your job queue
  });
}).listen(8080);

Note the length check before timingSafeEqual. That function throws when the two buffers differ in size, and a malformed signature shouldn’t crash your process. Also keep in mind that WAQR only delivers to HTTPS on port 443, so this server needs to sit behind your TLS-terminating proxy or load balancer.

Common verification mistakes

Nearly every “the signature never matches” report comes down to one of these four:

  • Re-serializing the JSON. If you run JSON.stringify(req.body) and sign that, whitespace, key order or character escaping may change. The signature covers the exact bytes that arrived. Always use the raw body.
  • Your framework already parsed the body. Express, Fastify and friends often turn the body into an object before your route sees it. Configure that route to receive the raw body (in Express, express.raw({ type: "application/json" })) and parse it yourself after verifying.
  • Comparing with ===. A regular string comparison stops at the first mismatched character, and response timing can leak information. Use crypto.timingSafeEqual or your language’s equivalent.
  • Clock drift. If your server clock runs a few minutes fast or slow, the 300-second check will reject legitimate deliveries. Keep NTP running on your hosts and containers.

Idempotency, fast responses and retries

Delivery is at-least-once: the same event can reach you more than once, for example when your response gets lost on the network. Store the webhook-id values you have processed (a table with a unique index works well) and drop repeats. That way a retry never creates a duplicate record or fires the same action twice.

Return a 2xx as soon as the signature checks out, and push the heavy lifting to a queue. WAQR waits 15 seconds at most; a receiver that calls other APIs or writes a lot to the database before answering will eventually count as a failure. Don’t redirect either: a 3xx is treated as an error.

When a delivery fails, WAQR retries immediately, then after 5 s, 5 min, 30 min, 2 h, 5 h, 10 h, 14 h, 20 h and 24 h, with ±10% random jitter. That’s 10 attempts spread over roughly three days. If they all fail, the delivery is marked exhausted and can only be resent by hand (replay) from the delivery log, where you can inspect every attempt with its status code and duration.

Two things disable an endpoint: answering 410 Gone, or piling up 50 consecutive failures with no success in between. You can turn it back on from the dashboard or through the API. Before going live, fire the webhook.test event to confirm everything works end to end.

Rotating the secret and fetching content

The whsec_… secret is shown exactly once, when you create the endpoint. Put it in your secrets manager, never in the repository.

Rotation causes no downtime. When you generate a new secret, the old one keeps signing for 24 hours, and each delivery carries both signatures separated by a space. Since the code above accepts any valid v1 signature, your receiver verifies correctly with either the old or the new secret. The sequence is simple: rotate in the dashboard, deploy the new secret, done, all within that 24-hour window.

One more thing worth knowing: the webhook body does not include message text or any secrets. It carries only identifiers and metadata, and stays under 64 KB. When you need a message’s content, ask the REST API (https://api.waqr.app/v1) from your server with a wq_live_… key that has the messages:read scope. Even if someone captures a delivery, they get no conversations out of it.

Where to start

Create an endpoint in the dashboard, store the secret, deploy the verifier and send a webhook.test. If you’d rather not maintain signing code, use the standardwebhooks library. The full event list lives in the webhooks documentation, and the rest of the API is on the developers page.

Connect your WhatsApp once

Scan the QR from the dashboard and decide which systems can use each number.

Keep reading

All articles