diff --git a/src/messaging/messaging.service.ts b/src/messaging/messaging.service.ts index 9904640..2e68e0e 100644 --- a/src/messaging/messaging.service.ts +++ b/src/messaging/messaging.service.ts @@ -48,7 +48,8 @@ export class MessagingService { async handleInbound(message: NormalizedMessage): Promise { const { phone, name, text } = message; - this.logger.log(`[WA] Inbound from ${phone} (${name}): ${text.substring(0, 100)}`); + const replyId = message.interactiveReply?.id; + this.logger.log(`[WA] Inbound from ${phone} (${name}): ${text.substring(0, 100)}${replyId ? ` [reply_id=${replyId}]` : ''}`); if (!this.aiModel) { await this.provider.sendText(phone, 'Our assistant is temporarily unavailable. Please call us directly.'); @@ -126,14 +127,14 @@ export class MessagingService { - Checking existing appointments APPOINTMENT BOOKING FLOW — follow this exact sequence: -1. When the patient wants to book, IMMEDIATELY call send_department_list. Do NOT ask "which department" in text — send the interactive list directly. -2. When the patient picks a department, IMMEDIATELY call send_doctor_list with that department. Do NOT ask "which doctor" in text. -3. When the patient picks a doctor, IMMEDIATELY call send_slot_list with that doctor. Do NOT ask "which time" in text. -4. When the patient picks a slot, call send_confirm_buttons with a summary of the appointment. -5. When the patient confirms, call book_appointment. +1. When the patient wants to book, IMMEDIATELY call send_department_list. Do NOT ask "which department" in text. +2. When the patient picks a department (selection_id starts with "dept:"), IMMEDIATELY call send_doctor_list with the department name after "dept:". +3. When the patient picks a doctor (selection_id starts with "doc:"), IMMEDIATELY call send_slot_list. Extract the doctorId from the selection_id format "doc:{doctorId}:{doctorName}" — use the UUID between the first and second colon as doctorId, and the text after the second colon as doctorName. +4. When the patient picks a slot (selection_id starts with "slot:"), call send_confirm_buttons with a summary. Extract the datetime from "slot:{doctorId}:{datetime}". +5. When the patient taps Confirm (selection_id = "confirm_booking"), call book_appointment with all collected details. 6. After booking, send a confirmation with doctor name, date, time, and reference number. -CRITICAL: Always use the interactive list/button tools instead of asking questions in text. The patient should tap to select, not type answers. +CRITICAL: Always use the interactive list/button tools. Never ask questions in text when a tool exists. When a user message contains "selection_id:", parse it and call the appropriate tool immediately. OTHER RULES: - Be concise — WhatsApp messages should be short (2-3 sentences max).