Description
Summary
WhatsApp voice notes reach the agent as an audio file, never as text. Transcription is gated to Telegram by an explicit channel check in the message router, so a WhatsApp user who sends a voice message gets an agent that cannot read it. This pulls item 3d out of the #468 umbrella into a standalone, pickable issue.
Context
src/backend/adapters/message_router.py (~line 936):
async def _maybe_transcribe_voice(...):
"""Step 2b: transcribe a Telegram voice note in place."""
if channel != "telegram":
return messageTwo things changed since 3d was written as a speculative bullet inside an umbrella framed as "ship only if demand appears":
- Demand appeared. A live deployment received WhatsApp voice notes from a real user and had to reply that it couldn't hear them.
- The channel is asymmetric. Outbound voice on WhatsApp already exists — an agent can deliver its reply as a playable voice note. Inbound is the remaining gap: the agent can speak but not listen.
Two details in the #468 3d bullet are stale and worth correcting when this is picked up: it specifies the Whisper API, but transcription moved to Gemini (_transcribe_audio_gemini, model pinned via GEMINI_TRANSCRIPTION_MODEL after #1130); and it cites message_router.py:212, while the branch now lives at ~936.
Hard dependency: WhatsApp media download is currently broken (#1932) — the SSRF allowlist refuses Twilio's media CDN, so download_file returns None for every attachment. Transcription cannot be built or tested until that lands.
Acceptance Criteria
- A WhatsApp voice note is transcribed and the transcript replaces the media placeholder in the agent's prompt, matching Telegram's behavior
- The transcription branch becomes channel-generic rather than gaining a second hardcoded channel name — the guard keys on "this message carries a voice attachment this adapter can fetch", not on a channel string
- Reuses the shared
_transcribe_audio_gemini(bytes, mime_type)helper — no WhatsApp-specific transcription implementation - Audio is fetched through the existing SSRF-gated
WhatsAppAdapter.download_file— no new fetch path - Graceful fallback: on download failure, transcription failure, or unsupported MIME type, the agent still receives the message with an honest placeholder naming what failed — never a silent drop
- When transcription is unavailable (no Gemini key configured), the user-visible result is a clear placeholder, not an error
- Oversized or long audio has a defined ceiling with a documented fallback rather than an unbounded API call
- Unit tests for the WhatsApp voice path: happy path, download failure, transcription failure, unsupported MIME
-
docs/memory/feature-flows/whatsapp-integration.mdupdated; feat(whatsapp): Phase 3 advanced features — templates, SMS, interactive, voice (WHATSAPP-001 Phase 3, #299 follow-up) #468 item 3d checked off
Technical Notes
- Guard:
src/backend/adapters/message_router.py—_maybe_transcribe_voice(~936), called from ~406 (verified ondev) - Transcription helper:
src/backend/services/telegram_media.py—_transcribe_audio_gemini(~220) is MIME-agnostic and takes raw bytes. WhatsApp voice notes arrive asaudio/ogg, the same MIME Telegram sends, so the helper should work unchanged process_voice(~172) is not reusable as-is — it downloads through the Telegram Bot API. Either extract its transcribe-and-format tail into a channel-neutral helper or call_transcribe_audio_geminidirectly from the WhatsApp path- Inbound shapes differ: Telegram's is
raw_msg["voice"], WhatsApp's is aFileAttachmentparsed fromMediaUrl{N}. The generic seam isNormalizedMessage.filesfiltered by audio MIME - Once a second channel uses it, consider whether the transcription helper still belongs in
telegram_media.py - A channel-generic guard would make Slack voice clips near-free — worth noting, not in scope here
Related
- Parent umbrella: feat(whatsapp): Phase 3 advanced features — templates, SMS, interactive, voice (WHATSAPP-001 Phase 3, #299 follow-up) #468 (WhatsApp Phase 3) — this is item 3d
- Blocked by: bug(whatsapp): inbound media download always fails — SSRF allowlist rejects Twilio's own media CDN #1932 — inbound WhatsApp media download always fails (SSRF allowlist rejects Twilio's media CDN)
- Transcription stack: feat(telegram): voice-in via Whisper transcription #318 (voice-in, originally Whisper), bug: Telegram voice transcription + image-gen prompt refinement fail — hardcoded retired Gemini model gemini-2.0-flash returns 404 #1130 (Gemini model pinning)
- WHATSAPP-001 Phase 1 feat: WhatsApp channel adapter via Twilio — per-agent integration (WHATSAPP-001) #299 / feat(channels): WhatsApp via Twilio — per-agent binding (#299) #463, Phase 2 feat(whatsapp): access control integration (WHATSAPP-001 Phase 2, #299 follow-up) #467
Activity
fix(whatsapp): allow Twilio's media CDN as a validated redirect target (