mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-15 07:14:08 +00:00
fix: preserve WhatsApp forwarded metadata
maintainer edit: carry the bridge isForwarded flag into channel metadata so forwarded voice messages remain distinguishable after transcription.
This commit is contained in:
parent
0505a4fb2a
commit
e1ff0f37d9
@ -290,6 +290,7 @@ class WhatsAppChannel(BaseChannel):
|
|||||||
"message_id": message_id,
|
"message_id": message_id,
|
||||||
"timestamp": data.get("timestamp"),
|
"timestamp": data.get("timestamp"),
|
||||||
"is_group": data.get("isGroup", False),
|
"is_group": data.get("isGroup", False),
|
||||||
|
"is_forwarded": bool(data.get("isForwarded", False)),
|
||||||
"participant": participant or None,
|
"participant": participant or None,
|
||||||
"is_reply_to_bot": data.get("isReplyToBot", False),
|
"is_reply_to_bot": data.get("isReplyToBot", False),
|
||||||
},
|
},
|
||||||
|
|||||||
@ -291,6 +291,30 @@ async def test_voice_message_transcription_uses_media_path():
|
|||||||
assert kwargs["content"].startswith("Hello world")
|
assert kwargs["content"].startswith("Hello world")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_forwarded_voice_message_preserves_metadata_after_transcription():
|
||||||
|
ch = WhatsAppChannel({"enabled": True, "allowFrom": ["*"]}, MagicMock())
|
||||||
|
ch._handle_message = AsyncMock()
|
||||||
|
ch.transcribe_audio = AsyncMock(return_value="Forwarded audio text")
|
||||||
|
|
||||||
|
await ch._handle_bridge_message(
|
||||||
|
json.dumps({
|
||||||
|
"type": "message",
|
||||||
|
"id": "v-forwarded",
|
||||||
|
"sender": "12345@s.whatsapp.net",
|
||||||
|
"pn": "",
|
||||||
|
"content": "[Voice Message]",
|
||||||
|
"timestamp": 1,
|
||||||
|
"media": ["/tmp/voice.ogg"],
|
||||||
|
"isForwarded": True,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
kwargs = ch._handle_message.await_args.kwargs
|
||||||
|
assert kwargs["content"] == "Forwarded audio text"
|
||||||
|
assert kwargs["metadata"]["is_forwarded"] is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_unauthorized_voice_message_does_not_transcribe() -> None:
|
async def test_unauthorized_voice_message_does_not_transcribe() -> None:
|
||||||
ch = WhatsAppChannel({"enabled": True, "allowFrom": ["allowed"]}, MagicMock())
|
ch = WhatsAppChannel({"enabled": True, "allowFrom": ["allowed"]}, MagicMock())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user