"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(channels): drop undefined transcribe calls in four IM adapters
VectorPeak7fd7b90ad882
diff --git a/agent/src/channels/feishu.py b/agent/src/channels/feishu.pyindex 8d641af10..934c92f16 100644--- a/agent/src/channels/feishu.py+++ b/agent/src/channels/feishu.py@@ -2350,12 +2350,6 @@ class FeishuChannel(BaseChannel):)if file_path:media_paths.append(file_path)-- if msg_type == "audio" and file_path:- transcription = await self.transcribe_audio(file_path)- if transcription:- content_text = f"[transcription: {transcription}]"-content_parts.append(content_text)elif msg_type in (diff --git a/agent/src/channels/matrix.py b/agent/src/channels/matrix.pyindex a5a3107c9..0909cbafc 100644--- a/agent/src/channels/matrix.py+++ b/agent/src/channels/matrix.py@@ -1013,13 +1013,7 @@ class MatrixChannel(BaseChannel):if isinstance(body := getattr(event, "body", None), str) and body.strip():parts.append(body.strip())- if attachment and attachment.get("type") == "audio":- transcription = await self.transcribe_audio(attachment["path"])- if transcription:- parts.append(f"[transcription: {transcription}]")- else:- parts.append(marker)- elif marker:+ if marker:parts.append(marker)await self._start_typing_keepalive(room.room_id)diff --git a/agent/src/channels/telegram.py b/agent/src/channels/telegram.pyindex f98bd50c4..feb4520fd 100644--- a/agent/src/channels/telegram.py+++ b/agent/src/channels/telegram.py@@ -1263,12 +1263,8 @@ class TelegramChannel(BaseChannel):file_path = media_dir / f"{unique_id}{ext}"await file.download_to_drive(str(file_path))path_str = str(file_path)- if media_type in ("voice", "audio"):- transcription = await self.transcribe_audio(file_path)- if transcription:- self.logger.info("Transcribed %s: %s...", media_type, transcription[:50])- return [path_str], [f"[transcription: {transcription}]"]- return [path_str], [f"[{media_type}: {path_str}]"]+ # No transcription backend is wired up, so voice/audio notes are+ # forwarded as attachments like any other media.return [path_str], [f"[{media_type}: {path_str}]"]except Exception as e:self.logger.warning("Failed to download message media: %s", e)diff --git a/agent/src/channels/weixin.py b/agent/src/channels/weixin.pyindex 1c6cbb732..c3b2bc3a0 100644--- a/agent/src/channels/weixin.py+++ b/agent/src/channels/weixin.py@@ -729,11 +729,7 @@ class WeixinChannel(BaseChannel):has_top_level_downloadable_media = Truefile_path = await self._download_media_item(voice_item, "voice")if file_path:- transcription = await self.transcribe_audio(file_path)- if transcription:- content_parts.append(f"[voice] {transcription}")- else:- content_parts.append(f"[voice]\n[Audio: source: {file_path}]")+ content_parts.append(f"[voice]\n[Audio: source: {file_path}]")media_paths.append(file_path)else:content_parts.append("[voice]")@@ -791,11 +787,7 @@ class WeixinChannel(BaseChannel):voice_item = ref_media_item.get("voice_item") or {}file_path = await self._download_media_item(voice_item, "voice")if file_path:- transcription = await self.transcribe_audio(file_path)- if transcription:- content_parts.append(f"[voice] {transcription}")- else:- content_parts.append(f"[voice]\n[Audio: source: {file_path}]")+ content_parts.append(f"[voice]\n[Audio: source: {file_path}]")media_paths.append(file_path)elif ref_type == ITEM_FILE:file_item = ref_media_item.get("file_item") or {}diff --git a/agent/tests/test_voice_note_attachment_passthrough.py b/agent/tests/test_voice_note_attachment_passthrough.pynew file mode 100644index 000000000..bd545bb25--- /dev/null+++ b/agent/tests/test_voice_note_attachment_passthrough.py@@ -0,0 +1,274 @@+"""Regression: voice/audio messages must reach the agent as attachments.++Telegram, Feishu, Matrix and Weixin used to await ``self.transcribe_audio()``,+a method defined nowhere, so a voice note was dropped (or mislabelled as a+failed download) instead of being forwarded.+"""++from __future__ import annotations++import asyncio+import json+import sys+import types+from types import SimpleNamespace++import pytest+++def _stub_telegram_deps() -> None:+ """Install minimal stubs so telegram.py imports without python-telegram-bot."""++ def _mod(name: str) -> types.ModuleType:+ mod = types.ModuleType(name)+ sys.modules[name] = mod+ return mod++ class _Accepting:+ def __init__(self, *args, **kwargs) -> None:+ for key, value in kwargs.items():+ setattr(self, key, value)++ tg = _mod("telegram")+ for name in (+ "BotCommand",+ "InlineKeyboardButton",+ "InlineKeyboardMarkup",+ "ReactionTypeEmoji",+ "ReplyParameters",+ "Update",+ ):+ setattr(tg, name, _Accepting)++ err = _mod("telegram.error")+ for name in ("BadRequest", "NetworkError", "TimedOut", "RetryAfter"):+ setattr(err, name, type(name, (Exception,), {}))++ ext = _mod("telegram.ext")+ for name in (+ "Application",+ "CallbackQueryHandler",+ "ContextTypes",+ "MessageHandler",+ "filters",+ ):+ setattr(ext, name, _Accepting)++ _mod("telegram.request").HTTPXRequest = _Accepting+++_stub_telegram_deps()++import src.channels.telegram as telegram_mod # noqa: E402+from src.channels.feishu import FeishuChannel # noqa: E402+from src.channels.telegram import TelegramChannel # noqa: E402+from src.channels.weixin import ITEM_TEXT, ITEM_VOICE, WeixinChannel # noqa: E402+++async def _noop(*args, **kwargs) -> None:+ return None+++def _capture_handle_message(channel) -> list[dict]:+ handled: list[dict] = []++ async def fake_handle_message(**kwargs) -> None:+ handled.append(kwargs)++ channel._handle_message = fake_handle_message+ return handled+++class TestTelegramVoiceNote:+ @pytest.mark.parametrize("attribute", ["voice", "audio"])+ def test_voice_note_is_forwarded_as_an_attachment(+ self, monkeypatch, tmp_path, attribute: str+ ) -> None:+ class _File:+ async def download_to_drive(self, path) -> None:+ pass++ class _Bot:+ async def get_file(self, file_id):+ assert file_id == "f1"+ return _File()++ channel = TelegramChannel({"token": "x"}, bus=None)+ channel._app = SimpleNamespace(bot=_Bot())+ monkeypatch.setattr(telegram_mod, "get_media_dir", lambda name: tmp_path)++ message = SimpleNamespace(photo=None, voice=None, audio=None)+ setattr(+ message,+ attribute,+ SimpleNamespace(+ file_id="f1",+ file_unique_id="v1",+ mime_type="audio/ogg",+ file_name=None,+ ),+ )++ media, parts = asyncio.run(+ channel._download_message_media(message, add_failure_content=True)+ )++ path = str(tmp_path / "v1.ogg")+ assert media == [path]+ assert parts == [f"[{attribute}: {path}]"]+++class TestFeishuVoiceNote:+ def test_audio_message_is_forwarded_as_an_attachment(self, tmp_path) -> None:+ path = str(tmp_path / "feishu_voice.ogg")+ channel = FeishuChannel({}, bus=None)+ channel.is_allowed = lambda sender_id: True+ channel._add_reaction = _noop+ handled = _capture_handle_message(channel)++ async def fake_download_and_save_media(msg_type, content_json, message_id=None):+ return path, f"[{msg_type}: {path}]"++ channel._download_and_save_media = fake_download_and_save_media++ message = SimpleNamespace(+ message_id="om_1",+ chat_id="oc_1",+ chat_type="p2p",+ message_type="audio",+ content=json.dumps({"file_key": "fk1"}),+ mentions=None,+ parent_id=None,+ root_id=None,+ thread_id=None,+ )+ data = SimpleNamespace(+ event=SimpleNamespace(+ message=message,+ sender=SimpleNamespace(+ sender_type="user",+ sender_id=SimpleNamespace(open_id="ou_1"),+ ),+ )+ )++ asyncio.run(channel._on_message(data))++ assert [(h["media"], h["content"]) for h in handled] == [+ ([path], f"[audio: {path}]")+ ]+++class TestMatrixVoiceNote:+ def test_audio_attachment_is_forwarded(self) -> None:+ pytest.importorskip("nio")+ pytest.importorskip("aiohttp")+ from src.channels.matrix import MatrixChannel++ path = "/tmp/matrix_voice.ogg"+ channel = MatrixChannel({}, bus=None)+ channel._is_pre_startup_event = lambda event: False+ channel._should_process_message = lambda room, event: True+ channel._is_direct_room = lambda room: True+ channel._start_typing_keepalive = _noop+ channel._base_metadata = lambda room, event: {}+ handled = _capture_handle_message(channel)++ async def fake_fetch_media_attachment(room, event):+ return (+ {+ "type": "audio",+ "path": path,+ "filename": "voice.ogg",+ "mime": "audio/ogg",+ },+ f"[attachment: {path}]",+ )++ channel._fetch_media_attachment = fake_fetch_media_attachment++ room = SimpleNamespace(room_id="!room:example.org")+ event = SimpleNamespace(sender="@alice:example.org", body="", event_id="$evt")++ asyncio.run(channel._on_media_message(room, event))++ assert [(h["media"], h["content"]) for h in handled] == [+ ([path], f"[attachment: {path}]")+ ]+++class TestWeixinVoiceNote:+ def test_top_level_voice_item_is_forwarded(self) -> None:+ path = "/tmp/weixin_voice.silk"+ channel = WeixinChannel({}, bus=None)+ channel.is_allowed = lambda sender_id: True+ channel._start_typing = _noop+ handled = _capture_handle_message(channel)++ async def fake_download_media_item(typed_item, media_type, filename=None):+ return path++ channel._download_media_item = fake_download_media_item++ asyncio.run(+ channel._process_message(+ {+ "message_type": 1,+ "message_id": "m1",+ "from_user_id": "u1",+ "item_list": [+ {+ "type": ITEM_VOICE,+ "voice_item": {+ "text": "",+ "media": {"encrypt_query_param": "q1"},+ },+ }+ ],+ }+ )+ )++ assert [(h["media"], h["content"]) for h in handled] == [+ ([path], f"[voice]\n[Audio: source: {path}]")+ ]++ def test_quoted_voice_message_is_forwarded(self) -> None:+ path = "/tmp/weixin_quoted_voice.silk"+ channel = WeixinChannel({}, bus=None)+ channel.is_allowed = lambda sender_id: True+ channel._start_typing = _noop+ handled = _capture_handle_message(channel)++ async def fake_download_media_item(typed_item, media_type, filename=None):+ return path++ channel._download_media_item = fake_download_media_item++ asyncio.run(+ channel._process_message(+ {+ "message_type": 1,+ "message_id": "m2",+ "from_user_id": "u2",+ "item_list": [+ {+ "type": ITEM_TEXT,+ "text_item": {"text": "what did they say?"},+ "ref_msg": {+ "message_item": {+ "type": ITEM_VOICE,+ "voice_item": {+ "media": {"encrypt_query_param": "q2"}+ },+ }+ },+ }+ ],+ }+ )+ )++ assert [(h["media"], h["content"]) for h in handled] == [+ ([path], f"what did they say?\n[voice]\n[Audio: source: {path}]")+ ]