Zero Labs
Industry News / AI

WhatsApp Business API Conversation Design: Building LLM Assistants Around the 24-Hour Window and…

Source · Towards AI By Hernan M

From the publisher’s feed, collected in the ZeroLabs newsroom.

WhatsApp Business API Conversation Design: Building LLM Assistants Around the 24-Hour Window and Message TemplatesThe flow you end up designing for: user message → 24-hour session → expiry → template-only reactivation → user reply reopens.The first time my WhatsApp bot hit the wall (and why it’s not a “bug”)Last month I noticed a support bot I’d built was “perfect” in staging and weirdly broken in production.Day one looked great. Users asked questions, the LLM answered, and my logs were clean.Then a customer came back the next afternoon — more than 24 hours later — and replied “Any update?” to an old thread.My backend did what any normal chat backend does: it loaded the conversation, generated a helpful response, and tried to send it.Meta rejected it.At first I treated it like an integration glitch. Wrong token? Wrong endpoint? A transient outage?But the rub was simpler: WhatsApp isn’t a neutral chat pipe. It’s a consent-shaped channel with a hard session boundary, and my “chatbot” was accidentally trying to behave like email.Once I internalised that, the design work started to look less like prompt tuning and more like building around an auth timeout.Async reality check: validate the window at send-time, not plan-time, or you’ll cross the line mid-queue.The 24-hour session window: time becomes part of your conversation stateOn the WhatsApp Business Platform, you can reply to a user message without a template as long as it’s within 24 hours of the last user message. Outside that 24-hour customer service window, you may only send messages via approved Message Templates (per WhatsApp’s Business Messaging Policy).Inside that window, you can send normal free-form messages. Outside it, you can’t send free-form outbound at all; you must use a template to re-engage.So for LLM systems, “time since last user message” isn’t metadata. It’s a routing key.Implementation detail I wish I’d done earlier: track window_expires_at, not a booleanI’m seeing this now across async pipelines: a boolean like is_in_window=true is a trap.Booleans go stale. Timestamps don’t.The pattern that holds up in production is storing window_expires_at as an absolute datetime, resetting it on every inbound message, and validating at the moment of send to avoid race conditions (a point Syed Amaan also calls out when describing multi-tenant WhatsApp backends).That last part matters more than it sounds.Imagine your worker starts an LLM call with 10 seconds left in the window. The model returns in 6 seconds. Your queue is backed up. The actual send happens 8 seconds later.You just crossed the line.If you checked “in window” when you enqueued the job, you’ll send a free-form message out-of-window and get rejected downstream (or worse, accepted by an intermediary and rejected later, which is harder to reason about). Validating right before send is the only version that matches reality.This is already happening in any system with retries, worker pools, or “typing…” delays. Pay attention to this next bit: treat the expiry timestamp as authoritative state, and check it at send-time, not at plan-time.The headscratcher in production: you can start in-window and still end up out-of-window by the time the API call fires.Message Templates: categories, approvals, and why LLMs make them awkwardOnce you’re outside the 24-hour window, templates aren’t “nice to have.” They’re the only compliant outbound mechanism on the WhatsApp Business Platform.WhatsApp’s policy is explicit: outside the 24-hour customer service window, you may only send messages via approved Message Templates. And WhatsApp/Meta can review, approve, pause, or reject templates.Template categories sound straightforward until you try to plug an LLM into them:Marketing templates cover promotional and engagement-oriented outreach; anything that doesn’t qualify as utility or authentication tends to land here.Utility templates are for updates tied to an existing user action or transaction (order updates, account alerts, appointment reminders) and are expected to stay factual/neutral.Authentication templates are for one-time passcodes and login/account verification flows, and they’re the most constrained.Rule-based bots handle this fine because they’re predictable. LLMs… aren’t.An LLM wants to “help” by adding a friendly upsell, a suggestion, a link, a little flourish. But templates are pre-approved, structured, and evaluated against intent. The more creative your model is, the more likely it is to drift outside what you got approved.And there’s a deeper mismatch: templates force you to decide your reactivation scenarios up front. That’s not how most LLM prototypes are built. Most prototypes assume you can always re-engage with a free-form “Hey, just checking in…”On WhatsApp, you can’t.Template categorization pitfalls: “mixed content” quietly becomes marketingIn practice, “mixed content” is where teams get burned: if you combine a transactional update with a promo, you’ve effectively created a marketing message. Third-party template-category guides hammer the same point — utility needs to stay single-purpose and non-promotional.For an LLM system, that means you can’t let the model casually append “By the way, want 10% off?” to a utility follow-up.The guardrail I’ve found workable is boring but effective: template selection is deterministic, and the LLM only fills variables.So instead of prompting the model with “write a reactivation message,” I prompt it with “choose one of these template IDs and provide values for {{1}}, {{2}}…” Then I validate those values (length, allowed characters) before sending.It’s not poetic. But it passes review, and it keeps your system from accidentally turning a utility workflow into marketing.Templates force you to decide scenarios up front — and keep the LLM on a leash (pick template deterministically, only fill variables).The real design problem: conversation continuity across session breaksThe hard part isn’t sending templates. It’s continuity.Users don’t behave like your test scripts. They disappear mid-checkout. They come back three days later with “hey” and nothing else. They reply to a template with a voice note that your pipeline transcribes badly (ask me how I know — actually don’t).So the design problem becomes: how do you resume an LLM conversation thread when (a) you may be forced into a template-first reactivation step, and (b) your context is stale?Mechanically, the rule is simple: after expiry, you can only send templates; if the customer responds, the session restarts and you can continue normally.That “if the customer responds” clause is the dagger. You’re designing for two states: out-of-window and possibly no-response.Over the last year, I’ve ended up with three architectural approaches, each with a different failure mode.Approach 1: Stateless restart (cheap, policy-safe, but forgetful)This is the simplest version: treat every out-of-window return as a new conversation.If the user comes back after 48 hours, you send a template like “Reply with what you need help with,” and once they respond, you start from scratch.It’s policy-safe because you’re not trying to be clever about old context. It’s also low quality, because the user has to repeat themselves.If you want a bit of structure, WhatsApp has “conversational components” like ice breakers and commands. Meta documents limits like up to 4 ice breakers and up to 30 commands, which can be useful for a stateless restart: “/order_status”, “/refund”, “/talk_to_agent”. Short. Deterministic.The catch is obvious: you’re throwing away continuity, which is often the whole reason you used an LLM in the first place.Approach 2: Summarized context injection (my default for support bots)In practice, what I’ve found is that a rolling summary gets you 70% of the UX with 30% of the complexity.The pattern looks like this:Store the full transcript in your database for audit/debug.Maintain a short “thread summary” that you update every N turns.On re-entry (especially after a long gap), inject only the summary + last known state into the prompt.Syed Amaan calls out context-window optimisation as a real production concern in WhatsApp systems, especially at scale. And n8n’s WhatsApp assistant workflow template treats memory as a first-class feature, using a vector store for longer-term recall.But here’s the honest limitation: summaries fossilize mistakes.If your summary says “User wants to cancel order #123,” and actually they changed their mind later, your model will confidently continue the wrong thread. It’s oddly satisfying when the model finally behaves… until it behaves confidently in the wrong direction.So I add a re-entry step: acknowledge the time gap and confirm intent.One line like: “Last time we discussed canceling order #123. Are you still trying to cancel it, or something else?” That tiny confirmation saves a lot of hallucinated continuity.This approach works until your user returns 6 days later and the context is completely cold — or their situation changed and your “helpful recap” becomes a liability.Approach 3: Persistent user profile + intent carry-over (powerful, but easy to overbuild)The most complex approach is separating memory into two buckets:Profile memory: stable facts and preferences (name, language, preferred store, “don’t call me,” etc.).Task state: active intents and workflows (open ticket ID, cart ID, appointment draft, last question asked).Then, when the user returns, you load only what’s relevant: the last open intent, key entities, and the next required user action.This is the architecture that starts to feel like a real system, not a chat demo.It also gets complicated fast.You need migrations when business rules change. You need explicit expiry for task state (“cart abandoned after 72 hours”). You need a human handoff path that can read the same state. And you need to be disciplined about what the LLM is allowed to mutate.WhatsApp’s policy framing (opt-in, opt-out, and quality enforcement) tends to push you toward a more CRM-like model anyway, because you can’t rely on “we’ll just ping them later” as a safety net.My caveat: this approach is great until it isn’t. If the user returns weeks later, you must re-confirm, because “intent carry-over” becomes guesswork.Fallback logic when the window expires mid-flow (checkout, tickets, human handoff)The nastiest bugs I’ve seen aren’t model bugs. They’re timing bugs.A user starts a checkout flow at 4pm. You ask for an address. They go silent. At 4:05pm the next day, your system tries to follow up with “Still need your address?” and gets blocked because the session expired.So the fallback design goal is: every flow step should be able to end in a safe “pause” state.I design for three outcomes:The user replies in time and we continue normally.The user doesn’t reply, the window expires, and we send a template that asks for a minimal response to reopen.The user never responds, and we stop — because WhatsApp is not a channel where you can nag indefinitely without consent.That third case is the one product teams hate. But it’s real.A practical pattern: “checkpoint + resume token”The most reliable pattern I’ve used is checkpointing.When you ask a question that might stall (“What’s your shipping address?”), persist a server-side checkpoint: cart_id, ticket_id, last_question_asked, and a next_expected_fields list.Then, if the window expires, you send a template that contains a minimal “resume” instruction — often a button or a short reply prompt like “Reply RESUME to continue.”Once the user replies, you reopen the session and continue deterministically from the checkpoint, not from the LLM’s memory of what it thinks happened.This keeps the LLM in its lane. It also makes human handoff easier, because an agent can see the checkpoint and pick up without reading 80 messages.Because templates are the only out-of-window mechanism, you have to encode those resume points as approved templates ahead of time. And yes, it’s a bit of a mess the first time you map all your “resume points.”But once you do, your system stops falling off cliffs.How tools handle it in practice: Twilio vs Botpress vs WATI (and what they don’t solve)Tooling changes how much pain you feel, but it doesn’t remove the constraints.Twilio gives you raw access to WhatsApp messaging with docs around opt-in requirements and the mechanics of sending/receiving messages; you get full control, and you own the session/template logic end-to-end. That’s great if you want to build the “timestamp at send-time” checks and your own state machine.Botpress (flow-based orchestration) does one thing genuinely well here: its explicit node/state model makes session boundaries and routing decisions visible and auditable, which is a nice antidote to “mystery meat” prompt-and-pray pipelines. You still have to model the 24-hour boundary as a real state transition, but at least you can point at it in a diagram and test it.WATI is more explicit about the constraint: they flat-out say the 24-hour expiry is a WhatsApp API rule and they can’t extend it. For teams that need guardrails and template management UI, that clarity is valuable.Some platforms abstract this entirely for non-technical teams. Atiendia, for instance, handles session logic and template management out of the box for SMBs in LATAM.Even with the nicest UI, though, the sharp edges remain: bad template strategy, unclear state machines, and sloppy memory design still produce confusing conversations.What this means for prompt engineers: treat the session boundary as a first-class prompt variableIf you’re designing prompts for WhatsApp, the session boundary can’t be an afterthought.I now treat in_window vs out_of_window as a top-level variable in the system prompt, right next to “tools available” and “brand voice.”When in_window=true, the model can respond normally—ask questions, clarify, proceed.When out_of_window=true, the model should not output free-form user-facing text. It should propose:a template ID (from an allowed set), aligned to the correct category rulesthe minimal variables to filla “what happens next” plan that assumes the user might not respond (because they often won’t)And when the user does respond and the window reopens, I use a “resume prompt” format: short recap, current checkpoint, one clarifying question, and an explicit acknowledgement of the time gap.Core takeaway: the 24-hour boundary has to be modeled as explicit system state — store window_expires_at, validate at send-time, and treat out-of-window outbound as template-only reactivation—not as an edge case you patch with prompt tweaks.SourcesWhatsApp Business Messaging Policy (24-hour window, templates, opt-in/opt-out)Freshdesk Omni: Create and Use WhatsApp Message Templates (workflow, limits, approval timing)eGrow: Utility vs Marketing template category guidance (mixed content pitfalls)Twilio: WhatsApp Business Platform API overviewSyed Amaan: Building Multi-Tenant WhatsApp AI (send-time window validation, production patterns)WATI: 24-hour session expiry explanationB2Chat: Managing session times for WhatsApp chatsMeta for Developers: Template categorizationMeta for Developers: Conversational Components (ice breakers, commands)n8n: WhatsApp assistant workflow with memory (vector store pattern)WhatsApp Business API Conversation Design: Building LLM Assistants Around the 24-Hour Window and… was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.