Skip to content

WhatsApp Cloud API webhooks on Cloudflare Workers, Bun, Deno and Vercel

The @solvejet/whatsapp-cloud-api/web entry point has the same createWebhookHandler, parsers and dedupe as the main entry, but it imports nothing from node:* and verifies signatures with Web Crypto. Use it wherever node:crypto is not available or you want one code path for every runtime.

website/snippets/edge-runtimes.ts
interface Env {
WHATSAPP_APP_SECRET: string;
WHATSAPP_VERIFY_TOKEN: string;
}
export default {
async fetch(
request: Request,
env: Env,
ctx: { waitUntil(promise: Promise<unknown>): void },
): Promise<Response> {
const webhook = createWebhookHandler({
appSecrets: env.WHATSAPP_APP_SECRET,
verifyToken: env.WHATSAPP_VERIFY_TOKEN,
ackMode: 'before', // answer first, run handlers after the response
});
webhook.on('message', ({ message }) => {
console.log('message', message.id, message.type);
});
return webhook.handleRequest(request, { waitUntil: (promise) => ctx.waitUntil(promise) });
},
};

You can also call the verifier directly:

website/snippets/edge-runtimes.ts
// Web Crypto only, no node:crypto. Resolves to a boolean and never throws.
const valid = await verifySignatureAsync(body, header, process.env.WHATSAPP_APP_SECRET!);
Runtime Status
Node.js 20, 22, 24 Verified in CI
Bun Verified in CI (the built web entry runs under Bun)
Deno Verified in CI only (the built web entry runs under Deno)
Cloudflare Workers Verified in CI in workerd, without the nodejs_compat flag
Vercel, Next.js Documented, not run in CI

With ackMode: 'before' the handler answers first and runs your handlers afterwards. Serverless platforms may stop the invocation after the response unless you tell them to wait.

  • Cloudflare Workers: pass ctx.waitUntil as in the example above.
  • Vercel: pass waitUntil from @vercel/functions as the waitUntil option, or call after() from next/server.
  • Node.js, Bun and Deno servers that keep running: nothing is needed. Without waitUntil, the background work runs as a detached promise and its failures go to onError.

If you do not need to answer early, leave ackMode at its default. The handlers then finish before the response is sent.

Independent open-source project. Not affiliated with, endorsed by or sponsored by Meta or WhatsApp. Released under the MIT licence. Source on GitHub.