Skip to content

feat(whatsapp): voice calls via WhatsApp Business Calling API + Gemini voice mode #628

Open

Description

@vybe

Summary

Add real-time voice call support to Trinity agents over WhatsApp, using the WhatsApp Business Calling API (GA July 2025) routed through Twilio and bridged to the existing Gemini Live voice mode.

Context

WhatsApp Business Calling API became generally available in July 2025 via both Meta's Cloud API and Twilio Programmable Voice. Trinity already uses Twilio for WhatsApp messaging (WHATSAPP-001), making this a natural extension.

The existing browser-based Gemini voice mode (routers/voice.py, services/gemini_voice.py) already implements the full speech-to-speech pipeline including Gemini Live API integration and run_task tool calling to Claude agents. The WhatsApp call path reuses this pipeline with Twilio Media Streams as the audio I/O layer instead of the browser.

Architecture:

WhatsApp user → Twilio (inbound call) → Media Streams WebSocket
    → [µ-law 8kHz ↔ PCM 16kHz conversion]
    → Gemini Live API (existing gemini_voice.py)
    → run_task tool → Claude agent
    → TTS audio back through same path → WhatsApp user

The audio format difference (Twilio: µ-law 8kHz / Gemini: PCM 16kHz) is handled by Python stdlib audioop — no new dependencies.

Acceptance Criteria

  • Inbound WhatsApp calls to a business number are answered by the bound Trinity agent
  • Audio streams bidirectionally between caller and Gemini Live API with correct codec conversion (µ-law 8kHz ↔ PCM 16kHz/24kHz)
  • run_task tool calling routes complex queries to the Claude agent during the call
  • Call transcripts are persisted as ChatMessage rows in the database (same as browser voice mode)
  • Per-agent voice system prompt is applied to the call session
  • TwiML webhook endpoint returns <Connect><Stream> to initiate Media Streams
  • WhatsApp binding config (in whatsapp_bindings table) includes a flag to enable/disable voice calls
  • Graceful call termination on agent stop or Twilio disconnect

Technical Notes

Files to create/modify:

  • src/backend/routers/voice.py — add new /ws/whatsapp-call/{agent_name} WebSocket endpoint for Twilio Media Streams
  • src/backend/services/gemini_voice.py — reuse as-is; extract GeminiVoiceSession to accept generic audio I/O callbacks
  • src/backend/adapters/whatsapp_adapter.py — add sendVoice / call control helpers
  • src/backend/adapters/transports/twilio_webhook.py — handle call event type, return TwiML
  • src/backend/db/ — add voice_enabled flag to whatsapp_bindings

External requirements:

  • Meta Business Verification (for the WhatsApp Business account)
  • Twilio Programmable Voice enabled on the account
  • Messaging limit ≥ 2,000 BIC/24h (only affects outbound calls, not inbound)

References:

Activity

  1. added
    priority-p2
    type-feature
    on May 2, 2026
  2. added
    theme-channels
    complexity-high
    on Jun 3, 2026
  3. added
    status-incubating
    on Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-highpriority-p2status-incubatingtheme-channelstype-feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions