Voice
The phone receptionist (Plivo and Dograh chat-completions), the voice calls log with cost, and the staff voice assistant for booking, billing and expenses.
7 min read
Overview
Kagami has separate voice features that share a name:

| System | Who talks | Entry point | Brain |
|---|---|---|---|
| Phone receptionist | A client phoning the salon | Plivo routes (/api/webhooks/plivo/voice/*) and /api/voice/dograh/v1/chat/completions |
The WhatsApp booking agent (runAgentTurn), channel phone |
| Staff voice assistant | Salon staff at the front desk | /dashboard/voice-assistant |
A one-shot tool-calling LLM parse (parseVoiceAction), then existing booking, billing and expense actions |
The receptionist does not have its own model or tools. It reuses the AI booking agent (see ai.md and ai-whatsapp-agent), so brand persona, catalog, store hours, token budget and handoff rules come from ai_agent_settings, not from voice_settings. Calls that arrived through the retired Twilio path keep their call-log rows.
Source: web/src/lib/voice/, web/src/lib/ai-gateway/voice-tenant.ts, web/src/components/voice-assistant/.
Where owners configure it
| What | Where | Who | Notes |
|---|---|---|---|
| Voice agent settings | Settings, "Voice agent" (/dashboard/settings/voice) |
Manager roles (MANAGER_ROLES); nav item requires the voice feature (tier pro, features/registry.ts) |
One voice_settings row per brand (UNIQUE (brand_id)), saved by saveVoiceSettingsAction |
| Calls log | /dashboard/voice-calls |
Manager roles (route rule in nav/sections.ts, parent Marketing) |
No sidebar link; reached from the empty-state button or by URL |
| Staff voice assistant | /dashboard/voice-assistant, top-bar mic button, Ctrl+J / Cmd+J |
All six roles (ALL_ROLES) |
Needs an active store selected |
| Plan gating | hasFeature(orgId, "voice") |
Enforced on the calls log page and the settings nav only. The webhooks and the staff assistant do not check it |
voice_settings columns: is_enabled (default false), twilio_account_sid, twilio_auth_token, twilio_phone_number (E.164), persona_name (default Aria), greeting_message, handoff_phone (E.164), plus org_id, brand_id. The settings page never sends the stored token to the browser; it shows a masked hint, and the token is only written when the owner types a new one (SALO-475). The Twilio webhook URLs are no longer shown: those routes were removed (see section 1).
1. Retired Twilio and Dograh-TwiML webhooks
The Twilio gather loop (/api/webhooks/voice/{inbound,gather,status}) and the Dograh TwiML webhook (/api/webhooks/dograh) were removed (SALO-3081, 2026-11-28): neither was configured at a provider, and with two app nodes a provider retry could land on either node with no dedupe or turn lock. Phone calls now arrive only through the Plivo routes and /api/voice/dograh/v1/chat/completions. Historical voice_calls rows from the Twilio path stay readable in the calls log.
2. Voice calls dashboard and cost log
Page: /dashboard/voice-calls lists up to 100 calls (listVoiceCalls), newest first, filtered to the active store plus calls with no location (SALO-2119). Detail page /dashboard/voice-calls/[id] shows status, outcome, duration, AI cost and the turn-by-turn transcript, scoped to the caller's org (getVoiceCallWithTurns(id, orgId)).
| Table | Columns (migration 0016_voice.sql, 0211) |
|---|---|
voice_calls |
call_sid (unique), from_phone, to_phone, status (ringing, in_progress, completed, failed, busy, no_answer, cancelled), outcome (booked, rescheduled, cancelled_appointment, handed_off, no_action, error), duration_sec, tokens_input, tokens_output, cost_usd NUMERIC(10,6), started_at, ended_at, location_id, updated_at |
voice_turns |
call_id, turn_index, speaker (agent or caller), text |
0123_ai_voice_agent.sql declares call_transcripts and re-declares other tables with different shapes; its CREATE TABLE IF NOT EXISTS statements were no-ops for tables that already existed (see the comment at the top of that file and 0211). The code reads and writes voice_turns, not call_transcripts.
How cost is computed
runAgentTurnsums tokens over its LLM calls and prices each withcomputeCostUsd(provider, in, out)=(in * costPer1M.input + out * costPer1M.output) / 1,000,000(lib/ai/llm.ts).- Per-provider rates are fixed or env-overridable: OpenRouter
OPENROUTER_COST_IN_PER_1M/OPENROUTER_COST_OUT_PER_1M; GroqGROQ_COST_IN_PER_1M/GROQ_COST_OUT_PER_1M; Anthropic is hard-coded by model family (haiku, sonnet, opus). - The result is written to
ai_action_logs(input_tokens,output_tokens,cost_usd). - After each turn
processVoiceTurnreads the latestai_action_logsrow for the conversation and adds it tovoice_calls.tokens_input,tokens_output,cost_usd.
Cost is LLM cost only, in USD, shown as $0.0000 (four decimals) or a dash when zero. It does not include Twilio per-minute telephony or text-to-speech charges, although the UI tooltip says "telephony plus model".
Outcome: the code only ever sets outcome = handed_off. booked, rescheduled, cancelled_appointment, no_action and error are never written, so most rows show the badge "In progress" even after the call has ended (the list page maps a null outcome to that label).
Permissions: the table voice_calls and voice_turns allow SELECT to org members (is_org_member) and ALL to the service role; the pages read through the admin client and filter by the caller's org. The page route is limited to manager roles.
3. Staff voice assistant
Page /dashboard/voice-assistant renders VoiceAssistantPanel. Flow: dictate or type, parse, confirm, execute.
| Step | Code | Detail |
|---|---|---|
| 1. Capture | voice-assistant-panel.tsx |
Browser Web Speech API (SpeechRecognition / webkitSpeechRecognition, lang = "en-IN", non-continuous, interim results). In the Android apps the device recognizer is used through window.SalonOSSpeech (lib/device/native-speech.ts), also en-IN. The transcript is editable in a text box; typing a command works without a microphone |
| 2. Parse | parseVoiceAction (lib/voice/assistant-actions.ts) |
Server action. Max 500 characters, rate limit 20 per 60 seconds per user (voice-parse:{userId}, fails closed). Loads the store (access checked with requireCallerLocationAccess), up to 1000 active services of the brand and the store's staff, and calls chatWithFailover (maxTokens: 500, temperature: 0.1) with three tools |
| 3. Confirm | Panel | Shows a summary card; bills and appointments need a staff member chosen in a dropdown (preselected from the spoken name, else the speaker's own staff record). Buttons: Confirm and Create, Cancel |
| 4. Execute | executeVoiceAction |
Re-validates the action with the zod VoiceActionSchema (client input is untrusted), re-checks staff belongs to the store, then calls the normal actions |
Tools and what each creates:
| Intent | LLM tool | Executes via | Limits and checks |
|---|---|---|---|
| Book or walk-in | create_appointment |
createAppointmentAction; client found by phone or created (createClientDirectAction) |
Service must match exactly one catalog entry (matchByName); time via parseRelativeTime (store timezone, "now" rounds up to 15 minutes, past times rejected); duration and price come from the catalog, not the payload; source is walk_in unless more than 30 minutes ahead; notes prefixed [Voice Assistant] |
| Bill | create_bill |
createPOSCheckoutAction |
Payment cash, upi or card (default cash); up to 20 lines, quantity 1 to 50, line cap Rs 5,00,000; an item with no spoken price and no catalog match is an error; a name without a phone makes a guest walk-in |
| Expense | log_expense |
createExpense |
Requires permission expenses.create; payment cash or upi; cap Rs 1,00,000; sends an expense_submitted alert |
The permission checks for bill and appointment creation live in the called actions (for example the staff booking restriction in createAppointmentAction), not in the voice layer. Voice-assistant model cost is not written to voice_calls, ai_action_logs or ai_usage_log.
Language support
Speech recognition is fixed to English (India), en-IN, in both the browser and native paths. The parse prompt is English; the LLM may cope with other scripts typed into the text box, but this is not tested or promised in code. Catalog and staff names are matched case-insensitively by exact or single partial match.
Explicit errors and mic permission
All failures show a specific message (user rule: no silent failures). Examples from the code:
| Cause | Message (abridged) |
|---|---|
Browser code not-allowed / service-not-allowed |
Microphone permission is blocked; allow it in app settings or the address bar |
unavailable, busy, no-speech, audio-capture, network |
Each has its own instruction; others show Voice input failed (code) |
| No Speech API at all | "This browser doesn't support voice input. Use Chrome or Edge, or type the command below." |
Android WebView without the native bridge (; wv) user agent) |
Install the newest Kagami app, or enable Google speech services |
| No active store | "Please select an active store in the sidebar before using Voice Assistant." |
| Parse failures | "Too many voice commands...", "That command is too long...", service, staff or time not understood, with the spoken phrase quoted |
| Execute failures | Real cause from the action, for example "Choose the staff member...", "You don't have permission to submit expenses." |
Device permission (SALO-2375): in the native apps the mic tap calls requestDevicePermission("microphone") first. granted starts listening; denied shows the blocked message and an "Open app settings" button (openAppSettings()); anything else asks the user to tap again and choose Allow. RECORD_AUDIO must be declared in both Android manifests and in NativePermissionBridge; a guard test checks this (see CLAUDE.md device-permissions rule and mobile.md). Browser and native failures are sent to the server log by reportVoiceClientIssue (prefix [voice.client], 30 per minute per user). A collapsible "Debug info" panel shows a timeline with a copy button.
Troubleshooting / where to look
| Symptom | Check |
|---|---|
| Agent says it is "not currently active" | ai_agent_settings.is_enabled off for the brand (voice depends on it) |
| Caller is transferred unexpectedly | AI token budget exhausted (checkBudget) or the agent requested a handoff; check ai_action_logs for the conversation |
| Voice assistant mic does nothing | Panel "Debug info"; server log lines starting [voice.client], [voice.parse]; voice.loadStore in monitoring |
| Costs look low | Only LLM cost is recorded, not telephony |
Related docs: ai.md, ai-whatsapp-agent, ai-quality-and-eval, settings.md, roles-permissions.md, error-codes.md.