Skip to content

Communications

WhatsApp (Meta Cloud API), Instagram and Messenger DMs, OTP SMS, email, push, appointment reminders, templates, and the staff inbox.

7 min read

Overview

The communications module handles outbound messages from the salon to clients (booking confirmations, reminders, journey and campaign messages, feedback requests) and the staff inbox where inbound chats land. WhatsApp is the main channel. SMS is used only for one-time codes. Email is used for transactional mail.

Kagami unified salon communications inbox with two-way WhatsApp messaging, SMS delivery logs, and chat threads

Consent: opt-outs are honoured. A client who has refused marketing or transactional messages on a channel (or on "all") is skipped by journeys and campaigns, and a WhatsApp STOP reply records an opt-out. There is no opt-in gate: no consent row means the client is allowed. See Marketing for the details.

Channels and Providers

Channel What sends it Used for
WhatsApp Meta WhatsApp Cloud API, called directly (Graph API v25.0). No BSP in between Confirmations, reminders, journeys, campaigns, feedback links, staff alerts, AI receptionist replies, inbox replies
Instagram and Messenger DMs Meta Graph API with the brand's Page token Inbound DMs reach the same inbox; staff and the AI reply inside Meta's 24 hour window
SMS Self-hosted android-sms-gateway, then TextBee, then httpSMS (first one configured that succeeds) One-time codes only (client portal, password reset). Not used for reminders or campaigns
Email Resend (RESEND_API_KEY, EMAIL_FROM) Booking confirmation, invoice receipt, reminder email, OTP codes, staff invitations, shift swaps, referral mail, alert emails, digests
Push Firebase Cloud Messaging (native Android apps) and Web Push (VAPID) New inbound message and staff alerts

When a brand has no WhatsApp credentials, the sender falls back to a stub provider that does nothing, so unconfigured environments never error.

OTP delivery order: each configured SMS provider in turn, then WhatsApp as a last resort. In the client portal the user can pick SMS or WhatsApp explicitly, and then there is no cross-channel fallback. WhatsApp codes use the approved otp_verification authentication template, because free-form text is not delivered outside the 24 hour window. See Integrations for setup.

Connecting WhatsApp

Each brand connects its own WhatsApp Business number in Settings -> WhatsApp & AI -> Message settings:

  1. Embedded Signup (Meta popup) or connect an existing number (WABA id, phone number id, access token, two-step PIN).
  2. Kagami exchanges the code for a token, registers the phone number with the Cloud API (a number stays PENDING and cannot send until registered), and subscribes the app to the WABA.
  3. The standard template set is submitted to Meta automatically.
  4. Token and phone-number health checks are available from the same page.

Credentials are stored per brand in messaging_settings. The access token is never sent to the browser.

Per-brand switches in messaging_settings: WhatsApp on/off, and separate toggles for confirmations, reminders, cancellations, reschedules and referral notifications, plus the template name used for each. A location can also switch WhatsApp off (location_messaging_settings); an absent row means on.

Inbound Webhooks

Endpoint Source Handles
/api/webhooks/whatsapp WhatsApp Cloud API Inbound messages, delivery status, template status updates
/api/webhooks/meta Instagram and Messenger Inbound DMs

Both verify the X-Hub-Signature-256 HMAC with META_APP_SECRET and reject (403) when the secret is missing. GET verification uses WHATSAPP_WEBHOOK_VERIFY_TOKEN and META_WEBHOOK_VERIFY_TOKEN. Each unit of work in a delivery is isolated, and the handler acknowledges with 200 so Meta does not retry forever.

Delivery status updates write to outbound_messages (sent, delivered, read, failed, with timestamps). Template status updates (APPROVED, REJECTED, PENDING, PAUSED, DISABLED, IN_APPEAL) write to whatsapp_templates, including the rejection reason.

Appointment Confirmations

Sent right after a booking is created online or at the desk, when the brand has WhatsApp and confirmations enabled.

  • Template variables: client name, service, time (IST) and location name.
  • One confirmation per appointment (idempotency key confirmation:<appointment id>).
  • A walk-in whose start time has already passed gets no confirmation. The row is recorded as skipped with the reason.
  • Cancellations and reschedules use their own templates (send_cancellations, send_reschedules).

Appointment Reminders

The live sender is POST /api/cron/reminders, scheduled by pg_cron every 15 minutes. Per brand with reminders and WhatsApp enabled:

  1. Main pass at reminder_hours_before (default 24 hours) before the appointment.
  2. Fixed 1 hour pass, skipped when the brand's main window is already 1 hour.

Reminders go out on WhatsApp only. A client without a phone, a location with WhatsApp off, an appointment that already started, and a duplicate (idempotency key per window) are all skipped. The default template appointment_reminder takes two body values: client name and time. Failures are stored on the outbound_messages row (failed, with error_detail).

Known caveat: Settings -> Reminders also edits a separate legacy config (reminder_configs, with a channel field and email copy). Its sender (POST /api/reminders/process) was never scheduled and was removed in SALO-3036, so those settings do not drive live reminders.

Confirm or Release

When a brand turns on Confirm reminders (reminder_confirm_enabled), the main reminder asks the client to Confirm, Reschedule or Cancel:

  • Inside the 24 hour service window the buttons are sent as an interactive message.
  • Outside it, the brand's own Meta template with quick-reply buttons (reminder_confirm_template) is used. With no such template, the normal reminder is sent and the client is not asked.
  • Only clients who actually received buttons are marked confirmation_status = pending.
  • Auto-release is a per-location setting, off by default. POST /api/cron/reminders/auto-release (every 15 minutes) cancels still-pending appointments inside the location's cut-off (1 to 23 hours before start), frees the slot and alerts staff. The client is not messaged on release.
  • Every action is logged to appointment_confirmation_events.

Replies to reminder messages are not yet processed as Confirm, Reschedule or Cancel actions.

Message Templates

WhatsApp requires approved templates for business-initiated messages outside the 24 hour window. Two sources:

  1. Standard set (web/src/lib/messaging/templates.ts). Submitted to Meta automatically when a brand connects a number. Covers booking confirmation, appointment reminder, cancellation, reschedule, referral rewards, invoice receipt, feedback request and feedback link, pre-arrival add-on offer, staff invites and alerts, playbook task notices (English, Tamil, Hindi) and raffle messages.
  2. Custom templates built in Settings -> WhatsApp templates: name, category (Utility, Marketing, Authentication), language, header (none, text, image, video, document or carousel), body, and buttons (quick reply, URL, phone). Body text uses named variables such as {{client_name}}; on submit the builder converts them to Meta's positional {{1}}, {{2}} and sends sample values for review. Carousels take 2 to 10 cards.

Lifecycle: draft, submitted to Meta, then APPROVED, REJECTED (with reason), PAUSED or DISABLED. Status refreshes through the webhook or a manual refresh.

Named variables available in the builder: client_name, staff_name, service_name, appointment_date, appointment_time, location_name, location_address, salon_name, invite_link, portal_link, role_label, inviter_name, revenue, appointments_count, new_clients_count.

Staff Inbox

Inbox in the dashboard lists chats from WhatsApp, the web chat widget, Instagram and Messenger.

  • Chats are scoped to a store. Chats with no store are shown in an "unassigned" view; staff limited to some stores only see those plus unassigned chats.
  • Messages from known numbers are matched to the client record by phone.
  • Staff replies are plain text. WhatsApp and DM replies must fall inside the 24 hour window; outside it the reply is refused with a message saying so.
  • The AI receptionist answers by default. A staff reply, or Take over, pauses the AI on that thread; Resume AI hands it back. When the AI cannot answer it holds the reply and raises an alert, shown as held replies.
  • New inbound messages trigger push notifications to subscribed staff devices.

There is no per-staff conversation assignment.

Birthday Messages

The /api/cron/birthdays job runs daily and enrols clients whose birthday (IST) is today into the brand's birthday journey, which sends an approved Meta template. A separate legacy endpoint (/api/birthdays/process, with a days_before setting) was never scheduled and was removed in SALO-3036. See Marketing.

Client Communications Log

Client comms (client_communications) is a manual log. Staff record calls, emails, SMS, WhatsApp chats, in-person talks and other contacts against a client (channel, direction, subject, body, status, time). Automated sends are tracked separately in outbound_messages, and inbound chats in inbound_messages and the AI conversation tables.

Delivery Status

Status Meaning
pending Row claimed, send not finished
sent Meta accepted the message (this is acceptance, not delivery)
delivered / read Confirmed by Meta's status webhook
failed Send rejected, or Meta reported failure later; reason in error_detail
skipped Deliberately not sent (for example the appointment had already started)

A failed AI reply raises an alert, because Meta reports many failures after returning 200.

Key Data Entities

  • messaging_settings - per-brand WhatsApp credentials, template names and send toggles
  • location_messaging_settings - per-location WhatsApp switch
  • outbound_messages - every automated send, with idempotency key and delivery status
  • whatsapp_templates - template names, language and approval status per brand
  • client_communications - manual contact log
  • appointment_confirmation_events - confirm-or-release audit trail

Permissions

Settings pages for messaging, templates and reminders are for managers (org owner, brand manager, location manager). Creating or editing message templates is the marketing.message_templates action permission, and sending campaigns is marketing.campaigns; both default to managers and can be changed per role in Settings -> Roles & permissions. The inbox is open to front desk and above, scoped by store.