Phase 14 — AI Operational Layer / Orchestration
Automation rules engine, visual workflow builder, intent routing, failover system, AI action logging, and a human escalation queue — making KaiVox a self-operating AI platform.
What It Does
Phase 14 adds an automation layer that reacts to events across the platform. When a missed call comes in, an automation rule can automatically send a follow-up SMS. When a call has negative sentiment, the owner gets notified. When a customer's lead stage changes, a WhatsApp message goes out. All configured visually without code.
Key Routes
| URL | Description |
|---|---|
GET /automations | Automation rules list |
GET /automations/create | Visual workflow builder — step 1: choose trigger |
POST /automations | Save new automation rule |
GET /automations/{id}/edit | Edit automation rule |
POST /automations/{id}/toggle | Enable/disable rule |
DELETE /automations/{id} | Delete rule |
GET /escalations | Human escalation queue |
POST /escalations/{id}/assign | Assign escalation to a staff member |
POST /escalations/{id}/resolve | Mark escalation as resolved |
POST /escalations/{id}/dismiss | Dismiss escalation |
Key Files
| Type | Path |
|---|---|
| Service | app/Services/AutomationService.php — condition checker + action dispatcher |
| Service | app/Services/IntentRouter.php — keyword intent detection (9 intents) |
| Service | app/Services/FailoverService.php — OpenAI failover wrapper |
| Model | app/Models/AutomationRule.php |
| Model | app/Models/AutomationRun.php — execution log |
| Model | app/Models/AiActionLog.php |
| Model | app/Models/EscalationQueue.php |
| Controller | app/Http/Controllers/AutomationController.php |
| Table | automation_rules — trigger_type, conditions (JSON), actions (JSON), is_active |
| Table | automation_runs — rule_id, trigger_data, actions_taken, ran_at |
| Table | ai_action_logs — event_type, call_log_id, data (JSON), created_at |
| Table | escalation_queue — tenant_id, call_log_id, priority, status, assigned_to, resolved_at |
Automation Triggers (10)
| Trigger | Fired By |
|---|---|
missed_call | VobizService: call duration < 15 seconds |
call_ended | VobizService: hangup webhook received |
call_negative_sentiment | VobizService: sentiment analysis = negative |
appointment_booked | AppointmentsController: appointment created |
appointment_cancelled | AppointmentsController: appointment cancelled |
new_customer | CustomersController: new customer created (first call) |
lead_stage_changed | CustomersController: pipeline stage updated |
inbound_sms | TwilioService: inbound SMS webhook received |
inbound_whatsapp | TwilioService: inbound WhatsApp webhook received |
low_wallet | BillingService: wallet falls below threshold |
Automation Actions (6)
| Action | What It Does |
|---|---|
send_sms | Sends an SMS to the customer (or a custom number) |
send_whatsapp | Sends a WhatsApp message to the customer |
notify_staff | Sends an internal notification to a staff member |
move_lead | Moves the customer to a specified pipeline stage |
create_escalation | Creates a record in the escalation queue |
add_tag | Adds a tag to the customer record (future — tag system) |
Escalation Queue
When the AI detects an emergency or human escalation request during a call, or when an automation rule creates an escalation, a record is added to the escalation queue.
Priority Levels
- emergency — caller mentioned emergency; shown at top in red
- high — caller requested human; shown in orange
- normal — complaint or negative sentiment; shown in yellow
- low — routine escalation; shown in green
AI Action Log
Every significant AI event is recorded in ai_action_logs:
intent_detected— intent identified by IntentRouterresponse_generated— OpenAI returned a responseescalation_triggered— emergency or human handoff createdfailover_activated— OpenAI failed, fallback response used
What's Complete
- Automation rules engine: full CRUD, 10 trigger types, conditional logic (AND), 6 action types
- Visual workflow builder UI: trigger cards → condition builder → action builder → save
- AutomationService: condition checker + action dispatcher + run logger
- IntentRouter: 9-intent keyword detection before OpenAI call
- FailoverService: wraps every OpenAI call, intent-aware fallback responses
- AiActionLog: every intent/response/escalation/failover event logged
- ConversationEngine updated: IntentRouter + FailoverService + AiActionLog wired in
- Human escalation queue dashboard: priority levels, assign/resolve/dismiss workflow
- VobizService wired: call_ended + missed_call + call_negative_sentiment triggers
- AppointmentsController wired: appointment_booked + appointment_cancelled triggers
- Automation + Escalation nav items in sidebar
What's Deferred
- Multi-channel context sync (same context across call + SMS + WhatsApp)
- Role-based AI permissions (different AI behaviour per caller segment)
- Twilio hangup trigger wiring (same as Vobiz — needs TwilioService update)
- Zapier-style event bus (pub/sub for external integrations)