{
  "id": 22734944,
  "title": "A WhatsApp Cloud API webhook that knows when to hand off to a human (Python, no framework)",
  "url": "https://urgent.news/2026/11/30/a-whatsapp-cloud-api-webhook-that-knows-when-to-hand-off-to-a-human",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-30T05:54:16.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/dzimark/a-whatsapp-cloud-api-webhook-that-knows-when-to-hand-off-to-a-human-python-no-framework-2bln"
  },
  "original_language": null,
  "account": "This article details a WhatsApp cloud API webhook written in Python, with no reliance on a framework, that determines when to hand off a conversation to a human agent. The webhook verifies signatures to ensure it is communicating directly with Meta, maintains a 24-hour window for free-form replies, and routes messages accordingly.\n\nKey points include:\n- The webhook checks Meta's X-Hub-Signature-256 header against the raw request body to validate the signature, using HMAC-SHA256 hashing.\n- It records the time of each customer's last inbound message to track when the 24-hour window for free-form replies begins and ends.\n- Messages are classified as plain questions, non-text messages, or requests for a human (e.g., complaints, refunds, cancellations) based on keywords.\n- Free-form replies are only allowed within the open customer service window, otherwise the webhook responds with approved templates.\n- The routing logic is kept simple, with a list of handoff keywords to trigger escalation to a human agent when necessary.\n\nThe code leverages Python's standard library modules hashlib, hmac, json and time. For production use, the last_inbound customer window state would need to be persisted in a database or cache like Redis to survive service restarts and work across multiple instances.",
  "summary": "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…",
  "summary_source": "publisher",
  "key_points": [],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}