Manage automated escalation triggers, pause AI autonomy, and intervene with staff replies.
The escalation service (src/server/services/escalation.ts) continuously monitors conversation sentiment and intent. A thread is flagged for human review when:
1. Explicit Customer Request: The customer says *"I want to talk to a person"*, *"Transfer me to an agent"*, or similar phrases.
2. Negative Sentiment & Frustration: Sentiment analysis detects repeated anger, frustration, or dissatisfaction.
3. Out-of-Scope Complex Inquiries: The customer asks questions outside the Knowledge Base with low RAG confidence scores.
4. Emergency Flags: Phrases indicating medical or safety emergencies trigger immediate escalation notifications.
When triggered, an escalation_requests record is generated, and the conversation is marked with an Escalated badge in /escalations and /inbox.
Every thread in the unified inbox features an AI Autopilot toggle backed by the server action toggleThreadAiAutonomyAction:
- Active: The AI answers all customer messages automatically.
- Paused: The AI remains silent, allowing human staff to handle the dialogue without AI interruptions.
When staff sends a manual reply from /inbox:
1. The server action sendStaffReplyAction sends the message via the connected channel provider.
2. The thread's aiAutonomy is automatically set to "paused" to prevent race conditions where both human and AI respond.
3. The message is tagged with isAiGenerated: false and attributed to the staff member's ID.
Staff can append private internal notes to any conversation thread or appointment record. These notes: - Are visible only to authenticated team members in the dashboard. - Are strictly excluded from the customer-facing context window.