Skip to content

Self-improving AI Employees for everyone

refactor(whatsapp): self-contained plugin folder (telegram pattern)

trohitg22a1c3ee701f
diff --git a/server/core/logging.py b/server/core/logging.py
index 8c85db4a..2ce3d4e1 100644
--- a/server/core/logging.py
+++ b/server/core/logging.py
@@ -33,7 +33,7 @@ class WebSocketLogHandler(logging.Handler):
'services.workflow': 'workflow',
'services.ai': 'ai',
'services.android': 'android',
- 'services.whatsapp_service': 'whatsapp',
+ 'nodes.whatsapp._service': 'whatsapp',
'routers.android': 'android',
'routers.websocket': 'websocket',
'routers.workflow': 'workflow',
diff --git a/server/nodes/social/_base.py b/server/nodes/social/_base.py
index dca96c7f..25e8c337 100644
--- a/server/nodes/social/_base.py
+++ b/server/nodes/social/_base.py
@@ -7,7 +7,7 @@ Email, Matrix, Teams).
Imported by :class:`nodes.social.social_receive.SocialReceiveNode` and
:class:`nodes.social.social_send.SocialSendNode`. Calls into
-``services.whatsapp_service`` for the WhatsApp bridge stay unchanged — moving
+``nodes.whatsapp._service`` for the WhatsApp bridge stay unchanged — moving
them out is a separate refactor.
"""
@@ -475,7 +475,7 @@ async def _send_via_whatsapp(
Maps socialSend parameters to whatsappSend parameters.
"""
- from services.whatsapp_service import handle_whatsapp_send as whatsapp_send_handler
+ from nodes.whatsapp._service import handle_whatsapp_send as whatsapp_send_handler
# Map socialSend params to whatsappSend format
whatsapp_params = {
diff --git a/server/nodes/whatsapp/__init__.py b/server/nodes/whatsapp/__init__.py
index db64d555..ca602d52 100644
--- a/server/nodes/whatsapp/__init__.py
+++ b/server/nodes/whatsapp/__init__.py
@@ -4,20 +4,35 @@ Public surface:
WhatsAppRuntime - edgymeow Go binary supervisor
get_whatsapp_runtime() - singleton accessor (lazy-init via classmethod)
-The runtime self-registers with ``services._supervisor.registry`` on
-package import, so ``services._supervisor.shutdown_all_supervisors()``
-called from the FastAPI lifespan will tear it down with all other
-plugin supervisors. No per-plugin lifespan hooks needed.
+Two self-registrations happen on package import:
+
+1. The Go-binary supervisor (``WhatsAppRuntime``) is registered with
+ :mod:`services._supervisor`, so the FastAPI lifespan teardown
+ reaches it via ``shutdown_all_supervisors()``.
+
+2. The WebSocket handler dispatch table (``WS_HANDLERS`` in
+ :mod:`._handlers`) is registered with
+ :mod:`services.ws_handler_registry`, so the central WS router in
+ ``routers/websocket.py`` picks up every ``whatsapp_*`` message type
+ without per-plugin imports. Same pattern as the telegram reference
+ plugin.
"""
from services._supervisor import register_supervisor
+from services.ws_handler_registry import register_ws_handlers
+from ._handlers import WS_HANDLERS
from ._runtime import WhatsAppRuntime, get_whatsapp_runtime
-# Self-registration: ensures shutdown_all_supervisors() reaches us.
+# Supervisor: ensures shutdown_all_supervisors() reaches us.
# get_instance() constructs the singleton once (lazy in spawn, not here).
register_supervisor(WhatsAppRuntime.get_instance())
+# WebSocket handlers: 19 message types (status / qr / send / restart /
+# groups / newsletters / chat_history / rate_limit_* / mark_read /
+# typing / presence / diagnostics / stop). Idempotent on re-import.
+register_ws_handlers(WS_HANDLERS)
+
__all__ = [
"WhatsAppRuntime",
"get_whatsapp_runtime",
diff --git a/server/nodes/whatsapp/_base.py b/server/nodes/whatsapp/_base.py
index eeb08fe9..5730cd32 100644
--- a/server/nodes/whatsapp/_base.py
+++ b/server/nodes/whatsapp/_base.py
@@ -1,7 +1,7 @@
"""WhatsApp send + DB business logic (Wave 11.D.9 inlined).
Imported by nodes.whatsapp.whatsapp_send and nodes.whatsapp.whatsapp_db.
-RPC dispatch still flows through services.whatsapp_service (HTTP to the Go
+RPC dispatch still flows through nodes.whatsapp._service (HTTP to the Go
bridge) — extracting that is a separate refactor, not required for the
plugin migration.
"""
@@ -145,7 +145,7 @@ async def handle_whatsapp_send(
Returns:
Execution result dict
"""
- from services.whatsapp_service import handle_whatsapp_send as whatsapp_send_handler
+ from nodes.whatsapp._service import handle_whatsapp_send as whatsapp_send_handler
start_time = time.time()
try:
@@ -289,7 +289,7 @@ async def handle_whatsapp_db(
Returns:
Execution result dict
"""
- from services.whatsapp_service import (
+ from nodes.whatsapp._service import (
handle_whatsapp_chat_history as whatsapp_chat_history_handler,
whatsapp_rpc_call
)
diff --git a/server/nodes/whatsapp/_handlers.py b/server/nodes/whatsapp/_handlers.py
new file mode 100644
index 00000000..cd1dfc9f
--- /dev/null
+++ b/server/nodes/whatsapp/_handlers.py
@@ -0,0 +1,167 @@
+"""WhatsApp WebSocket handlers — plugin-owned dispatch table.
+
+Self-registered into the central WS dispatcher via
+``register_ws_handlers(WS_HANDLERS)`` from this package's
+``__init__.py``. ``routers/websocket.py`` knows nothing about
+WhatsApp; the message-type strings are wired here so renames /
+additions stay local to the plugin.
+
+Each handler is a thin shim over the underlying RPC client in
+:mod:`._service`. Logic lives in the service module; this module is
+the WS surface.
+"""
+
+from __future__ import annotations
+
+from typing import Any, Dict
+
+from fastapi import WebSocket
+
+from ._service import (
+ handle_whatsapp_chat_history as _wa_chat_history,
+ handle_whatsapp_connected_phone as _wa_connected_phone,
+ handle_whatsapp_group_info as _wa_group_info,
+ handle_whatsapp_groups as _wa_groups,
+ handle_whatsapp_newsletters as _wa_newsletters,
+ handle_whatsapp_qr as _wa_qr,
+ handle_whatsapp_restart as _wa_restart,
+ handle_whatsapp_send as _wa_send,
+ handle_whatsapp_start as _wa_start,
+ handle_whatsapp_status as _wa_status,
+ whatsapp_rpc_call as _wa_rpc_call,
+)
+
+
+async def handle_whatsapp_status(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ return await _wa_status()
+
+
+async def handle_whatsapp_connected_phone(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Get the connected WhatsApp phone number."""
+ return await _wa_connected_phone()
+
+
+async def handle_whatsapp_qr(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ return await _wa_qr()
+
+
+async def handle_whatsapp_send(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Forward all send params to WhatsApp handler — supports all message types."""
+ return await _wa_send(data)
+
+
+async def handle_whatsapp_start(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ return await _wa_start()
+
+
+async def handle_whatsapp_restart(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ return await _wa_restart()
+
+
+async def handle_whatsapp_groups(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ return await _wa_groups()
+
+
+async def handle_whatsapp_newsletters(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Get list of subscribed newsletter channels."""
+ return await _wa_newsletters()
+
+
+async def handle_whatsapp_group_info(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Get group participants with resolved phone numbers."""
+ group_id = data.get("group_id", "")
+ return await _wa_group_info(group_id)
+
+
+async def handle_whatsapp_chat_history(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Get chat history from WhatsApp history store."""
+ return await _wa_chat_history(data)
+
+
+# ---- Rate-limit RPC passthroughs ----
+
+async def handle_whatsapp_rate_limit_get(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Get rate-limit config and current stats."""
+ return await _wa_rpc_call("rate_limit_get", {})
+
+
+async def handle_whatsapp_rate_limit_set(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Update rate-limit configuration."""
+ return await _wa_rpc_call("rate_limit_set", data.get("config", {}))
+
+
+async def handle_whatsapp_rate_limit_stats(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Get current rate-limit statistics."""
+ return await _wa_rpc_call("rate_limit_stats", {})
+
+
+async def handle_whatsapp_rate_limit_unpause(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Resume rate limiting after an automatic pause."""
+ return await _wa_rpc_call("rate_limit_unpause", {})
+
+
+# ---- Lightweight RPC passthroughs ----
+
+async def handle_whatsapp_mark_read(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Mark messages as read. Schema: mark_read({message_ids, chat_jid, sender_jid?})."""
+ message_ids = data.get("message_ids", [])
+ chat_jid = data.get("chat_jid", "")
+ if not message_ids or not chat_jid:
+ return {"success": False, "error": "message_ids (array) and chat_jid are required"}
+ params: Dict[str, Any] = {"message_ids": message_ids, "chat_jid": chat_jid}
+ if sender_jid := data.get("sender_jid"):
+ params["sender_jid"] = sender_jid
+ return await _wa_rpc_call("mark_read", params)
+
+
+async def handle_whatsapp_typing(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Send typing indicator. Schema: typing({jid, state: 'composing'|'paused', media?})."""
+ jid = data.get("jid", "")
+ if not jid:
+ return {"success": False, "error": "jid is required"}
+ params: Dict[str, Any] = {"jid": jid, "state": data.get("state", "composing")}
+ if media := data.get("media"):
+ params["media"] = media
+ return await _wa_rpc_call("typing", params)
+
+
+async def handle_whatsapp_presence(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Set online/offline presence. Schema: presence({status: 'available'|'unavailable'})."""
+ return await _wa_rpc_call("presence", {"status": data.get("status", "available")})
+
+
+async def handle_whatsapp_stop(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Graceful WhatsApp shutdown."""
+ return await _wa_rpc_call("stop", {})
+
+
+async def handle_whatsapp_diagnostics(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
+ """Get WhatsApp diagnostics / debug info."""
+ return await _wa_rpc_call("diagnostics", {})
+
+
+# Dispatch table consumed by ``services.ws_handler_registry`` —
+# ``__init__.py`` registers this dict on package import. Ordering
+# preserved from the legacy ``MESSAGE_HANDLERS`` block in
+# ``routers/websocket.py`` so the wire surface is byte-identical.
+WS_HANDLERS = {
+ "whatsapp_status": handle_whatsapp_status,
+ "whatsapp_connected_phone": handle_whatsapp_connected_phone,
+ "whatsapp_qr": handle_whatsapp_qr,
+ "whatsapp_send": handle_whatsapp_send,
+ "whatsapp_start": handle_whatsapp_start,
+ "whatsapp_restart": handle_whatsapp_restart,
+ "whatsapp_groups": handle_whatsapp_groups,
+ "whatsapp_group_info": handle_whatsapp_group_info,
+ "whatsapp_chat_history": handle_whatsapp_chat_history,
+ "whatsapp_newsletters": handle_whatsapp_newsletters,
+ "whatsapp_rate_limit_get": handle_whatsapp_rate_limit_get,
+ "whatsapp_rate_limit_set": handle_whatsapp_rate_limit_set,
+ "whatsapp_rate_limit_stats": handle_whatsapp_rate_limit_stats,
+ "whatsapp_rate_limit_unpause": handle_whatsapp_rate_limit_unpause,
+ "whatsapp_mark_read": handle_whatsapp_mark_read,
+ "whatsapp_typing": handle_whatsapp_typing,
+ "whatsapp_presence": handle_whatsapp_presence,
+ "whatsapp_stop": handle_whatsapp_stop,
+ "whatsapp_diagnostics": handle_whatsapp_diagnostics,
+}
diff --git a/server/nodes/whatsapp/_runtime.py b/server/nodes/whatsapp/_runtime.py
index a3322938..bb7c96e6 100644
--- a/server/nodes/whatsapp/_runtime.py
+++ b/server/nodes/whatsapp/_runtime.py
@@ -3,7 +3,7 @@
Spawns the binary with cwd inside the project (``<data_dir>/whatsapp``)
so the SQLite session DB lives next to ``credentials.db`` and survives
``pnpm install``, version bumps, and worktree switches. Lazy-init from
-``services.whatsapp_service.get_client()``; teardown from FastAPI lifespan.
+``nodes.whatsapp._service.get_client()``; teardown from FastAPI lifespan.
Subclasses :class:`BaseProcessSupervisor` for spawning, tree-kill, status
snapshots, restart policy, and the singleton ``get_instance()`` accessor.
diff --git a/server/services/whatsapp_service.py b/server/nodes/whatsapp/_service.py
similarity index 100%
rename from server/services/whatsapp_service.py
rename to server/nodes/whatsapp/_service.py
diff --git a/server/routers/websocket.py b/server/routers/websocket.py
index 61a1f9a6..da5d16f4 100644
--- a/server/routers/websocket.py
+++ b/server/routers/websocket.py
@@ -1902,142 +1902,6 @@ async def handle_android_relay_reconnect(data: Dict[str, Any], websocket: WebSoc
# this router.
# ----------------------------------------------------------------------------
-# ============================================================================
-# WhatsApp Handlers - Wrappers for services.whatsapp_service functions
-# ============================================================================
-
-from services.whatsapp_service import (
- handle_whatsapp_status as _wa_status,
- handle_whatsapp_connected_phone as _wa_connected_phone,
- handle_whatsapp_qr as _wa_qr,
- handle_whatsapp_send as _wa_send,
- handle_whatsapp_start as _wa_start,
- handle_whatsapp_restart as _wa_restart,
- handle_whatsapp_groups as _wa_groups,
- handle_whatsapp_group_info as _wa_group_info,
- handle_whatsapp_chat_history as _wa_chat_history,
- handle_whatsapp_newsletters as _wa_newsletters,
- whatsapp_rpc_call as _wa_rpc_call,
-)
-
-
-async def handle_whatsapp_status(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- return await _wa_status()
-
-
-async def handle_whatsapp_connected_phone(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Get the connected WhatsApp phone number."""
- return await _wa_connected_phone()
-
-
-async def handle_whatsapp_qr(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- return await _wa_qr()
-
-
-async def handle_whatsapp_send(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Forward all send params to WhatsApp handler - supports all message types."""
- return await _wa_send(data)
-
-
-async def handle_whatsapp_start(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- return await _wa_start()
-
-
-async def handle_whatsapp_restart(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- return await _wa_restart()
-
-
-async def handle_whatsapp_groups(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- return await _wa_groups()
-
-
-async def handle_whatsapp_newsletters(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Get list of subscribed newsletter channels."""
- return await _wa_newsletters()
-
-
-async def handle_whatsapp_group_info(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Get group participants with resolved phone numbers."""
- group_id = data.get("group_id", "")
- return await _wa_group_info(group_id)
-
-
-async def handle_whatsapp_chat_history(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Get chat history from WhatsApp history store."""
- return await _wa_chat_history(data)
-
-
-async def handle_whatsapp_rate_limit_get(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Get rate limit config and current stats."""
- result = await _wa_rpc_call("rate_limit_get", {})
- return result
-
-
-async def handle_whatsapp_rate_limit_set(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Update rate limit configuration."""
- config = data.get("config", {})
- result = await _wa_rpc_call("rate_limit_set", config)
- return result
-
-
-async def handle_whatsapp_rate_limit_stats(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Get current rate limit statistics."""
- result = await _wa_rpc_call("rate_limit_stats", {})
- return result
-
-
-async def handle_whatsapp_rate_limit_unpause(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Resume rate limiting after automatic pause."""
- result = await _wa_rpc_call("rate_limit_unpause", {})
- return result
-
-
-async def handle_whatsapp_mark_read(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Mark messages as read. Schema: mark_read({message_ids, chat_jid, sender_jid?})"""
- message_ids = data.get("message_ids", [])
- chat_jid = data.get("chat_jid", "")
- if not message_ids or not chat_jid:
- return {"success": False, "error": "message_ids (array) and chat_jid are required"}
- params: Dict[str, Any] = {"message_ids": message_ids, "chat_jid": chat_jid}
- sender_jid = data.get("sender_jid")
- if sender_jid:
- params["sender_jid"] = sender_jid
- result = await _wa_rpc_call("mark_read", params)
- return result
-
-
-async def handle_whatsapp_typing(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Send typing indicator. Schema: typing({jid, state: 'composing'|'paused', media?})"""
- jid = data.get("jid", "")
- state = data.get("state", "composing")
- if not jid:
- return {"success": False, "error": "jid is required"}
- params: Dict[str, Any] = {"jid": jid, "state": state}
- media = data.get("media")
- if media:
- params["media"] = media
- result = await _wa_rpc_call("typing", params)
- return result
-
-
-async def handle_whatsapp_presence(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Set online/offline presence. Schema: presence({status: 'available'|'unavailable'})"""
- status = data.get("status", "available")
- result = await _wa_rpc_call("presence", {"status": status})
- return result
-
-
-async def handle_whatsapp_stop(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Graceful WhatsApp shutdown."""
- result = await _wa_rpc_call("stop", {})
- return result
-
-
-async def handle_whatsapp_diagnostics(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:
- """Get WhatsApp diagnostics/debug info."""
- result = await _wa_rpc_call("diagnostics", {})
- return result
-
# ============================================================================
# Plugin-owned WS handlers (telegram, future plugins, ...) live in their
@@ -3269,25 +3133,6 @@ MESSAGE_HANDLERS: Dict[str, MessageHandler] = {
# ``validate_api_key`` for all providers.
# WhatsApp operations
- "whatsapp_status": handle_whatsapp_status,
- "whatsapp_connected_phone": handle_whatsapp_connected_phone,
- "whatsapp_qr": handle_whatsapp_qr,
- "whatsapp_send": handle_whatsapp_send,
- "whatsapp_start": handle_whatsapp_start,
- "whatsapp_restart": handle_whatsapp_restart,
- "whatsapp_groups": handle_whatsapp_groups,
- "whatsapp_newsletters": handle_whatsapp_newsletters,
- "whatsapp_group_info": handle_whatsapp_group_info,
- "whatsapp_chat_history": handle_whatsapp_chat_history,
- "whatsapp_rate_limit_get": handle_whatsapp_rate_limit_get,
- "whatsapp_rate_limit_set": handle_whatsapp_rate_limit_set,
- "whatsapp_rate_limit_stats": handle_whatsapp_rate_limit_stats,
- "whatsapp_rate_limit_unpause": handle_whatsapp_rate_limit_unpause,
- "whatsapp_mark_read": handle_whatsapp_mark_read,
- "whatsapp_typing": handle_whatsapp_typing,
- "whatsapp_presence": handle_whatsapp_presence,
- "whatsapp_stop": handle_whatsapp_stop,
- "whatsapp_diagnostics": handle_whatsapp_diagnostics,
# Telegram operations live in nodes/telegram/_handlers.py and
# self-register via services.ws_handler_registry. Dispatch hits them
diff --git a/server/services/node_option_loaders/whatsapp_loaders.py b/server/services/node_option_loaders/whatsapp_loaders.py
index e2763683..7c58bb6f 100644
--- a/server/services/node_option_loaders/whatsapp_loaders.py
+++ b/server/services/node_option_loaders/whatsapp_loaders.py
@@ -18,7 +18,7 @@ from typing import Any
async def load_whatsapp_groups(params: dict[str, Any]) -> list[dict[str, Any]]:
"""List WhatsApp groups for the recipient_type='group' selector."""
- from services.whatsapp_service import handle_whatsapp_groups as _wa_groups
+ from nodes.whatsapp._service import handle_whatsapp_groups as _wa_groups
response = await _wa_groups()
groups = response.get("groups", []) if isinstance(response, dict) else []
@@ -34,7 +34,7 @@ async def load_whatsapp_groups(params: dict[str, Any]) -> list[dict[str, Any]]:
async def load_whatsapp_channels(params: dict[str, Any]) -> list[dict[str, Any]]:
"""List subscribed newsletter channels for the channel_jid selector."""
- from services.whatsapp_service import handle_whatsapp_newsletters as _wa_newsletters
+ from nodes.whatsapp._service import handle_whatsapp_newsletters as _wa_newsletters
response = await _wa_newsletters()
channels = response.get("newsletters", []) if isinstance(response, dict) else []
@@ -51,7 +51,7 @@ async def load_whatsapp_group_members(params: dict[str, Any]) -> list[dict[str,
"""List members of a specific WhatsApp group for the senderNumber
selector. Depends on ``params['group_id']``."""
- from services.whatsapp_service import handle_whatsapp_group_info as _wa_group_info
+ from nodes.whatsapp._service import handle_whatsapp_group_info as _wa_group_info
group_id = params.get("group_id") or ""
if not group_id:
diff --git a/server/services/status_broadcaster.py b/server/services/status_broadcaster.py
index 777ec9cc..5b76f570 100644
--- a/server/services/status_broadcaster.py
+++ b/server/services/status_broadcaster.py
@@ -323,7 +323,7 @@ class StatusBroadcaster:
"""
with tracer.start_as_current_span("broadcaster.refresh_whatsapp") as span:
try:
- from services.whatsapp_service import get_client
+ from nodes.whatsapp._service import get_client
import time
client = await get_client()
diff --git a/server/tests/nodes/test_telegram_social.py b/server/tests/nodes/test_telegram_social.py
index 1304fcbc..d821dad0 100644
--- a/server/tests/nodes/test_telegram_social.py
+++ b/server/tests/nodes/test_telegram_social.py
@@ -355,7 +355,7 @@ class TestSocialSend:
return_value={"success": True, "message_id": "wamid.xyz"}
)
- with patch("services.whatsapp_service.handle_whatsapp_send", whatsapp_send):
+ with patch("nodes.whatsapp._service.handle_whatsapp_send", whatsapp_send):
result = await harness.execute(
"socialSend",
{
@@ -385,7 +385,7 @@ class TestSocialSend:
# recipientType=phone but no phone param -> ValueError inside handler
whatsapp_send = AsyncMock()
- with patch("services.whatsapp_service.handle_whatsapp_send", whatsapp_send):
+ with patch("nodes.whatsapp._service.handle_whatsapp_send", whatsapp_send):
result = await harness.execute(
"socialSend",
{
@@ -404,7 +404,7 @@ class TestSocialSend:
# Any non-whatsapp channel should surface as a failed envelope.
whatsapp_send = AsyncMock()
- with patch("services.whatsapp_service.handle_whatsapp_send", whatsapp_send):
+ with patch("nodes.whatsapp._service.handle_whatsapp_send", whatsapp_send):
result = await harness.execute(
"socialSend",
{
@@ -425,7 +425,7 @@ class TestSocialSend:
return_value={"success": False, "error": "rpc boom"}
)
- with patch("services.whatsapp_service.handle_whatsapp_send", whatsapp_send):
+ with patch("nodes.whatsapp._service.handle_whatsapp_send", whatsapp_send):
result = await harness.execute(
"socialSend",
{
diff --git a/server/tests/nodes/test_whatsapp.py b/server/tests/nodes/test_whatsapp.py
index b9b90b7e..7758b7a7 100644
--- a/server/tests/nodes/test_whatsapp.py
+++ b/server/tests/nodes/test_whatsapp.py
@@ -5,9 +5,9 @@ These tests freeze the input -> output behaviour documented in
to the Go `whatsapp-rpc` service via a WebSocket RPC client in
`routers/whatsapp.py`. We patch the two entry points the handlers use:
- - `services.whatsapp_service.handle_whatsapp_send` - sending messages
- - `services.whatsapp_service.whatsapp_rpc_call` - generic RPC calls
- - `services.whatsapp_service.handle_whatsapp_chat_history` - chat history RPC
+ - `nodes.whatsapp._service.handle_whatsapp_send` - sending messages
+ - `nodes.whatsapp._service.whatsapp_rpc_call` - generic RPC calls
+ - `nodes.whatsapp._service.handle_whatsapp_chat_history` - chat history RPC
For `whatsappReceive` we use the same event-waiter stub pattern as
`test_telegram_social.py` - patching the module reference imported by both
@@ -32,15 +32,15 @@ pytestmark = pytest.mark.node_contract
def _patch_whatsapp_send(return_value):
- """Patch services.whatsapp_service.handle_whatsapp_send at the import site."""
+ """Patch nodes.whatsapp._service.handle_whatsapp_send at the import site."""
return patch(
- "services.whatsapp_service.handle_whatsapp_send",
+ "nodes.whatsapp._service.handle_whatsapp_send",
new=AsyncMock(return_value=return_value),
)
def _patch_rpc_call(return_value=None, *, side_effect=None):
- """Patch services.whatsapp_service.whatsapp_rpc_call.
+ """Patch nodes.whatsapp._service.whatsapp_rpc_call.
``return_value`` may be a dict or list. ``side_effect`` may be a callable
for per-method routing.
@@ -50,12 +50,12 @@ def _patch_rpc_call(return_value=None, *, side_effect=None):
kwargs["side_effect"] = side_effect
else:
kwargs["return_value"] = return_value if return_value is not None else {}
- return patch("services.whatsapp_service.whatsapp_rpc_call", new=AsyncMock(**kwargs))
+ return patch("nodes.whatsapp._service.whatsapp_rpc_call", new=AsyncMock(**kwargs))
def _patch_chat_history_handler(return_value):
return patch(
- "services.whatsapp_service.handle_whatsapp_chat_history",
+ "nodes.whatsapp._service.handle_whatsapp_chat_history",
new=AsyncMock(return_value=return_value),
)
@@ -95,7 +95,7 @@ class TestWhatsappSend:
return {"success": True}
with patch(
- "services.whatsapp_service.handle_whatsapp_send",
+ "nodes.whatsapp._service.handle_whatsapp_send",
new=AsyncMock(side_effect=fake_send),
), patch(
"services.markdown_formatter.to_whatsapp",