Attach automatic WhatsApp / SMS / email messages, and follow-up tasks, to a specific Service or Product. Configured once on the catalog row, fires every time that Service is delivered or that Product is sold. Empty toggle means nothing is sent. Setup-incomplete means the toggle is blocked until messaging is connected. The clinic does not need to remember anything once it is configured.

How the AI gets at catalog and availability data. Each inbound to the AI carries an ai_context payload with relevant catalog, booking, and patient information. The AI workflow is responsible for picking, quoting, and committing. Hoopoe today does not run a deterministic "if patient asked about service X, send price Y" handler, that logic lives in the workflow. The handler-based variant is on the roadmap.

Where it lives#

  • Catalog → Services → [open one] → Automation: per-Service toggles (after-care, rebooking, review request, marketing follow-up with offer, smart upsell, auto task).
  • Catalog → Products → [open one] → Automation: per-Product toggles (post-purchase thank-you, refill reminder, review request, marketing follow-up with offer, smart cross-sell, auto task).
  • Settings → Integrations: connect WhatsApp / SMS / email senders. Until at least one provider is configured as default, the toggles above are disabled.
  • Settings → Message templates: where the templates referenced by the toggles live. Only APPROVED templates are sendable.
  • Settings → Messaging defaults: tenant-level channel order, quiet hours, 24h window enforcement.
  • Settings → Notifications log: ops view of what fired and why something was skipped.

The big picture, in one paragraph#

Operator turns on Refill reminder on a shampoo (60 days, template refill_reminder_v1). Sixty days after any patient buys it, the dispatcher composes a WhatsApp template message, picks the clinic's default WhatsApp sender, enforces opt-out, quiet hours, frequency cap, the 24h window rule, and the template-status freshness check, then sends. The clinic never had to remember to follow up.

The full automation catalogue#

On Services#

  • After-care, trigger: session marked Done. Delay: immediate. Channel: WhatsApp. Template required. Respects the 24h window.
  • Rebooking nudge, trigger: scheduler.daily.rebooking_check, run daily by Celery beat. Delay: configurable (days from sales / last completed visit / last scheduled visit). Channel: WhatsApp. Template required (utility category).
  • Review request, trigger: session Done + delay (default 1 day). Channel: WhatsApp. Template required.
  • Marketing follow-up with offer, trigger: session Done + delay (days / weeks / months). Channel: WhatsApp. Template required (marketing category, capped at 2 per recipient per 24h by Meta). Optional offer payload: discount_code or cross_sell.
  • Smart upsell at booking, trigger: booking creation. Channel: in-app booking screen.
  • Auto task, trigger: session Done + delay (days). Channel: internal Task. Assigned to the configured staff member.

On Products#

  • Post-purchase thank-you, trigger: sales.invoice.confirmed.v2. Delay: immediate. Channel: WhatsApp. Template required.
  • Refill reminder, trigger: scheduler.daily.refill_reminder_check. Delay: configurable (default 30 days). Channel: WhatsApp. Template required (utility).
  • Review request, trigger: invoice confirmed + delay (default 7 days). Channel: WhatsApp. Template required.
  • Marketing follow-up with offer, trigger: invoice confirmed + delay (days / weeks / months). Channel: WhatsApp. Template required (marketing). Optional offer payload.
  • Smart cross-sell, trigger: post-purchase template renders cross_sell_product_ids as related items.
  • Auto task, trigger: invoice confirmed + delay. Channel: internal Task.

Empty toggle and empty template_key both mean nothing will be sent. There is no fallback that quietly sends some default, the absence of configuration is a deliberate choice the system honours. The CatalogPolicyGuard in the messaging dispatcher enforces this server-side.

Required tenant setup, do these in order before turning any toggle on#

  1. Connect WhatsApp WABA in Settings → Integrations → WhatsApp. The status badge must read Verified. Until this step is done, all WhatsApp toggles in the catalog are disabled and a warning Alert is shown.
  2. Optionally connect SMS and email providers if you plan to fan out to those channels.
  3. Mark one row per channel as Default in Settings → Integrations. The dispatcher refuses to send when no default exists.
  4. Set default channel order in Settings → Messaging defaults. UAE clinics typically: WhatsApp → SMS → email. Iran clinics typically: SMS → WhatsApp → email.
  5. Set quiet hours in Settings → Messaging defaults. Use the hours shown in your tenant settings. The provider guard blocks marketing during those hours; transactional sends pass unless block_transactional is enabled. A block does not by itself guarantee that every caller will queue and retry later.
  6. Pick a 24h window strictness: advisory (default, warn) or strict (block free-text outside the window). New clinics should run advisory for two weeks and then move to strict.
  7. Sync Meta templates: Settings → Message templates → Sync from Meta. At least one APPROVED template must exist per intent kind you plan to enable. PAUSED or REJECTED templates are skipped.
  8. If a marketing follow-up uses a discount code: create the code in Settings → Promo codes before referencing it in marketing_followup_offer.code.

What the system applies automatically, you do not need to ask for any of this#

  • Empty toggle = no message + no task. Enforced by CatalogPolicyGuard in the dispatcher.
  • Opt-out list honoured per (customer, channel, category). Marketing categories always honour opt-out; transactional only when the row says so.
  • Meta's marketing cap: at most 2 marketing templates per recipient per 24h, across all senders. Breach returns error 131049 and the dispatcher records it.
  • Quiet hours honoured by tenant config. The provider guard blocks marketing inside the window and blocks transactional sends when block_transactional is True. Retry or deferral depends on the caller.
  • 24h customer-service window: outside the window, only template messages are allowed. Strict mode blocks free text. Advisory warns and lets it through, recording window_warning on the NotificationRecord.
  • Template freshness: an hourly Celery beat resyncs status from Meta. A template that flips to PAUSED is auto-skipped on next send (skipped:template_unavailable).
  • Sender resolution order: per-rule sender_account override → tenant default → no-send (records no_provider_configured).
  • Demo tenants: outbound suppressed regardless of toggles unless the number is in DEMO_NOTIFICATION_WHITELIST.
  • Locked records: a Service that already has paid invoices keeps its automation settings but the form locks; remove the lock first to edit.

Important workflows, walk these end-to-end#

WF-1, first-time tenant onboarding#

  1. Clinic admin: complete the 8 setup steps above end-to-end.
  2. Acceptance: open any Service → Automation. The toggles are enabled and a green readiness chip appears next to the channel.

WF-2, service operator turns on After-care + Review request on "Botox forehead"#

  1. Catalog → Services → Botox forehead → Automation.
  2. Switch After-care ON. Pick template botox_aftercare_v2. Save.
  3. Switch Review request ON. Delay 24 hours. Pick template review_request_v1. Save.
  4. Acceptance: when a Botox session is marked Done, the after-care WhatsApp lands within 5 minutes. 24 hours later the review request lands. Patient opt-out and quiet hours are honoured.

WF-3, pharmacy operator sets up Refill reminder on "Minoxidil 5% solution"#

  1. Catalog → Products → Minoxidil 5% solution → Automation.
  2. Switch Refill reminder ON. Delay 60 days. Pick template refill_reminder_v1. Save.
  3. Acceptance: when the product is sold and the invoice is confirmed, a delayed Celery job is scheduled. On day 60 the WhatsApp lands from the clinic's default WhatsApp sender. Patient opt-out is honoured.

WF-4, marketing follow-up with offer, "Botox re-touch in 1 month, 10% off"#

  1. Catalog → Services → Botox forehead → Automation.
  2. Switch Marketing follow-up ON. Delay 1 month. Pick template botox_retouch_offer_v1. Set offer kind discount_code, code BOTOX10, percentage 10. Save.
  3. Acceptance: 1 month after the session, the template renders the {{offer.code}} variable as BOTOX10. Redemption is tracked when the patient places an order with the code.

WF-5, operator picks a typo'd template key#

  1. The picker rejects unapproved or non-existent keys, so this rarely happens by hand.
  2. If an automation references a removed template (e.g. it was deleted from Meta), the dispatcher records skipped:template_unavailable and surfaces a warning chip in Settings → Automations → Health.
  3. Operator fixes the template_key in the catalog row and the next send succeeds.

Scenarios worth knowing#

  • S-1. Patient inside the 24h conversation window → free text allowed even when no template is set.
  • S-2. Patient outside the window → only template messages send. Free text is warned (advisory) or blocked (strict).
  • S-3. Patient opted out of marketing → marketing follow-up skipped; utility templates (refill, after-care, review) still send.
  • S-4. Tenant exceeds Meta's marketing cap (2 per recipient per 24h across all senders) → next marketing intent rejected with code 131049, visible in Settings → Notifications log.
  • S-5. Template status flips to PAUSED in Meta during the day → next send within the hour returns skipped:template_unavailable. Hourly sync auto-disables the row.
  • S-6. Tenant runs two WhatsApp numbers (Reception vs Treatment) → per-action sender_account override routes the right rule to the right number.
  • S-7. Service has is_locked=True (paid invoices exist) → automation toggles are editable but the form locks the rest of the row; clear the lock first to edit other fields.
  • S-8. Empty template_key on Refill → no message sent, no error logged. Documented behaviour.
  • S-9. Demo tenant → all outbound suppressed regardless of toggles unless the number is in DEMO_NOTIFICATION_WHITELIST.
  • S-10. Tenant migrates from "everything off" to a configured catalog → tenant admin can preview the next 30 days of scheduled messages in Settings → Notifications → Upcoming.

Glossary#

  • WABA, WhatsApp Business Account, the Meta-side container for your numbers and templates.
  • BSP, Business Solution Provider, the platform routing messages to WABA (Meta Cloud API directly, 360dialog, Twilio).
  • 24h customer-service window, opened by an inbound patient message, closes when 24h pass with no inbound. Free text allowed inside; template only outside.
  • Utility / Marketing / Authentication, Meta template categories with different cost and consent rules.
  • Opt-out, patient suppression list. Marketing always honours; transactional honours only when configured.
  • Quiet hours, tenant-configured do-not-disturb window; marketing always blocked, transactional conditionally.
  • Frequency cap, Meta cap of 2 marketing templates per recipient per 24h across all senders.
  • Dispatcher, the single chokepoint NotificationDispatcher.send() that runs guards and routes to the resolved provider.
  • Intent, a neutral, provider-agnostic outbound message description.
  • Guard, a pre-send check (opt-out, quiet hours, frequency cap, catalog policy, 24h window).

Troubleshooting: "I turned it on but nothing fires"#

  • Is the template APPROVED in Meta? Sync from Meta and check status.
  • Is the channel ready? Settings → Integrations should show a Verified badge.
  • Is the patient on the opt-out list?
  • Did the send hit quiet hours? Look at skipped:quiet_hours in Settings → Notifications log.
  • Did it hit the frequency cap? Look at skipped:frequency_cap in the log.
  • Free text outside the window in strict mode? The send is blocked.
  • Is the feature flag MESSAGING_ENFORCE_CATALOG_POLICY enabled for this tenant? Until flipped, the guard does not enforce.