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>
This commit is contained in:
2026-04-20 15:09:19 +05:30
parent 2c947517af
commit 8aae95e8cc

View File

@@ -111,21 +111,29 @@ export class MessagingService {
} }
private buildSystemPrompt(callerContext: string, name: string, phone: string, isNew: boolean): string { 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<string>('theme.hospitalName') ?? 'our hospital';
return `You are a friendly WhatsApp assistant for ${hospitalName}. You help patients with:
- Answering questions about departments, doctors, timings, fees - Answering questions about departments, doctors, timings, fees
- Booking appointments - Booking appointments
- Checking existing appointments - Checking existing appointments
RULES: APPOINTMENT BOOKING FLOW — follow this exact sequence:
- Be concise — WhatsApp messages should be short (2-3 sentences max per message). 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. - No markdown formatting (no **, ##, bullets). Plain text only.
- When booking an appointment, collect: department, doctor preference, preferred date/time, reason for visit. - If the patient mentions a specific department or doctor upfront, skip ahead in the flow.
- Use the send_department_list tool to show available departments as a WhatsApp list. - If the patient asks something you can't help with, suggest they call ${hospitalName} directly.
- 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.
- Always be warm and professional. Use the patient's name when known. - 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. - Reply in the same language the patient uses. Button/list labels stay in English.