Skip to content

Self-improving AI Employees for everyone

fix(whatsapp): align trigger Run output with deploy, give each node its icon

trohitg7582506b64a1
diff --git a/server/nodes/whatsapp_business/icon.svg b/server/nodes/whatsapp_business/icon.svg
deleted file mode 100644
index c2df5a87..00000000
--- a/server/nodes/whatsapp_business/icon.svg
+++ /dev/null
@@ -1 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#25D366"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/></svg>
diff --git a/server/nodes/whatsapp_business/icon_whatsappBusinessSend.svg b/server/nodes/whatsapp_business/icon_whatsappBusinessSend.svg
deleted file mode 100644
index 42f8b042..00000000
--- a/server/nodes/whatsapp_business/icon_whatsappBusinessSend.svg
+++ /dev/null
@@ -1 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#25D366"><path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/></svg>
diff --git a/server/nodes/whatsapp_business/meta.json b/server/nodes/whatsapp_business/meta.json
index 550bea1d..6128e276 100644
--- a/server/nodes/whatsapp_business/meta.json
+++ b/server/nodes/whatsapp_business/meta.json
@@ -1 +1,9 @@
-{"color": "#128C7E"}
+{
+ "color": "#128C7E",
+ "icons": {
+ "whatsappBusinessSend": "lucide:Send",
+ "whatsappBusinessMedia": "lucide:Paperclip",
+ "whatsappBusinessReceive": "lucide:Inbox",
+ "whatsappBusinessStatus": "lucide:CheckCheck"
+ }
+}
diff --git a/server/nodes/whatsapp_business/whatsapp_business_receive.py b/server/nodes/whatsapp_business/whatsapp_business_receive.py
index 9b247d26..e8f064d3 100644
--- a/server/nodes/whatsapp_business/whatsapp_business_receive.py
+++ b/server/nodes/whatsapp_business/whatsapp_business_receive.py
@@ -1,10 +1,21 @@
"""Inbound triggers for the WhatsApp Cloud API.
-Two nodes rather than one with a mode switch. Per-node filters are not
-applied on the deployed push path -- only the CloudEvents type is -- so a
-``trigger_on: messages | statuses`` parameter would work when you press Run
-and silently fire on everything once deployed. Separate node types get
-separate type strings, which is the discriminator that actually works.
+Two nodes rather than one with a mode switch, for two reasons that
+outlived the original one.
+
+The original reason was that per-node filters were not applied on the
+deployed push path, so a ``trigger_on: messages | statuses`` parameter
+would work on Run and silently fire on everything once deployed. That is
+no longer true -- the node's filter now gates the spawn (see
+``machina-trigger-listener-node-filter``) -- but the split still stands:
+
+ * The CloudEvents type is the routing key. A canary trigger registers
+ exactly one type (``canary_registry`` is a str-to-str map and the
+ listener carries a single ``EventType`` keyword Search Attribute), so
+ one merged node could only subscribe to one of the two.
+ * The payloads are genuinely different shapes. An inbound message and a
+ delivery receipt share almost no fields, so merging would mean a union
+ output schema and weaker ``{{trigger.field}}`` resolution downstream.
"""
from __future__ import annotations
@@ -96,19 +107,19 @@ class WhatsAppBusinessStatusOutput(BaseModel):
model_config = ConfigDict(extra="allow")
-class WhatsAppBusinessReceiveNode(WebhookTriggerNode):
- type = "whatsappBusinessReceive"
- display_name = "WhatsApp Business Receive"
- subtitle = "Inbound message"
+class _WhatsAppBusinessTrigger(WebhookTriggerNode, abstract=True):
+ """Everything both inbound triggers share.
+
+ ``abstract=True`` keeps ``__init_subclass__`` from registering this as
+ a node; only the two concrete subclasses below appear on the canvas.
+ """
+
group = ("whatsapp_business", "trigger")
- description = "Trigger when a WhatsApp user messages your business number"
component_kind = "trigger"
handles = _OUTPUT_HANDLE
credentials = (WhatsAppBusinessCredential,)
webhook_source = WhatsAppBusinessWebhookSource
- event_type_prefix = "com.opencompany.whatsapp_business.message."
Params = BaseTriggerParams
- Output = WhatsAppBusinessReceiveOutput
async def _check_precondition(self) -> Optional[str]:
"""Fail fast on the canvas instead of waiting out the 24h timeout."""
@@ -126,24 +137,39 @@ class WhatsAppBusinessReceiveNode(WebhookTriggerNode):
)
return None
+ def shape_output(self, event: WorkflowEvent) -> Dict:
+ """Emit the flat payload, which is what the deployed path emits.
+
+ ``TriggerListenerWorkflow`` hands downstream nodes ``event.data``,
+ while the base default dumps the whole CloudEvents envelope. Without
+ this override ``{{trigger.text}}`` resolves once deployed and breaks
+ when you press Run, and the Run output does not match the declared
+ ``Output`` model.
+
+ The shaping itself already happened in the webhook source, so this
+ only unwraps -- deliberately, so the two paths cannot drift into
+ producing different fields.
+ """
+ return event.data if isinstance(event.data, dict) else {}
+
+
+class WhatsAppBusinessReceiveNode(_WhatsAppBusinessTrigger):
+ type = "whatsappBusinessReceive"
+ display_name = "WhatsApp Business Receive"
+ subtitle = "Inbound message"
+ description = "Trigger when a WhatsApp user messages your business number"
+ event_type_prefix = "com.opencompany.whatsapp_business.message."
+ Output = WhatsAppBusinessReceiveOutput
+
-class WhatsAppBusinessStatusNode(WebhookTriggerNode):
+class WhatsAppBusinessStatusNode(_WhatsAppBusinessTrigger):
type = "whatsappBusinessStatus"
display_name = "WhatsApp Business Status"
subtitle = "Delivery status"
- group = ("whatsapp_business", "trigger")
description = "Trigger on sent / delivered / read / failed callbacks for messages you sent"
- component_kind = "trigger"
- handles = _OUTPUT_HANDLE
- credentials = (WhatsAppBusinessCredential,)
- webhook_source = WhatsAppBusinessWebhookSource
event_type_prefix = "com.opencompany.whatsapp_business.status."
- Params = BaseTriggerParams
Output = WhatsAppBusinessStatusOutput
- async def _check_precondition(self) -> Optional[str]:
- return await WhatsAppBusinessReceiveNode._check_precondition(self) # type: ignore[arg-type]
-
__all__ = [
"WhatsAppBusinessReceiveNode",
diff --git a/server/tests/nodes/test_whatsapp_business.py b/server/tests/nodes/test_whatsapp_business.py
index e5992683..ecf1cf9a 100644
--- a/server/tests/nodes/test_whatsapp_business.py
+++ b/server/tests/nodes/test_whatsapp_business.py
@@ -379,6 +379,81 @@ class TestAbsorbedTemplateAndInteractive:
assert "context" not in captured["body"]
+class TestRunAndDeployAgreeOnOutputShape:
+ """The deployed path hands downstream nodes ``event.data`` flat, while
+ the base ``shape_output`` dumps the whole CloudEvents envelope. Without
+ an override, ``{{trigger.text}}`` resolves when deployed and breaks on
+ Run, and the Run output does not match the declared Output model."""
+
+ def _event(self):
+ from services.events import WorkflowEvent
+
+ return WorkflowEvent(
+ source="opencompany://test",
+ type="com.opencompany.whatsapp_business.message.received",
+ data={"message_id": "wamid.1", "text": "hi"},
+ )
+
+ @pytest.mark.parametrize(
+ "node_cls_name",
+ ["WhatsAppBusinessReceiveNode", "WhatsAppBusinessStatusNode"],
+ )
+ def test_shape_output_is_the_flat_payload(self, node_cls_name):
+ import nodes.whatsapp_business.whatsapp_business_receive as mod
+
+ node = getattr(mod, node_cls_name)()
+ shaped = node.shape_output(self._event())
+ assert shaped == {"message_id": "wamid.1", "text": "hi"}
+ # The envelope members must not leak into the trigger output.
+ for envelope_only in ("specversion", "id", "source", "type", "data"):
+ assert envelope_only not in shaped
+
+ def test_both_triggers_share_one_implementation(self):
+ """They inherit it, so the two paths cannot drift apart."""
+ import nodes.whatsapp_business.whatsapp_business_receive as mod
+
+ assert (
+ mod.WhatsAppBusinessReceiveNode.shape_output
+ is mod.WhatsAppBusinessStatusNode.shape_output
+ )
+
+ def test_the_shared_base_is_not_itself_a_node(self):
+ from models.node_metadata import NODE_METADATA
+
+ assert "_WhatsAppBusinessTrigger" not in NODE_METADATA
+
+
+class TestIconsComeFromTheLibraryNotVendoredArtwork:
+ def test_each_node_type_gets_a_distinct_icon(self):
+ """All four rendered the same glyph before: only Send shipped a
+ per-node SVG, so the rest fell back to the folder's shared one."""
+ from services.node_spec import get_node_spec
+
+ icons = {}
+ for node_type in (
+ "whatsappBusinessSend",
+ "whatsappBusinessMedia",
+ "whatsappBusinessReceive",
+ "whatsappBusinessStatus",
+ ):
+ spec = get_node_spec(node_type)
+ data = spec if isinstance(spec, dict) else spec.model_dump(mode="json")
+ icons[node_type] = data["icon"]
+
+ assert all(icon.startswith("lucide:") for icon in icons.values())
+ assert len(set(icons.values())) == len(icons)
+
+ def test_no_vendored_node_svgs_remain(self):
+ """The credential icon stays -- it resolves through a different
+ chain (Credential.get_icon_path) and is a brand mark lucide has no
+ equivalent for."""
+ import pathlib
+
+ folder = pathlib.Path(__file__).resolve().parents[2] / "nodes" / "whatsapp_business"
+ svgs = {p.name for p in folder.glob("*.svg")}
+ assert svgs == {"whatsapp_business.svg"}
+
+
class TestFileWidgetVisibility:
def test_media_picker_is_gated_on_operation_as_well_as_source(self):
"""media_source defaults to "file", so keying on it alone rendered the
@@ -467,23 +542,7 @@ class TestModelCannotChooseTheSendingNumber:
class TestSendText:
def _send(self, params, *, number="PN1"):
- node = WhatsAppBusinessSendNode()
- captured = {}
-
- async def _fake_post(ctx, path, body=None, **kwargs):
- captured["path"] = path
- captured["body"] = body
- return {"messages": [{"id": "wamid.X"}], "contacts": [{"wa_id": "1"}]}
-
- with (
- patch("nodes.whatsapp_business.whatsapp_business_send.graph_post", new=_fake_post),
- patch(
- "services.plugin.deps.get_auth_service",
- return_value=SimpleNamespace(get_api_key=AsyncMock(return_value=number)),
- ),
- ):
- _run(node.execute("wac-1", {"operation": "send_text", **params}, _ctx()))
- return captured
+ return _capture({"operation": "send_text", **params}, number=number)
def test_builds_the_documented_text_envelope(self):
captured = self._send({"to": "+1 (415) 555-1234", "text": "hello", "format_markdown": False})
@@ -514,28 +573,14 @@ class TestSendText:
def test_oversize_body_is_refused_not_truncated(self):
"""Silently dropping the tail of a business message is worse than
failing."""
- node = WhatsAppBusinessSendNode()
- with patch(
- "services.plugin.deps.get_auth_service",
- return_value=SimpleNamespace(get_api_key=AsyncMock(return_value="PN1")),
- ):
- envelope = _run(
- node.execute(
- "wac-1",
- {"operation": "send_text", "to": "+14155551234", "text": "a" * 5000, "format_markdown": False},
- _ctx(),
- )
- )
+ envelope = self._send(
+ {"to": "+14155551234", "text": "a" * 5000, "format_markdown": False}
+ )["envelope"]
assert envelope["success"] is False
assert "4096" in envelope["error"]
def test_empty_body_is_refused(self):
- node = WhatsAppBusinessSendNode()
- with patch(
- "services.plugin.deps.get_auth_service",
- return_value=SimpleNamespace(get_api_key=AsyncMock(return_value="PN1")),
- ):
- envelope = _run(node.execute("wac-1", {"operation": "send_text", "to": "+14155551234", "text": " "}, _ctx()))
+ envelope = self._send({"to": "+14155551234", "text": " "})["envelope"]
assert envelope["success"] is False