@open-wa/node-red 5.1.0 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +66 -39
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,72 +1,99 @@
1
1
  # @open-wa/node-red
2
2
 
3
- Official @open-wa node-red integration.
3
+ `@open-wa/node-red` connects Node-RED flows to an existing open-wa Easy API session. The current package is `5.1.0` and registers three node types: `owa-server`, `cmd`, and `listen`.
4
4
 
5
- Part of the [@open-wa v5 monorepo](https://github.com/open-wa/wa-automate-nodejs).
5
+ The integration keeps the Node-RED palette small and maps commands and events to the Easy API metadata endpoints. It uses `@open-wa/socket-client` as the compatibility client; v5 commands travel over HTTP RPC and runtime events use the client event stream.
6
6
 
7
- ## What it does
7
+ ## Quick start
8
8
 
9
- `@open-wa/node-red` provides Node-RED nodes for connecting flows to a remote open-wa Easy API session. The package registers three Node-RED node types from `package.json`: `owa-server`, `cmd`, and `listen`.
9
+ Start Easy API separately, then install the package into Node-RED's user directory:
10
10
 
11
- Use this integration so Node-RED can call open-wa commands or react to events through an Easy API server connection.
11
+ ```bash
12
+ npx @open-wa/wa-automate@5.1.0 \
13
+ --session-id sales \
14
+ --port 8080 \
15
+ --api-key "$OPENWA_API_KEY"
12
16
 
13
- Legacy compatibility note: this integration uses `@open-wa/socket-client`. The active v5 runtime uses HTTP RPC and SSE instead of direct Socket.IO. Do not use `SocketManager` from `@open-wa/api` with current releases.
17
+ cd ~/.node-red
18
+ npm install @open-wa/node-red@5.1.0
19
+ node-red
20
+ ```
21
+
22
+ Open `http://127.0.0.1:1880`, choose **Manage palette**, and confirm `@open-wa/node-red` is installed. Add an **owa-server** configuration node with the Easy API URL and the same key passed to `--api-key`. Leave the key empty only when Easy API was started without one.
23
+
24
+ The configuration node keeps the `SocketClient` in Node-RED global context. It reports `connected`, `disconnected`, and connection-error states so a flow can distinguish a stopped API from a command failure.
14
25
 
15
26
  ## Node types
16
27
 
17
- | Node type | Source-visible behavior |
18
- | --- | --- |
19
- | `owa-server` | Configuration node that stores `name`, `url`, and `key`, creates a `SocketClient`, exposes its socket-like connection object, and stores the client in Node-RED global context. It emits and reports connected, disconnected, and connect error status changes. |
20
- | `cmd` | Executes a selected open-wa command against the configured server. It loads command metadata from `/meta/basic/commands`, accepts `method` and `args` from the incoming message or node config, calls `server.client.ask(method, args)`, and supports a timeout in seconds. |
21
- | `listen` | Registers an event listener against the configured server. It loads listener names from `/meta/basic/listeners`, calls `client.listen(listener, listenerFn)`, sends received event data as `msg.payload`, and stops the listener on node close. |
28
+ | Palette label | Runtime type | Behavior |
29
+ | --- | --- | --- |
30
+ | **owa-server** | `owa-server` | Stores `name`, `url`, and optional `key`, creates a `SocketClient`, and owns the connection lifecycle. |
31
+ | **Command** | `cmd` | Loads command metadata from `/meta/basic/commands`, then calls `client.ask(method, args)` with node or message values. |
32
+ | **Listen** | `listen` | Loads listener names from `/meta/basic/listeners`, subscribes with `client.listen(listener, callback)`, and emits event data as `msg.payload`. |
22
33
 
23
- ## Configuration fields
34
+ The visible labels are **Command** and **Listen**. Older guides that describe separate Send, Receive, Session, or Media nodes refer to `@open-wa/node-red-contrib-wa-automate`, which is a different package and palette.
24
35
 
25
- The visible editor templates and runtime source define these fields.
36
+ ## Configuration fields
26
37
 
27
38
  ### `owa-server`
28
39
 
29
- - `name`: Node-RED display name and status payload socket ID.
30
- - `url`: Base URL for the remote open-wa Easy API server.
31
- - `key`: Optional API key sent as `X-API-Key` when loading command and listener metadata and passed to `SocketClient`.
40
+ - `name`: Node-RED display name.
41
+ - `url`: Easy API base URL, such as `http://127.0.0.1:8080`.
42
+ - `key`: Optional API key. The editor sends it as `X-API-Key` while loading command and listener metadata, and the client uses it for runtime requests.
32
43
 
33
44
  ### `cmd`
34
45
 
35
- - `server`: Reference to an `owa-server` config node.
36
- - `method`: Command method to call when the incoming message does not provide `msg.method`.
37
- - `args`: JSON-like command arguments merged with object-like `msg.payload` values when present.
38
- - `name`: Node-RED display name.
39
- - `timeout`: Timeout in seconds. The runtime treats `-1` as no timeout and falls back to 30 seconds when parsing fails.
46
+ - `server`: The **owa-server** configuration node.
47
+ - `method`: Command name, such as `sendText`.
48
+ - `args`: JSON arguments. Message values in `msg.method` and `msg.args` take precedence; object-like `msg.payload` is merged when configured arguments are object-like.
49
+ - `timeout`: Seconds. Invalid or empty values fall back to 30 seconds; `-1` intentionally disables the command timeout.
50
+
51
+ For `sendText`, the command arguments can be an object:
52
+
53
+ ```json
54
+ {
55
+ "to": "1234567890@c.us",
56
+ "content": "Hello from Node-RED"
57
+ }
58
+ ```
40
59
 
41
60
  ### `listen`
42
61
 
43
- - `server`: Reference to an `owa-server` config node.
44
- - `listener`: Listener name to register.
62
+ - `server`: The **owa-server** configuration node.
63
+ - `listener`: Listener name, for example `onMessage`.
45
64
  - `name`: Node-RED display name.
46
65
 
47
- ## Runtime behavior
66
+ The listener stops when its node closes or its server disconnects. A session that is not authenticated or ready cannot emit WhatsApp events even when Node-RED itself is running.
67
+
68
+ ## Connection checks
69
+
70
+ Use the same URL and key outside Node-RED to separate API reachability, authentication, and session readiness:
71
+
72
+ ```bash
73
+ curl -sS -D - \
74
+ -H "X-API-Key: $OPENWA_API_KEY" \
75
+ http://127.0.0.1:8080/health
48
76
 
49
- - `owa-server` constructs `new SocketClient(url, key)`, stores it under the node ID in the global `CLIENT_STORE`, and removes it on disconnect or node removal.
50
- - `cmd` uses `/meta/basic/commands` to populate command options in the editor. At runtime it prefers `msg.method` and `msg.args`, otherwise it parses configured args and `msg.payload`, then sends the result with `client.ask`.
51
- - `cmd` reports `Executing..`, `Done`, timeout, waiting, and missing server states through Node-RED node status.
52
- - `listen` uses `/meta/basic/listeners` to populate listener options in the editor. It registers once per node instance, forwards listener messages as `payload`, reports connection status, and calls `stopListener` on close.
77
+ curl -sS -D - \
78
+ -H "X-API-Key: $OPENWA_API_KEY" \
79
+ http://127.0.0.1:8080/meta/basic/commands
80
+ ```
81
+
82
+ A connection refusal means the URL or process is wrong. `401` means the configured key is absent or different. A `200` health response with `connected: false` or `session.ready: false` means Node-RED can reach Easy API but the WhatsApp session still needs authentication or readiness work.
53
83
 
54
84
  ## Development
55
85
 
56
- - `pnpm --filter @open-wa/node-red add-node`
57
- - `pnpm --filter @open-wa/node-red copy`
58
- - `pnpm --filter @open-wa/node-red build:editor`
59
- - `pnpm --filter @open-wa/node-red build:runtime`
60
- - `pnpm --filter @open-wa/node-red build`
61
- - `pnpm --filter @open-wa/node-red dev`
62
- - `pnpm --filter @open-wa/node-red lint`
63
- - `pnpm --filter @open-wa/node-red lint:fix`
64
- - `pnpm --filter @open-wa/node-red test`
65
- - `pnpm --filter @open-wa/node-red test:watch`
86
+ From the monorepo checkout:
87
+
88
+ ```bash
89
+ pnpm --filter @open-wa/node-red dev
90
+ ```
91
+
92
+ The package source lives under `integrations/node-red`; the published Node-RED entrypoints are the `dist/nodes/*` files declared in `package.json`.
66
93
 
67
94
  ## Documentation
68
95
 
69
- See the [docs site](https://openwa.dev).
96
+ See the [Node-RED guide](https://openwa.dev/docs/guides/node-red) for the importable echo flow and the full troubleshooting journey.
70
97
 
71
98
  ## License
72
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/node-red",
3
- "version": "5.1.0",
3
+ "version": "5.3.0",
4
4
  "description": "Official @open-wa node-red integration.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -55,9 +55,9 @@
55
55
  "yarpm": "^1.2.0"
56
56
  },
57
57
  "dependencies": {
58
- "@open-wa/schema": "5.1.0",
59
- "@open-wa/socket-client": "5.1.0",
60
- "@open-wa/wa-automate-types-only": "5.1.0"
58
+ "@open-wa/schema": "5.3.0",
59
+ "@open-wa/socket-client": "5.3.0",
60
+ "@open-wa/wa-automate-types-only": "5.3.0"
61
61
  },
62
62
  "scripts": {
63
63
  "add-node": "node ./utils/add-node.js",