Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(whatsapp): normalize neonize message timestamps to seconds
jipeng6036-dele5a69544e825
diff --git a/nanobot/channels/whatsapp/runtime.py b/nanobot/channels/whatsapp/runtime.pyindex 458e0b160..9ffd6588b 100644--- a/nanobot/channels/whatsapp/runtime.py+++ b/nanobot/channels/whatsapp/runtime.py@@ -679,7 +679,8 @@ class WhatsAppChannel(BaseChannel):if chat_jid == "status@broadcast":return- timestamp = float(_safe_attr(info, "Timestamp", 0) or 0)+ # Neonize encodes MessageInfo.Timestamp as Unix milliseconds.+ timestamp = float(_safe_attr(info, "Timestamp", 0) or 0) / 1000if self._started_at and timestamp and timestamp < self._started_at:returndiff --git a/nanobot/channels/whatsapp/tests/test_whatsapp_channel.py b/nanobot/channels/whatsapp/tests/test_whatsapp_channel.pyindex ff3ee9063..b66530762 100644--- a/nanobot/channels/whatsapp/tests/test_whatsapp_channel.py+++ b/nanobot/channels/whatsapp/tests/test_whatsapp_channel.py@@ -588,6 +588,40 @@ async def test_group_allow_from_does_not_allow_same_participant_in_other_group()assert bus.inbound_size == 0+async def test_message_before_startup_is_dropped_with_millisecond_timestamp() -> None:+ bus = MessageBus()+ ch = WhatsAppChannel({"enabled": True, "allowFrom": ["*"]}, bus)+ ch._started_at = 1_700_000_000.250+ ch._send_read_receipt = AsyncMock()++ await ch._handle_neonize_message(+ SimpleNamespace(download_any=AsyncMock()),+ _event(message=_Proto(conversation="old message"), timestamp=1_700_000_000_249),+ )++ assert bus.inbound_size == 0+ ch._send_read_receipt.assert_not_awaited()++[email protected]("timestamp", [1_700_000_000_251, 1_700_000_001_987])+async def test_message_after_startup_has_timestamp_in_seconds(timestamp: int) -> None:+ bus = MessageBus()+ ch = WhatsAppChannel({"enabled": True, "allowFrom": ["*"]}, bus)+ ch._started_at = 1_700_000_000.250++ await ch._handle_neonize_message(+ SimpleNamespace(download_any=AsyncMock()),+ _event(message=_Proto(conversation="new message"), timestamp=timestamp),+ )++ assert bus.inbound_size == 1+ msg = await bus.consume_inbound()+ assert msg.content == "new message"+ assert msg.metadata["timestamp"] == timestamp // 1000++@pytest.mark.asyncioasync def test_read_receipt_is_requested_once_after_dedup() -> None:ch = _make_channel()