Webhook receiver
Use when receiving tawk.to webhook events (chat start/end, transcripts, new tickets) — scaffolds a receiver endpoint with HMAC-SHA1 signature verification for Express, Cloudflare Workers, or Next.js.From its SKILL.md
npx -y skills add beyrakIn/tawk-plugin --skill webhook-receiverAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
4.5 KB, as published. Nobody here has run it
tawk.to Webhook Receiver
Reference: https://developer.tawk.to/webhooks/
Facts that shape the implementation
- Events:
chat:start,chat:end,chat:transcript(sent ~3 minutes after the chat ends),ticket:create. - Registration is dashboard-only (no API): Administration → Settings → Webhooks, max 10 per property. The dashboard shows the webhook secret key at creation time.
- Every delivery is signed:
X-Tawk-Signatureheader = HMAC-SHA1 (hex) of the raw request body using the webhook secret. ALWAYS verify it — never scaffold without. - Retries: failed deliveries retry for up to 12 hours;
X-Hook-Event-Idis identical across retries — use it for idempotency. - Respond fast with 200; do heavy work async. tawk times out at 30 seconds.
Signature verification (the part everyone gets wrong)
Verify against the RAW body bytes, not re-serialized JSON. Use a constant-time compare.
const crypto = require("crypto");
function verifyTawkSignature(rawBody, signatureHeader, secret) {
const expected = crypto.createHmac("sha1", secret).update(rawBody).digest("hex");
const a = Buffer.from(expected, "hex");
const b = Buffer.from(signatureHeader ?? "", "hex");
return a.length === b.length && crypto.timingSafeEqual(a, b);
}
Express
express.json() destroys the raw body — capture it with express.raw on this route:
const express = require("express");
const app = express();
app.post("/webhooks/tawk", express.raw({ type: "application/json" }), (req, res) => {
if (!verifyTawkSignature(req.body, req.get("X-Tawk-Signature"), process.env.TAWK_WEBHOOK_SECRET)) {
return res.status(401).send("bad signature");
}
const event = JSON.parse(req.body.toString("utf8"));
res.sendStatus(200); // ack immediately, process after
switch (event.event) {
case "chat:start": /* handle */ break;
case "chat:end": /* handle */ break;
case "chat:transcript": /* handle */ break;
case "ticket:create": /* handle */ break;
}
});
Next.js (App Router)
// app/api/webhooks/tawk/route.ts
import crypto from "crypto";
export async function POST(request: Request) {
const rawBody = Buffer.from(await request.arrayBuffer());
const signature = request.headers.get("x-tawk-signature") ?? "";
const expected = crypto
.createHmac("sha1", process.env.TAWK_WEBHOOK_SECRET!)
.update(rawBody)
.digest("hex");
const a = Buffer.from(expected, "hex");
const b = Buffer.from(signature, "hex");
if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {
return new Response("bad signature", { status: 401 });
}
const event = JSON.parse(rawBody.toString("utf8"));
// dispatch on event.event as in the Express example
return new Response("ok");
}
Cloudflare Workers
WebCrypto has no SHA-1 HMAC shortage — use crypto.subtle:
async function verifyTawkSignature(rawBody, signatureHex, secret) {
const key = await crypto.subtle.importKey(
"raw", new TextEncoder().encode(secret),
{ name: "HMAC", hash: "SHA-1" }, false, ["sign"]
);
const mac = await crypto.subtle.sign("HMAC", key, rawBody);
const expected = [...new Uint8Array(mac)].map((b) => b.toString(16).padStart(2, "0")).join("");
return expected === signatureHex; // acceptable here; timingSafeEqual unavailable in Workers
}
export default {
async fetch(request, env) {
if (request.method !== "POST") return new Response("not found", { status: 404 });
const rawBody = await request.arrayBuffer();
const ok = await verifyTawkSignature(rawBody, request.headers.get("X-Tawk-Signature"), env.TAWK_WEBHOOK_SECRET);
if (!ok) return new Response("bad signature", { status: 401 });
const event = JSON.parse(new TextDecoder().decode(rawBody));
// dispatch on event.event
return new Response("ok");
},
};
Checklist when helping a user
- Ask which framework, then scaffold from the matching template above.
- Secret goes in an env var (
TAWK_WEBHOOK_SECRET) — never hardcode. - Remind them to register the URL in Administration → Settings → Webhooks and copy the secret shown there.
- If their handler does slow work (DB writes, LLM calls), ack 200 first, process after.
- Suggest idempotency via
X-Hook-Event-Idif their downstream effects aren't naturally idempotent.