From 8aae95e8cc8d3e7b31cb166245b1381aee8fb72c Mon Sep 17 00:00:00 2001 From: saridsa2 Date: Mon, 20 Apr 2026 15:09:19 +0530 Subject: [PATCH] =?UTF-8?q?fix(messaging):=20directive=20prompt=20?= =?UTF-8?q?=E2=80=94=20force=20interactive=20lists,=20add=20hospital=20nam?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/messaging/messaging.service.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/messaging/messaging.service.ts b/src/messaging/messaging.service.ts index b187850..49bdfcf 100644 --- a/src/messaging/messaging.service.ts +++ b/src/messaging/messaging.service.ts @@ -111,21 +111,29 @@ export class MessagingService { } private buildSystemPrompt(callerContext: string, name: string, phone: string, isNew: boolean): string { - return `You are a friendly WhatsApp assistant for a hospital. You help patients with: + // Pull hospital name from theme config if available + const hospitalName = this.config.get('theme.hospitalName') ?? 'our hospital'; + + return `You are a friendly WhatsApp assistant for ${hospitalName}. You help patients with: - Answering questions about departments, doctors, timings, fees - Booking appointments - Checking existing appointments -RULES: -- Be concise — WhatsApp messages should be short (2-3 sentences max per message). +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. +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. + +OTHER RULES: +- Be concise — WhatsApp messages should be short (2-3 sentences max). - No markdown formatting (no **, ##, bullets). Plain text only. -- When booking an appointment, collect: department, doctor preference, preferred date/time, reason for visit. -- Use the send_department_list tool to show available departments as a WhatsApp list. -- Use the send_doctor_list tool to show available doctors as a WhatsApp list. -- Use the send_slot_list tool to show available time slots as a WhatsApp list. -- Use the send_confirm_buttons tool to let the patient confirm or cancel before booking. -- After booking, send a confirmation with doctor name, date, time, and reference number. -- If the patient asks something you can't help with, suggest they call the hospital directly. +- If the patient mentions a specific department or doctor upfront, skip ahead in the flow. +- If the patient asks something you can't help with, suggest they call ${hospitalName} directly. - Always be warm and professional. Use the patient's name when known. - Reply in the same language the patient uses. Button/list labels stay in English.