Skip to content

WhatsApp Cloud API webhook in Hono with signature verification

In Hono, hand the underlying fetch Request (c.req.raw) to handleRequest. It answers the GET handshake and the signed POST, and reads the raw bytes itself, so do not call c.req.json() first.

examples/hono/server.ts
import { serve } from '@hono/node-server';
import { Hono } from 'hono';
import { createWebhookHandler } from '@solvejet/whatsapp-cloud-api';
import { echoText, requireEnv } from '../shared/reply.js';
const webhook = createWebhookHandler({
appSecrets: requireEnv('WHATSAPP_APP_SECRET'),
verifyToken: requireEnv('WHATSAPP_VERIFY_TOKEN'),
});
webhook.on('message', ({ message }) => echoText(message));
const app = new Hono();
// handleRequest takes a fetch Request and answers both the GET handshake and the
// signed POST. It reads the raw bytes itself, so do not parse the body first.
app.all('/webhook', (c) => webhook.handleRequest(c.req.raw));
serve({ fetch: app.fetch, port: 3000 });
console.log('Listening on http://localhost:3000/webhook');

The full runnable project is in examples/hono. Each step is explained in verify the signature and the hub.challenge handshake. Meta’s own description of the two request types is in the webhook endpoint guide.

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