Real-Time Lead Alerts via WhatsApp Cloud Webhooks

A visitor fills in your quote form at 11pm on a Saturday. The email sits unread until Monday morning. By then the visitor has filled in three other forms — and one of those businesses called back within the hour.
Speed of reply wins high-ticket work. This guide explains the alert system we wire into websites so that never happens again — as a pipeline you can follow stage by stage, with the code that holds it together.
The pipeline, end to end
Here is the whole flow in one picture. A lead is not an email and not a dashboard row; it is a message that has to travel from a stranger's browser to your pocket, and every stage below is a place it can get lost:
- Form: the visitor submits the quote form on your website.
- Webhook endpoint: your server receives the submission and checks it really came from Meta.
- Queue: the verified job waits its turn instead of being sent on the spot.
- WhatsApp Cloud API: a worker sends the alert through the Cloud API, under your business name.
- Delivery receipt: Meta confirms the message landed, and the lead is written to a Sheet as the permanent record.
Each stage is small on its own; the reliability comes from all five working together.
Stage one: the form fires
Everything starts with the form, and its job is narrower than most people think. It collects four things — name, service, phone number, message — and posts them to your server, not only to an inbox. The server decides what happens next, which is why a form that only sends an email has already given up: the email has no way to wake anyone up.
Validation happens on the server, not just in the browser, because browser checks are a courtesy and server checks are the lock. A phone number must be digits after cleaning; the service must come from the real list of services, not free text that breaks the alert; the message must be present, not a blank submit from a bot. A lead that fails validation is logged and dropped with a reason, not silently lost.
Stage two: verify before you trust it
The endpoint that receives Meta's callbacks cannot trust every request that arrives at it. Anyone can post to a URL; only Meta can sign the request correctly. Every callback carries an X-Hub-Signature-256 header — an HMAC of the request body, made with your app secret — and the handler recomputes it and compares. If they do not match, the request is rejected before anything else happens.
This is the handler, in Flask. It verifies the signature, pulls the message id out of the payload, drops duplicates, and hands the real message to the alert sender:
import hashlib
import hmac
from flask import Flask, request
app = Flask(__name__)
APP_SECRET = "put-your-app-secret-in-an-env-var"
SEEN = set()
@app.route("/webhook", methods=["POST"])
def webhook():
signature = request.headers.get("X-Hub-Signature-256", "")
expected = "sha256=" + hmac.new(
APP_SECRET.encode(), request.data, hashlib.sha256
).hexdigest()
if not hmac.compare_digest(signature, expected):
return "bad signature", 403
body = request.get_json(force=True)
message_id = body["entry"][0]["changes"][0]["value"]["messages"][0]["id"]
if message_id in SEEN:
return "duplicate", 200
SEEN.add(message_id)
send_whatsapp_alert(body)
return "ok", 200
Three things in that handler deserve a second look. The comparison uses hmac.compare_digest, not a plain ==, so the check does not leak timing information. The dedupe happens on the message id before anything is sent, so a redelivered event can never produce a second alert. And SEEN here is an in-memory set for readability — in production it lives in Redis, because a server restart would forget every id and send every alert twice. Meta also checks the endpoint once with a GET request carrying hub.challenge: answer it with the challenge value and the verify token you chose, or the webhook is never switched on.

Stage three: queue, then send
The handler does not send the WhatsApp message itself. It puts a job on a Redis queue and returns, and a worker takes the job and calls the Cloud API. That separation keeps the endpoint fast — Meta expects a quick 200 response, and a handler that waits on a slow API call will time out and get the same event delivered again. The queue also holds night leads for quiet hours: they wait and arrive in the morning, still recorded, never lost.
We learned the value of the queue building the WhatsApp bot inside LeadForge Engine, our own lead-generation tool. Its messages go out only for approved leads, inside warm-up caps that rise gradually, because a number that spams gets restricted and then nothing gets through at all. The approval gate and the caps are part of the design, not an afterthought. The alert system only messages you, the business owner — but the sending number still has to stay in good standing, and a queue with caps is how it stays there.
Stage four: the alert itself
A good alert has everything needed to reply in one glance: who wrote, what they want, how to reach them, and what they said. Nothing more — an alert that needs a second look-up before you can reply is an alert that gets answered late. The message goes out through the WhatsApp Cloud API, under your business name, not from a personal number pasted into a script: delivery is reliable, the business name shows on the alert, and nothing breaks when a phone is switched off or a number changes.
The setup needs a WhatsApp Business account and a verified business. We handle the setup; you approve the business details, and the alerts belong to your business from day one. A quiet copy of every lead goes into a Sheet at the same time, so there is always a record — even if a phone is lost or a message is deleted by accident. The Sheet is the backup; the phone is the trigger.
Stage five: the delivery receipt
Sending is not the same as delivering. Meta returns a message id and a status for every send, and the worker stores both next to the lead. If the receipt never arrives, the job stays in the queue and is retried — the lead is not assumed delivered just because the API call returned. And when you reply to a lead on WhatsApp, you are messaging a person who asked to be contacted: reply to the enquiry, not with a broadcast they never asked for.
We test the whole pipeline with your own number before it goes live: you submit the form yourself, and your phone lights up. If it does not, we fix it before any real lead depends on it — a green tick in a dashboard is not a message on a phone.
When it breaks: three failure modes
Pipelines break in predictable ways, and each one has a boring fix:
- Duplicate delivery: Meta can deliver the same event twice. The fix is the dedupe in the handler — check the message id against the Redis set first, and return 200 without sending anything the second time. A duplicate alert is worse than a late one: it teaches you to ignore the alerts.
- Expired token: the Cloud API token expires or is rotated, and the send fails with an authentication error. The worker logs it, the job stays queued instead of being dropped, and you regenerate the token in Meta's dashboard. The token lives in an environment variable, never hard-coded in the source.
- Rate limits: too many sends too fast, and the API answers with a rate-limit error. The worker backs off, the rest wait in the queue, and sends spread out instead of piling up. Warm-up caps exist for exactly this reason: a new number earns its sending volume gradually.
None of these needs a human watching a dashboard — just the queue, the log, and the receipt the pipeline is built from.
What to do next
Check one thing: how long did your last three enquiries wait for a reply? If the answer is "till Monday", the fix is a webhook and an afternoon of setup. Read about our AI chatbot and Python Automation work, get an instant estimate, or tell us on WhatsApp which form should trigger the alert.