@raevon/n8n-nodes-whatsapp 2.0.10 → 2.0.12

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.
@@ -11,6 +11,7 @@ export interface WhatsAppCredentials {
11
11
  }
12
12
  export declare function getServerUrl(cfg: WhatsAppCredentials): string;
13
13
  export declare function ensureServerRunning(cfg: WhatsAppCredentials): Promise<void>;
14
+ export declare function startServerIfNeeded(cfg: WhatsAppCredentials): Promise<void>;
14
15
  export declare function stopServer(cfg: WhatsAppCredentials): Promise<void>;
15
16
  export declare function disconnect(): Promise<void>;
16
17
  export declare function getWhatsAppCredentials(credentials: Record<string, any>): Promise<WhatsAppCredentials>;
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.getServerUrl = getServerUrl;
40
40
  exports.ensureServerRunning = ensureServerRunning;
41
+ exports.startServerIfNeeded = startServerIfNeeded;
41
42
  exports.stopServer = stopServer;
42
43
  exports.disconnect = disconnect;
43
44
  exports.getWhatsAppCredentials = getWhatsAppCredentials;
@@ -345,20 +346,31 @@ async function startServer(cfg) {
345
346
  }
346
347
  async function ensureServerRunning(cfg) {
347
348
  const port = getPort(cfg);
348
- // Try to connect to existing server first
349
+ // Just check if server is running — don't start it
349
350
  try {
350
- const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(5000) });
351
+ const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(3000) });
351
352
  if (res.ok)
352
353
  return; // Server alive
353
354
  }
354
355
  catch { }
355
- // Server not running start it
356
+ throw new Error(`WhatsApp server not running on port ${port}. Run "Start Server" or "Connect" first.`);
357
+ }
358
+ async function startServerIfNeeded(cfg) {
359
+ const port = getPort(cfg);
360
+ // Check if already running
361
+ try {
362
+ const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(3000) });
363
+ if (res.ok)
364
+ return; // Already running
365
+ }
366
+ catch { }
367
+ // Port free — start server
356
368
  if (await isPortOpen(port)) {
357
369
  await startServer(cfg);
358
370
  return;
359
371
  }
360
372
  // Port occupied by something else
361
- throw new Error(`Port ${port} occupied by another process. Restart n8n container to clear.`);
373
+ throw new Error(`Port ${port} occupied. Restart n8n container, then try again.`);
362
374
  }
363
375
  async function stopServer(cfg) {
364
376
  const port = getPort(cfg);
@@ -54,22 +54,31 @@ class WhatsAppConnect {
54
54
  for (let i = 0; i < items.length; i++) {
55
55
  try {
56
56
  if (operation === 'startServer') {
57
- await (0, WhatsAppApiHelper_1.ensureServerRunning)(cfg);
57
+ await (0, WhatsAppApiHelper_1.startServerIfNeeded)(cfg);
58
58
  returnData.push({
59
59
  json: { success: true, message: 'Server started', port: (0, WhatsAppApiHelper_1.getServerUrl)(cfg), sessionPath: cfg.sessionPath },
60
60
  pairedItem: { item: i },
61
61
  });
62
62
  }
63
63
  else if (operation === 'stopServer') {
64
- await (0, WhatsAppApiHelper_1.stopServer)(cfg);
65
- returnData.push({
66
- json: { success: true, message: 'Server stopped', sessionPath: cfg.sessionPath },
67
- pairedItem: { item: i },
68
- });
64
+ // Try graceful shutdown via /signout
65
+ try {
66
+ await fetch(`${(0, WhatsAppApiHelper_1.getServerUrl)(cfg)}/signout`, { method: 'POST', signal: AbortSignal.timeout(3000) });
67
+ returnData.push({
68
+ json: { success: true, message: 'Server stopped', sessionPath: cfg.sessionPath },
69
+ pairedItem: { item: i },
70
+ });
71
+ }
72
+ catch {
73
+ returnData.push({
74
+ json: { success: false, message: 'Server may be in another worker. Restart n8n container to fully stop.', sessionPath: cfg.sessionPath },
75
+ pairedItem: { item: i },
76
+ });
77
+ }
69
78
  }
70
79
  else if (operation === 'connect') {
71
80
  try {
72
- await (0, WhatsAppApiHelper_1.ensureServerRunning)(cfg);
81
+ await (0, WhatsAppApiHelper_1.startServerIfNeeded)(cfg);
73
82
  }
74
83
  catch (err) {
75
84
  returnData.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raevon/n8n-nodes-whatsapp",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "description": "n8n community node for WhatsApp — send and receive messages with anti-ban protection via the Baileys library",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",