Please update app/lia_ure.py with the following focused changes: 1) Improve detect_appointment_confirmation so it also picks up messages like: - "Maybe Tuesday afternoon if that works?" - "Saturday morning is fine" - "Tomorrow afternoon" - "Ok can I book Saturday at 10:30?" Implement it like this (you can reuse or adapt my existing function): - At the top of the file, import re and define: DAY_WORDS = ["monday","tuesday","wednesday","thursday","friday","saturday","sunday"] TIME_OF_DAY = ["morning","afternoon","evening"] RELATIVE_WORDS = ["tomorrow","this weekend","this week","next week","later today"] TIME_REGEXES = [ re.compile(r"\b([01]?\d|2[0-3]):[0-5]\d\b"), # 14:30, 9:05 re.compile(r"\b([1-9]|1[0-2])\s?(am|pm)\b"), # 9am, 10 pm ] - Then implement: def detect_appointment_confirmation(body_lower: str) -> bool: # day + time-of-day (e.g. "tuesday afternoon") if any(d in body_lower for d in DAY_WORDS) and any(t in body_lower for t in TIME_OF_DAY): return True # relative terms + time-of-day (e.g. "tomorrow morning") if any(word in body_lower for word in RELATIVE_WORDS) and any(t in body_lower for t in TIME_OF_DAY): return True # day + " at " pattern (e.g. "saturday at 10:30") if " at " in body_lower and any(d in body_lower for d in DAY_WORDS): return True # explicit time patterns for pattern in TIME_REGEXES: if pattern.search(body_lower): return True return False 2) Add an EARLY RETURN in generate_lia_reply when an appointment is detected, BEFORE any other handlers run. - After normalising the inbound text and checking opted_out, add: if detect_appointment_confirmation(body_lower): raw_name = customer_state.get("customer_name") name = raw_name if raw_name else "there" reply = ( f"Perfect, {name} – I’ve made a note of that.\n\n" "If anything changes before then, just drop me a quick message here." ) customer_state["appointment_status"] = "BOOKED" customer_state["appointment_confirmed_text"] = inbound_text customer_state["appointment_confirmed_at"] = datetime.now(timezone.utc).isoformat() customer_state["last_message"] = inbound_text customer_state["last_reply_type"] = "APPOINTMENT_CONFIRMED" return reply, customer_state - Make sure datetime and timezone are imported at the top: from datetime import datetime, timezone 3) Replace the “Unknown” fallback with a softer “there”: - Wherever we build the customer name, use: raw_name = customer_state.get("customer_name") name = raw_name if raw_name else "there" - Then use `name` in the reply templates (e.g. "Hi there" instead of "Hi Unknown"). 4) After making these changes, run `python -m app.lia_ure` to ensure the module still runs its test block without errors. Only change what’s needed for these behaviours; keep the rest of the Universal Reply Engine logic as it is.