How mauroproto/vocero works
Purpose and Runtime
Vocero is a Python 3.12/FastAPI backend that turns WhatsApp text or voice-note requests into autonomous provider phone calls and reports booking outcomes. The application entry point is app/main.py; configuration and environment boundaries are centralized in app/config.py. It runs directly under Uvicorn or in Docker via Dockerfile and docker-compose.yml.
Ingress: WhatsApp Request Handling
Meta WhatsApp webhooks enter through app/api/whatsapp.py, which verifies webhook subscriptions and receives inbound messages. This is the primary user-facing ingress. Message content is normalized into the request workflow; voice media is streamed/downloaded through app/api/media_stream.py and transcribed by app/services/transcription.py.
Conversation Understanding and State
app/services/intent.py uses OpenAI GPT to extract a structured appointment request defined in app/schemas/intent.py: service/provider need, location, scheduling preferences, and likely language/context. app/services/state.py owns the conversation-state boundary between possibly incomplete WhatsApp interactions and a request ready for call orchestration.
Provider Discovery and Selection
When the user has not specified a provider, app/services/places.py queries Google Places for candidates. app/services/contact.py supplies contact-oriented handling. Candidate outcomes from simultaneous calls are compared in app/services/ranking.py, separating search and result-selection policy from telephony execution.
Outbound Voice-Agent Call Orchestration
app/services/elevenlabs_call.py coordinates the outbound path: it registers a call with ElevenLabs Conversational AI, receives TwiML, and asks Twilio to originate the PSTN call. Twilio connects directly to the ElevenLabs voice-agent WebSocket; FastAPI is orchestration and tool infrastructure rather than an audio bridge. The relevant integration boundary is app/services/twilio.py.
Mid-Call Tool Boundary
During a live call, ElevenLabs invokes server tools exposed by app/api/tools.py. Tool contracts in app/schemas/tools.py support availability reporting, preference validation, booking confirmation, and no-availability outcomes. These endpoints let the phone agent make bounded, structured decisions against request state instead of owning backend persistence or messaging logic.
Completion, Notifications, and Persistence
Twilio lifecycle callbacks arrive at app/api/callbacks.py; post-call processing summarizes the transcript via OpenAI and determines the final user-facing outcome. app/services/messages.py renders/sends progress and completion messages through Meta WhatsApp. Confirmed appointments receive a Google Calendar link from app/services/calendar.py. PostgreSQL persistence is represented by app/db/session.py and domain models including app/models/appointment.py, app/models/call_log.py, and app/models/appointment_request.py.
External Services and Control Flow
Primary control flow is: Meta WhatsApp → FastAPI webhook → transcription (if needed) → OpenAI intent extraction/state completion → Google Places discovery (optional) → ElevenLabs registration + Twilio call → ElevenLabs tool callbacks → Twilio completion callback → OpenAI summary/ranking → WhatsApp notification and calendar link. Material external dependencies are Meta Cloud API, ElevenLabs Agents/Scribe, Twilio Voice, OpenAI GPT, Google Places, Google Calendar-link generation, and Docker-hosted PostgreSQL.
Main entry points: ranking.py Outcome ranking · state.py Conversation state · intent.py Intent extraction · whatsapp.py WhatsApp webhook
Components 22
FastAPI ingress
- Vocero API · Application runtime and integration host.
app/main.py - Configuration
app/config.py - WhatsApp webhook
app/api/whatsapp.py - Voice media stream
app/api/media_stream.py - Agent tools · Bounded live-call operations against request state.
app/api/tools.py - Twilio callbacks
app/api/callbacks.py
Request workflow
- Transcription
app/services/transcription.py - Intent extraction
app/services/intent.py - Conversation state · Holds incomplete conversations until ready for calling.
app/services/state.py - Provider discovery
app/services/places.py - Outcome ranking
app/services/ranking.py - WhatsApp messaging
app/services/messages.py - Calendar link
app/services/calendar.py
Call execution
- Call orchestrator · Registers the agent and initiates provider calls.
app/services/elevenlabs_call.py - Twilio integration
app/services/twilio.py
External services
- Meta Cloud API
- OpenAI GPT
- Google Places
- ElevenLabs Agents · Hosts the agent and its direct audio WebSocket.
- Twilio Voice
- Google Calendar
Persistence
- PostgreSQL · Stores requests, calls, and appointments.
app/db/session.py
Connections 25
- Meta Cloud API → WhatsApp webhook: inbound messages
- WhatsApp webhook → Voice media stream: voice notes
- Voice media stream → Transcription: audio
- WhatsApp webhook → Intent extraction: text request
- Transcription → Intent extraction: transcript
- Intent extraction → OpenAI GPT: extract request
- Intent extraction → Conversation state: structured request
- Conversation state → PostgreSQL: persist state
- Conversation state → Provider discovery: provider unspecified
- Provider discovery → Google Places: search candidates
- Conversation state → Call orchestrator: ready request
- Call orchestrator → ElevenLabs Agents: register agent call
- Call orchestrator → Twilio integration: originate call
- Twilio integration → Twilio Voice: PSTN call
- Twilio Voice → ElevenLabs Agents: audio WebSocket · Twilio connects directly to the voice agent.
- ElevenLabs Agents → Agent tools: tool invocations
- Agent tools → Conversation state: validate and update
- Twilio Voice → Twilio callbacks: call lifecycle
- Twilio callbacks → Outcome ranking: completed call
- Outcome ranking → OpenAI GPT: summarize outcome
- Outcome ranking → PostgreSQL: store outcome
- Outcome ranking → Calendar link: confirmed booking
- Calendar link → Google Calendar: calendar link
- Outcome ranking → WhatsApp messaging: final outcome
- WhatsApp messaging → Meta Cloud API: progress and completion