Skip to content
Developers

Verifying webhook signatures

Every iChatUp webhook carries an X-iChatUp-Signature header of the form sha256= followed by a hex HMAC-SHA256 of the raw request body, keyed with your account’s webhook secret. To verify a call, compute the same HMAC over the exact bytes you received, add the prefix, and compare the two in constant time. Reject the request when they differ.

更新于 2026年11月22日 · 由 Rahil · Markdown

要点一览

HeaderX-iChatUp-Signature: sha256=…
AlgorithmHMAC-SHA256, hex digest
Signed contentThe raw JSON body, byte for byte
SecretIntegrations page, “For your developer”; starts with whsec_

Node.js

const crypto = require("crypto");

function isFromIchatup(rawBody, header, secret) {
  const expected = "sha256=" +
    crypto.createHmac("sha256", secret).update(rawBody).digest("hex");
  const a = Buffer.from(expected);
  const b = Buffer.from(header || "");
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

// Express: app.post("/ichatup", express.raw({ type: "application/json" }), ...)
// then isFromIchatup(req.body, req.get("X-iChatUp-Signature"), process.env.ICHATUP_WEBHOOK_SECRET)

PHP

$raw = file_get_contents("php://input");
$expected = "sha256=" . hash_hmac("sha256", $raw, getenv("ICHATUP_WEBHOOK_SECRET"));
$given = $_SERVER["HTTP_X_ICHATUP_SIGNATURE"] ?? "";

if (!hash_equals($expected, $given)) {
    http_response_code(401);
    exit;
}
$event = json_decode($raw, true);

Common mistakes

  • Hashing parsed JSON. Re-encoding the body changes spacing and escaping, so the HMAC will not match. Hash the raw bytes.
  • Forgetting the prefix. The header value includes sha256=.
  • Comparing with ==. Use a constant-time comparison.
  • Trusting old calls. The signature does not cover a timestamp, so also de-duplicate on X-iChatUp-Delivery and ignore events whose occurred_at is far in the past.

Keep the secret on your server, like an API key. Event fields are listed in webhook events.

常见问题

When is the secret created?

The first time a webhook address is saved. It then stays the same, and the Integrations page shows it under “For your developer”.

Is the test lead signed too?

Yes. The “Send a test lead” button signs it with the same secret, so you can test verification with it.

在您自己的号码上试试

两分钟完成连接,免费试用 7 天,无需信用卡。AI 员工会在顾客已经熟悉的 WhatsApp 号码上回复、预订并跟进。