WhatsApp Message Arrives
User sends a message via WhatsApp Business API. The webhook fires to our FastAPI ingestion service, parsing intent, language, and context in real-time.
- WhatsApp Business API
- FastAPI
- Webhook Handler
04 — Technical Showcase
Engineering the bridge between conversational text AI and real-time voice telephony. A complete system that transitions a WhatsApp chat into a live AI voice call — using Twilio SIP Domains, ElevenLabs, and LLM orchestration.
Stages
5
Integrations
Twilio · ElevenLabs · LLM
Modes
Text + Voice
User sends a message via WhatsApp Business API. The webhook fires to our FastAPI ingestion service, parsing intent, language, and context in real-time.
The message payload hits the LLM orchestration layer (OpenAI GPT-4o / Google Gemini 1.5). The model decides: generate a text reply, or trigger the voice pipeline? Intent classification happens here.
When the voice path is chosen, the LLM-generated text response is passed to ElevenLabs streaming API. A cloned or multilingual voice renders the response as a high-fidelity WAV/MP3 audio stream.
A Twilio SIP Domain is configured as the PSTN bridge. The audio stream is routed via TwiML — the call is initiated to the user's number with the ElevenLabs-generated voice. Real-time bidirectional audio over WebRTC/SIP.
The agent delivers the AI-generated voice response as a real phone call. The user can interact back (speech-to-text via Whisper), creating a full conversational loop — from text message to live phone AI agent.
# Simplified orchestration flowasync def handle_whatsapp_message(payload: WebhookPayload): # 1. Parse intent with LLM intent = await llm_router.classify(payload.body) if intent.requires_voice: # 2. Generate response text response = await openai_client.chat.completions.create( model="gpt-4o", messages=build_conversation(payload) ) # 3. Synthesize voice via ElevenLabs audio_stream = await elevenlabs.generate( text=response.choices[0].message.content, voice="ankush-custom-voice", stream=True ) # 4. Initiate Twilio SIP call call = twilio_client.calls.create( twiml=build_twiml(audio_stream), to=payload.from_number, from_=settings.TWILIO_SIP_DOMAIN ) return {"call_sid": call.sid, "status": "voice_delivered"} return await send_whatsapp_reply(payload, intent.text_response)ElevenLabs audio streamed directly into Twilio TwiML — sub-2s latency voice delivery
Whisper STT captures user's spoken reply, routes back to LLM for context-aware follow-up
ElevenLabs multilingual v2 + Gemini enable native voice responses in 29+ languages