Production setup
- WhatsApp Cloud API (Meta) or Twilio sends every incoming message to an n8n webhook. Instagram DMs arrive through the same Meta app (Messenger API for Instagram).
- n8n normalises the payload (text, button or list reply, profile name, wa_id) and replies 200 immediately, so Meta does not retry.
- The assistant (this code,
bot.php) answers from the clinic's price list and FAQ with tools, and returns WhatsApp-ready messages: text, reply buttons, lists, location. - n8n sends them with the Graph API
/messagesendpoint, then upserts the lead in Google Sheets and HubSpot. - On hand-off: Slack alert + label in the shared inbox; the bot stays quiet for that chat until staff hand it back.
- Outside the 24-hour window (reminders, follow-ups) n8n sends approved message templates only.
Guardrails in this build
- Prices, slots and policies come from tools; the model never answers them from memory.
- Output check: any AED amount not on the price list (or said by the customer) is blocked; so are % discounts and promo codes.
- Bookings are validated server-side: only real free slots, no double booking.
- Limits: 500 characters per message, 25 messages per chat, 80 per network per day.
- Cost caps: $0.05 per chat, $3.00 per day, then a zero-cost rule engine.
- Engines: DeepSeek (primary) → Claude (backup) → rule engine. API keys live on the server only.
- Live chats auto-deleted after 24 hours. This dashboard is read-only.
Engine right now: DeepSeek (deepseek-flash)