Commit Graph

10 Commits

Author SHA1 Message Date
963cf28d23 fix: link patientId to appointment in WhatsApp booking
Appointments created via WhatsApp had null patientId — lookup_appointments
couldn't find them. Now resolves patient before booking and includes
patientId in the createAppointment mutation. Fixed in both flow tool
registry and legacy messaging service.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 18:56:39 +05:30
2e0527e1d8 feat: config-driven flow runtime engine for WhatsApp conversations
Groups + Blocks execution model adapted from Typebot:
- FlowExecutionService: walks through groups/blocks, pauses at InputBlocks
- FlowSessionService: Redis-backed session state (24h TTL)
- FlowStoreService: loads flow definitions from data/flows/ JSON files
- FlowVariableService: {{variable}} interpolation + expressions
- ToolRegistry: registered tool handlers (departments, doctors, slots, booking)
- Default appointment-booking.json flow seeded on first run

MessagingService delegates to flow engine when published flows exist,
falls back to hardcoded AI chat otherwise (backward compatible).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 18:27:29 +05:30
6a3834a7eb feat(messaging): conflict check before booking appointment
Check for duplicate patient+doctor+date and max 3 slots per time before
creating the appointment. Returns actionable message if conflict found.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 15:46:27 +05:30
6847f5de95 fix(messaging): appointment field is 'status' not 'appointmentStatus'
Matched the working agent tool mutation — platform expects 'status'
for AppointmentCreateInput, not 'appointmentStatus'.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 15:44:56 +05:30
d857a0b270 fix(messaging): truncate WhatsApp list section titles to 24 char limit
WhatsApp list messages have strict limits: section title max 24 chars,
row title max 24 chars. Long doctor names + dates in section titles
caused Gupshup to silently drop the list options.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 15:37:30 +05:30
214cc60917 fix(messaging): teach AI to parse selection_id format for tool dispatch
AI wasn't calling send_slot_list after doctor selection because it didn't
know how to extract doctorId from "doc:{uuid}:{name}" format. Updated
system prompt with explicit selection_id parsing instructions for each
step of the booking flow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 15:31:20 +05:30
c4c437abd6 fix(messaging): parse postbackText from Gupshup list_reply, pass selection ID to AI
Gupshup list_reply has empty id field — postbackText carries our ID.
Fixed ?? to || fallback. Also inject selection_id into user message so
AI can extract doctorId from "doc:{uuid}:{name}" format.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 15:25:35 +05:30
b1922809d0 fix(messaging): generate hourly slots from visitSlots day-of-week data
Was reading non-existent availableSlots field. Now reads raw visitSlots,
matches target date's day-of-week, and generates hourly time slots from
startTime to endTime. Doctors with 08:00-20:00 get 10 hourly options.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 15:19:09 +05:30
8aae95e8cc fix(messaging): directive prompt — force interactive lists, add hospital name
AI was asking "which department?" in text instead of sending the
interactive list. Updated system prompt to be prescriptive: IMMEDIATELY
call send_department_list, never ask in text. Also injects hospital name
from theme config.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 15:09:19 +05:30
2c947517af feat: WhatsApp AI assistant — provider-agnostic messaging with Gupshup
Provider-agnostic WhatsApp integration for AI-driven appointment booking:

- MessagingProvider interface (sendText, sendButtons, sendList, parseInbound)
- GupshupProvider implementation (Gupshup WhatsApp API)
- MessagingService — AI orchestration with tools (department/doctor/slot
  lists via interactive WhatsApp messages, appointment booking, caller
  resolution + context injection)
- Redis conversation history (24h TTL, matches WhatsApp session window)
- Webhook controller at POST /api/messaging/webhook

Swappable to Ozonetel or Meta Cloud API by implementing MessagingProvider
and switching MESSAGING_PROVIDER env var.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 14:45:26 +05:30