@jep182/n8n-nodes-whatsthat 0.4.2 → 0.4.3

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.
package/README.md CHANGED
@@ -17,8 +17,8 @@ It lets you:
17
17
 
18
18
  Use this node to:
19
19
 
20
- - create a session
21
20
  - connect a session
21
+ - wait for a session to become connected
22
22
  - list sessions
23
23
  - inspect session status
24
24
  - disconnect a session
@@ -86,14 +86,15 @@ WhatsThat embeds Baileys directly in n8n.
86
86
  ```
87
87
 
88
88
  3. Add `WhatsThat Session`.
89
- 4. Choose `Ensure Session`, then provide:
89
+ 4. Choose `Connect Session`, then provide:
90
90
  - `Session ID (Internal)`: a stable unique ID such as `main-phone`
91
91
  - `Label (Visible Name)`: a human-readable name such as `Luca personal phone`
92
92
  - optional `Phone Number For Pairing`: full number with country code, digits only, without `00` or `+`
93
- 5. Set `Return When` to `Pairing Is Ready Or Connected` for first-time pairing.
94
- 6. Use the returned `pairingCode`, `qrCodeUrl`, or `qrDataUrl` to connect the device.
95
- 7. Use `WhatsThat Targets` to discover and link chats/groups.
96
- 8. Use `WhatsThat Message` to send messages by alias or raw JID.
93
+ 5. Run the node and use the returned `pairingCode`, `qrCodeUrl`, or `qrDataUrl` to connect the device.
94
+ 6. Add another `WhatsThat Session` node with `Ensure Session`.
95
+ 7. Set `Return When` to `Connected` so the workflow waits until the already-started session finishes pairing.
96
+ 8. Use `WhatsThat Targets` to discover and link chats/groups.
97
+ 9. Use `WhatsThat Message` to send messages by alias or raw JID.
97
98
 
98
99
  Example workflow:
99
100
 
@@ -23,8 +23,9 @@ class WhatsThatSession {
23
23
  displayName: 'Operation',
24
24
  name: 'operation',
25
25
  type: 'options',
26
- default: 'ensure',
26
+ default: 'connect',
27
27
  options: [
28
+ { name: 'Connect Session', value: 'connect' },
28
29
  { name: 'Ensure Session', value: 'ensure' },
29
30
  { name: 'List Sessions', value: 'list' },
30
31
  { name: 'Get Session Status', value: 'status' },
@@ -50,7 +51,7 @@ class WhatsThatSession {
50
51
  default: '',
51
52
  description: 'Human-readable name shown in results. Example: "Luca personal phone" or "Support number".',
52
53
  displayOptions: {
53
- show: { operation: ['ensure'] },
54
+ show: { operation: ['connect', 'ensure'] },
54
55
  },
55
56
  },
56
57
  {
@@ -60,7 +61,7 @@ class WhatsThatSession {
60
61
  default: '',
61
62
  description: 'Optional. Full phone number with country code, digits only, without 00 or +. Example: 393331234567.',
62
63
  displayOptions: {
63
- show: { operation: ['ensure'] },
64
+ show: { operation: ['connect', 'ensure'] },
64
65
  },
65
66
  },
66
67
  {
@@ -104,6 +105,17 @@ class WhatsThatSession {
104
105
  const sessionId = operation === 'list' ? (0, validation_1.normalizeSessionId)(rawSessionId) : (0, validation_1.requireSessionId)(rawSessionId);
105
106
  let json;
106
107
  switch (operation) {
108
+ case 'connect': {
109
+ const label = this.getNodeParameter('label', itemIndex, '').trim();
110
+ const phoneNumberForPairing = this.getNodeParameter('phoneNumberForPairing', itemIndex, '').trim();
111
+ await runtime_1.registry.ensureSession(access.paths.root, access, {
112
+ sessionId,
113
+ label: label || sessionId,
114
+ phoneNumberForPairing,
115
+ });
116
+ json = await runtime_1.registry.connectSession(access.paths.root, access, sessionId);
117
+ break;
118
+ }
107
119
  case 'ensure': {
108
120
  const label = this.getNodeParameter('label', itemIndex, '').trim();
109
121
  const phoneNumberForPairing = this.getNodeParameter('phoneNumberForPairing', itemIndex, '').trim();
@@ -46,7 +46,7 @@ declare class WhatsThatRegistry extends EventEmitter {
46
46
  phoneNumberForPairing?: string;
47
47
  }): Promise<SessionRecord>;
48
48
  connectSession(storageRoot: string, access: DataAccess, sessionId: string): Promise<SessionRecord>;
49
- ensureConnectedSession(storageRoot: string, access: DataAccess, input: {
49
+ ensureConnectedSession(_storageRoot: string, access: DataAccess, input: {
50
50
  sessionId: string;
51
51
  label: string;
52
52
  phoneNumberForPairing?: string;
@@ -71,6 +71,7 @@ declare class WhatsThatRegistry extends EventEmitter {
71
71
  private emitRuntime;
72
72
  private waitForSessionState;
73
73
  private matchesWaitTarget;
74
+ waitForConnectedSession(access: DataAccess, sessionId: string, timeoutMs: number): Promise<SessionRecord>;
74
75
  private required;
75
76
  private buildQrCodeUrl;
76
77
  }
@@ -219,14 +219,14 @@ class WhatsThatRegistry extends node_events_1.EventEmitter {
219
219
  this.sockets.set(sessionId, socket);
220
220
  return (await this.getSession(access, sessionId)) ?? starting;
221
221
  }
222
- async ensureConnectedSession(storageRoot, access, input, options) {
223
- await this.ensureSession(storageRoot, access, input);
222
+ async ensureConnectedSession(_storageRoot, access, input, options) {
223
+ await this.ensureSession(_storageRoot, access, input);
224
224
  const current = await this.getSession(access, input.sessionId);
225
225
  if (!current) {
226
226
  throw new Error(`Unknown session ${input.sessionId}`);
227
227
  }
228
228
  if (!this.sockets.has(input.sessionId) && current.status !== 'connected') {
229
- await this.connectSession(storageRoot, access, input.sessionId);
229
+ throw new Error(`Session ${input.sessionId} is not active. Run Connect Session first and keep the n8n runtime alive until pairing completes.`);
230
230
  }
231
231
  return this.waitForSessionState(access, input.sessionId, options?.waitFor ?? 'pairing_or_connected', options?.timeoutMs ?? 20000);
232
232
  }
@@ -508,6 +508,16 @@ class WhatsThatRegistry extends node_events_1.EventEmitter {
508
508
  }
509
509
  return false;
510
510
  }
511
+ async waitForConnectedSession(access, sessionId, timeoutMs) {
512
+ const current = await this.getSession(access, sessionId);
513
+ if (!current) {
514
+ throw new Error(`Unknown session ${sessionId}`);
515
+ }
516
+ if (!this.sockets.has(sessionId) && current.status !== 'connected') {
517
+ throw new Error(`Session ${sessionId} is not active. Run Connect Session first and keep the n8n runtime alive until pairing completes.`);
518
+ }
519
+ return this.waitForSessionState(access, sessionId, 'connected', timeoutMs);
520
+ }
511
521
  required(value, field) {
512
522
  if (value === undefined || value === null || value === '') {
513
523
  throw new Error(`Missing required field ${field}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jep182/n8n-nodes-whatsthat",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "n8n community nodes with embedded Baileys runtime for multi-session chat automation",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",