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): add bridge migration compatibility
chengyongrufbf96a350291
diff --git a/docs/chat-apps.md b/docs/chat-apps.mdindex c67f8adc2..26531e158 100644--- a/docs/chat-apps.md+++ b/docs/chat-apps.md@@ -343,6 +343,12 @@ Optional session database path:}```+**Migrating from the old bridge**++- Remove `bridgeUrl` and `bridgeToken`; WhatsApp no longer runs a local Node.js bridge.+- Re-run `nanobot channels login whatsapp`; old Baileys bridge auth data is not reused by neonize.+- Update `allowFrom` entries to the WhatsApp sender ID without a leading `+`.+**3. Run**```bashdiff --git a/nanobot/channels/whatsapp.py b/nanobot/channels/whatsapp.pyindex 3a5bec03f..9e7e3e6f1 100644--- a/nanobot/channels/whatsapp.py+++ b/nanobot/channels/whatsapp.py@@ -50,12 +50,17 @@ class _MediaInfo(NamedTuple):_NEONIZE_API: _NeonizeAPI | None = None_JID_RE = re.compile(r"^(?P<user>[^@]+)@(?P<server>[^@]+)$")+_LEGACY_BRIDGE_CONFIG_FIELDS = ("bridgeUrl", "bridgeToken", "bridge_url", "bridge_token")def _default_database_path() -> Path:return get_runtime_subdir("whatsapp-auth") / "neonize.db"+def _legacy_bridge_config_fields(config: dict[str, Any]) -> list[str]:+ return [field for field in _LEGACY_BRIDGE_CONFIG_FIELDS if field in config]++def _load_neonize() -> _NeonizeAPI:global _NEONIZE_APIif _NEONIZE_API is not None:@@ -272,9 +277,16 @@ class WhatsAppChannel(BaseChannel):return WhatsAppConfig().model_dump(by_alias=True)def __init__(self, config: Any, bus: MessageBus):+ legacy_bridge_fields = _legacy_bridge_config_fields(config) if isinstance(config, dict) else []if isinstance(config, dict):config = WhatsAppConfig.model_validate(config)super().__init__(config, bus)+ if legacy_bridge_fields:+ self.logger.warning(+ "Ignoring deprecated WhatsApp bridge config fields: {}. "+ "Run 'nanobot channels login whatsapp' to create a neonize session.",+ ", ".join(legacy_bridge_fields),+ )self._client: Any | None = Noneself._connected = Falseself._processed_message_ids: OrderedDict[str, None] = OrderedDict()diff --git a/tests/channels/test_whatsapp_channel.py b/tests/channels/test_whatsapp_channel.pyindex 6d58f7a98..e3eee242a 100644--- a/tests/channels/test_whatsapp_channel.py+++ b/tests/channels/test_whatsapp_channel.py@@ -8,7 +8,7 @@ import pytestfrom nanobot.bus.events import OutboundMessagefrom nanobot.channels import whatsapp as whatsapp_module-from nanobot.channels.whatsapp import WhatsAppChannel, _NeonizeAPI+from nanobot.channels.whatsapp import WhatsAppChannel, _legacy_bridge_config_fields, _NeonizeAPIclass _Proto:@@ -123,6 +123,11 @@ def test_default_config_has_no_bridge_fields() -> None:assert config["databasePath"] == ""+def test_legacy_bridge_config_fields_are_detected() -> None:+ assert _legacy_bridge_config_fields({"bridgeUrl": "ws://localhost:3001"}) == ["bridgeUrl"]+ assert _legacy_bridge_config_fields({"bridgeToken": "secret"}) == ["bridgeToken"]++@pytest.mark.asyncioasync def test_login_succeeds_when_connected(monkeypatch) -> None:_patch_neonize_api(monkeypatch)