mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-05-18 20:08:19 +00:00
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>
This commit is contained in:
@@ -48,7 +48,8 @@ export class MessagingService {
|
|||||||
|
|
||||||
async handleInbound(message: NormalizedMessage): Promise<void> {
|
async handleInbound(message: NormalizedMessage): Promise<void> {
|
||||||
const { phone, name, text } = message;
|
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) {
|
if (!this.aiModel) {
|
||||||
await this.provider.sendText(phone, 'Our assistant is temporarily unavailable. Please call us directly.');
|
await this.provider.sendText(phone, 'Our assistant is temporarily unavailable. Please call us directly.');
|
||||||
@@ -126,14 +127,14 @@ export class MessagingService {
|
|||||||
- Checking existing appointments
|
- Checking existing appointments
|
||||||
|
|
||||||
APPOINTMENT BOOKING FLOW — follow this exact sequence:
|
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.
|
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, IMMEDIATELY call send_doctor_list with that department. Do NOT ask "which doctor" 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, IMMEDIATELY call send_slot_list with that doctor. Do NOT ask "which time" in text.
|
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, call send_confirm_buttons with a summary of the appointment.
|
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 confirms, call book_appointment.
|
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.
|
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:
|
OTHER RULES:
|
||||||
- Be concise — WhatsApp messages should be short (2-3 sentences max).
|
- Be concise — WhatsApp messages should be short (2-3 sentences max).
|
||||||
|
|||||||
Reference in New Issue
Block a user