intelligence_src_6dc544294b7f21f98a
- Source-provided label
- Publisher RSS metadata
- Evidence class
- mentioned in report
- Confidence
- Not reported
- Observed
- Nov 30, 2026 05:54 UTC
- Retrieved
- Nov 30, 2026 06:09 UTC
Most WhatsApp chatbot tutorials stop at "echo the message back". The parts that bite in production are different: checking that the webhook call really came from Meta, knowing whether you are still allowed to send a free-form reply, and getting a customer to a person when the bot shouldn't answer. WhatsApp's own rules make the last two non-optional. Free-form replies are only allowed inside the 24-hour customer service window that opens each time the customer writes to you; outside it you can send approved templates only. And WhatsApp's business messaging policy says automation is fine inside that window as long as there are "prompt, clear, and direct escalation paths" to a human. This post builds the routing core for that in plain Python (standard library only), so you can drop it behind Flask, FastAPI, a Lambda or whatever already runs your site. What the router does Verifies the signature. Meta signs each webhook POST with an HMAC-SHA256 of the raw body, using your app secret, in the X-Hub-Signature-256 header. Reject anything that doesn't match. Records the window. Every inbound message from a customer resets their 24-hour window, so we store the time of their last message. Routes each message. Plain questions go to the bot; non-text messages and anything that asks for a person, a refund or a complaint go to a human queue. Answers "can I reply free-form?" before anything is sent later. The code import hashlib, hmac, json, time WINDOW_SECONDS = 24 * 60 * 60 HANDOFF_WORDS = {"human", "agent", "person", "complaint", "refund", "cancel"} last_inbound = {} # wa_id -> unix time of the customer's last message def signature_ok(raw_body: bytes, header: str, app_secret: str) -> bool: """Check Meta's X-Hub-Signature-256 header against the raw request body.""" if not header or not header.startswith("sha256="): return False expected = hmac.new(app_secret.encode(), raw_body, hashlib.sha256).hexdigest() return hmac.compare_digest(expected, header[len("sha256="):]) def window_open(wa_id: str, now: float) -> bool: """True while the 24-hour customer service window is open for this customer.""" t = last_inbound.get(wa_id) return t is not None and now - t < WINDOW_SECONDS def route(payload: dict, now: float): """Turn a webhook payload into (wa_id, action) decisions.""" out = [] for entry in payload.get("entry", []): for change in entry.get("changes", []): for msg in change.get("value", {}).get("messages", []): wa_id = msg["from"] last_inbound[wa_id] = now # every inbound message resets the window text = msg.get("text", {}).get("body", "").lower() if msg.get("type") != "text": out.append((wa_id, "handoff: non-text message")) elif HANDOFF_WORDS & set(text.replace("?", " ").split()): out.append((wa_id, "handoff: customer asked for a person")) else: out.append((wa_id, "bot: answer from knowledge base")) return out def can_send_free_form(wa_id: str, now: float) -> str: return "free-form reply allowed" if window_open(wa_id, now) else "template only" A few details that matter: Use the raw body for the HMAC. If your framework parses JSON first and you re-serialise it, the bytes change and every signature fails. In Flask that is request.get_data(); in FastAPI, await request.body(). hmac.compare_digest avoids leaking timing information when comparing signatures. The window is per customer, keyed on the from number (wa_id). In production, keep last_inbound in Redis or your database, not in memory, so it survives restarts and works across workers. The keyword list is deliberately blunt. It's a safety net, not the main classifier. If you use an LLM to answer, also let the model return a "needs human" flag for anything outside its knowledge, an
3376252b4fc3e03533905d92bfe26a33b38a290d2d5108ba775391209c80b686Network indicators are visibly defanged. This page does not make them clickable or send them to another service.
No validated file hashes or network indicators are stored for this record.
This record contains metadata and attribution only. It does not host, download, unpack, render, or execute malware samples.
Sources represented on this page. Publication and observation dates describe the content; successful batch dates describe local collection. A recent batch does not certify complete coverage or current provider availability.
1 sources: 0 stale, 0 needing attention, 0 paused, 0 unverified.
Stale means older than twice the recorded collection interval, with a minimum of one hour; without an interval, the threshold is 24 hours. Cached content remains available while a feed is stale, paused, or unverified.