WhatsApp guide

How to test WhatsApp Cloud API webhooks locally

Get Meta to accept a webhook URL before your app is deployed, check every signature against your App Secret, and replay messages and status updates while you work on your handler.

Updated 19 November 2026 · 8 minute read

The WhatsApp Cloud API sends incoming messages and delivery updates to a webhook, and Meta only accepts a public HTTPS URL that answers its verify request first. Your handler runs on localhost. This guide gets a fixed URL past that check, then forwards every event to your machine and keeps a history you can replay.

Why WhatsApp webhooks are awkward to test

  • Meta checks the URL before saving it. It sends a GET with hub.mode=subscribe, hub.verify_token and hub.challenge, and only saves the URL if the response is 200 with the challenge as the whole body.
  • Each test needs a real message. To see a messages event you send a WhatsApp message from your phone. To see delivered and read statuses you send a message from the API and wait for them.
  • Deliveries look like GitHub's. Meta signs with X-Hub-Signature-256, an HMAC-SHA256 of the raw body keyed with your app's App Secret. Verifying a re-encoded body fails, and Meta's bodies escape non-ASCII characters, so parsed and re-serialised JSON rarely matches.

A tunnel gets requests to your laptop, but its URL changes or goes quiet when your laptop sleeps, and each new URL has to pass the verify request again. A fixed URL that answers the verify request itself avoids both.

1. Get a fixed webhook URL

Sign up and SlingHook creates an endpoint. (The no-account try page catches requests too, but it has no settings, so it can't answer Meta's verify request.) Its URL looks like this:

https://slinghook.co.za/c/9f2c41d0-7a3e-4b8e-a1f5-2d6c8e0b3a17

2. Pass Meta's verify request

  1. Make up a verify token, for example my-whatsapp-dev. It is not a secret key, just a value both sides agree on.
  2. In SlingHook, open the endpoint's settings and enter it under Meta verify token.
  3. In the Meta App Dashboard, open your app, then WhatsApp → Configuration. Under Webhook, paste the SlingHook URL as the Callback URL, enter the same verify token and choose Verify and save.
  4. Under Webhook fields, subscribe to messages. That one field carries both incoming messages and status updates.

The catch URL answers the verify request with the challenge when the token matches, and with 403 when it doesn't. Both requests show in the feed, so if Meta reports that the URL couldn't be validated you can see exactly what it sent.

Instagram and Messenger use the same verify request and the same signature, so this works for their webhooks too.

3. Check signatures with your App Secret

In the App Dashboard, open App settings → Basic and reveal the App secret. Paste it into the endpoint's Webhook signing secret in SlingHook and set the signature provider to GitHub / Meta. Each WhatsApp request in the feed is then marked valid or invalid.

When a signature fails, click the badge. The signature debugger tells you whether the secret is wrong (a common mix-up is pasting the access token or the verify token), has stray whitespace, or whether the body was changed on the way.

4. Forward events to your machine

Sign in to the CLI once, then listen:

npx slinghook login
npx slinghook listen 9f2c41d0-7a3e-4b8e-a1f5-2d6c8e0b3a17 --forward http://localhost:3000/webhooks/whatsapp

The CLI makes an outbound connection, so there are no open ports. Each event reaches your local server with Meta's original body and X-Hub-Signature-256 header, so your verification code runs exactly as it will in production.

5. Write the handler

Your production URL will have to answer the verify request itself, so the handler covers both the GET and the POST. Verify the signature against the raw body. In Express:

import crypto from 'node:crypto';
import express from 'express';

const app = express();

// Meta's verify request when you save the callback URL
app.get('/webhooks/whatsapp', (req, res) => {
    if (req.query['hub.mode'] === 'subscribe'
        && req.query['hub.verify_token'] === process.env.META_VERIFY_TOKEN) {
        return res.type('text/plain').send(String(req.query['hub.challenge']));
    }
    res.sendStatus(403);
});

// Raw body for this route only. Register it before app.use(express.json()).
app.post('/webhooks/whatsapp', express.raw({ type: 'application/json' }), (req, res) => {
    const received = Buffer.from(req.get('x-hub-signature-256') ?? '');
    const expected = Buffer.from('sha256=' + crypto
        .createHmac('sha256', process.env.META_APP_SECRET)
        .update(req.body)                              // a Buffer, not a parsed object
        .digest('hex'));
    if (received.length !== expected.length || !crypto.timingSafeEqual(received, expected)) {
        return res.sendStatus(401);
    }

    const payload = JSON.parse(req.body);
    for (const entry of payload.entry ?? []) {
        for (const { value } of entry.changes ?? []) {
            for (const message of value.messages ?? []) {
                // message.from, message.type, message.text?.body
            }
            for (const status of value.statuses ?? []) {
                // status.id (the wamid you sent), status.status: sent, delivered, read or failed
            }
        }
    }
    res.sendStatus(200);
});

app.listen(3000);

The same in plain PHP. PHP turns hub.mode into hub_mode in $_GET:

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    if (($_GET['hub_mode'] ?? '') === 'subscribe'
        && hash_equals(getenv('META_VERIFY_TOKEN'), (string) ($_GET['hub_verify_token'] ?? ''))) {
        header('Content-Type: text/plain');
        echo (string) ($_GET['hub_challenge'] ?? '');
        exit;
    }
    http_response_code(403);
    exit;
}

$payload  = file_get_contents('php://input');
$expected = 'sha256=' . hash_hmac('sha256', $payload, getenv('META_APP_SECRET'));
if (!hash_equals($expected, $_SERVER['HTTP_X_HUB_SIGNATURE_256'] ?? '')) {
    http_response_code(401);
    exit;
}

$event = json_decode($payload, true);

Answer 200 quickly. Meta retries deliveries that fail, with longer gaps each time, for several days, so do slow work in a queue.

6. Send yourself test events

  • A message. On WhatsApp → API Setup, add your own phone number as a recipient of the test number, then send the test number a WhatsApp message. A messages event arrives with value.messages.
  • Status updates. Send the hello_world template to your phone from the same page (or with the Graph API). Status events arrive as it is sent, delivered and read, with value.statuses.
  • SlingHook's simulator. Press Simulate above the feed and pick a WhatsApp event: a text message, a button reply, or a delivered, read or failed status. With your App Secret saved, it is signed the way Meta signs it.

7. Change your code and replay

When your handler throws, fix it and press Replay on the event in SlingHook. The same body and X-Hub-Signature-256 go to localhost again, so you don't need another message from your phone to test one line. Meta's signature has no timestamp, so a replayed event still passes verification, however old it is.

De-duplicate by message id. Meta can deliver the same event more than once, and a replay is a deliberate repeat. Store message.id (a wamid.) or the status id and status, and skip ones you've already handled. Replays also carry X-Webhook-Replay: true if you want to tell them apart.

Checklist

  • Callback URL saved in the App Dashboard, with the same verify token in SlingHook
  • Subscribed to the messages webhook field
  • The App Secret (not the access token) in your .env and in SlingHook
  • Raw body on the webhook route
  • Return 200 quickly and handle repeats safely
  • A GET handler for the verify request before you point Meta at production

Catch your WhatsApp webhooks in one place.

Free plan, no card needed. Your URL is ready as soon as you sign up.

Get a free endpoint