"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(channels): stop dropping whatsapp voice notes on an undefined transcribe call
Lanre Shittucf5fb25b21db
diff --git a/agent/src/channels/whatsapp.py b/agent/src/channels/whatsapp.pyindex f01720e0d..b01966dff 100644--- a/agent/src/channels/whatsapp.py+++ b/agent/src/channels/whatsapp.py@@ -582,12 +582,11 @@ class WhatsAppChannel(BaseChannel):if media is not None:path = await self._download_media(client, event, media)if media.kind == "audio" and media.is_voice:- transcription = await self.transcribe_audio(path)- if transcription:- text = transcription- else:- media_paths.append(path)- text = self._append_media_tag(text, "audio", path)+ # No transcription backend is wired up for this channel, so+ # treat a voice note like any other attachment instead of+ # calling an undefined method and dropping the message.+ media_paths.append(path)+ text = self._append_media_tag(text, "audio", path)else:media_paths.append(path)text = self._append_media_tag(text, media.kind, path)diff --git a/agent/tests/test_whatsapp_voice_note_handling.py b/agent/tests/test_whatsapp_voice_note_handling.pynew file mode 100644index 000000000..1582984fe--- /dev/null+++ b/agent/tests/test_whatsapp_voice_note_handling.py@@ -0,0 +1,49 @@+"""Regression: an inbound WhatsApp voice note must reach the agent as a+media attachment, not be dropped on an undefined transcription call.+"""++from __future__ import annotations++import asyncio+from types import SimpleNamespace++from src.channels.whatsapp import WhatsAppChannel+++def _make_voice_note_event() -> SimpleNamespace:+ audio_message = SimpleNamespace(mimetype="audio/ogg", fileName="", PTT=True, ptt=True)+ message = SimpleNamespace(+ imageMessage=None, videoMessage=None, audioMessage=audio_message,+ documentMessage=None, stickerMessage=None, conversation="", extendedTextMessage=None,+ )+ source = SimpleNamespace(+ IsFromMe=False, Chat="[email protected]", IsGroup=False,+ Sender="[email protected]", SenderAlt=None,+ )+ info = SimpleNamespace(MessageSource=source, Timestamp=0, ID="msg1")+ return SimpleNamespace(Info=info, Message=message)+++class TestVoiceNoteHandling:+ def test_voice_note_reaches_the_agent_as_an_audio_attachment(self) -> None:+ channel = WhatsAppChannel({}, bus=None)+ channel.is_allowed = lambda sender_id: True++ async def fake_download_media(client, event, media):+ return "/tmp/voice_note.ogg"++ channel._download_media = fake_download_media++ handled: dict = {}++ async def fake_handle_message(**kwargs):+ handled.update(kwargs)++ channel._handle_message = fake_handle_message++ asyncio.run(+ channel._handle_neonize_message(client=None, event=_make_voice_note_event())+ )++ assert handled.get("media") == ["/tmp/voice_note.ogg"]+ assert handled.get("content") == "[audio: /tmp/voice_note.ogg]"