@raevon/n8n-nodes-whatsapp 2.0.9 → 2.0.11
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.
|
@@ -345,20 +345,34 @@ async function startServer(cfg) {
|
|
|
345
345
|
}
|
|
346
346
|
async function ensureServerRunning(cfg) {
|
|
347
347
|
const port = getPort(cfg);
|
|
348
|
-
//
|
|
348
|
+
// Check if server is already running and healthy
|
|
349
|
+
try {
|
|
350
|
+
const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(3000) });
|
|
351
|
+
if (res.ok)
|
|
352
|
+
return; // Server alive
|
|
353
|
+
}
|
|
354
|
+
catch { }
|
|
355
|
+
// Port is in use but server not responding — stale from another worker, can't kill it
|
|
356
|
+
// Just try to use it anyway (might have recovered)
|
|
357
|
+
try {
|
|
358
|
+
const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(5000) });
|
|
359
|
+
if (res.ok)
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
catch { }
|
|
363
|
+
// Port truly free — start server
|
|
349
364
|
if (await isPortOpen(port)) {
|
|
350
365
|
await startServer(cfg);
|
|
351
366
|
return;
|
|
352
367
|
}
|
|
353
|
-
// Port
|
|
368
|
+
// Port occupied, can't start — try to use existing anyway
|
|
354
369
|
try {
|
|
355
|
-
const res = await fetch(`http://127.0.0.1:${port}/
|
|
370
|
+
const res = await fetch(`http://127.0.0.1:${port}/connect`, { method: 'POST', signal: AbortSignal.timeout(60000) });
|
|
356
371
|
if (res.ok)
|
|
357
|
-
return; //
|
|
372
|
+
return; // It worked
|
|
358
373
|
}
|
|
359
374
|
catch { }
|
|
360
|
-
|
|
361
|
-
throw new Error(`Port ${port} occupied. Use "Stop Server" first, or restart n8n container.`);
|
|
375
|
+
throw new Error(`Port ${port} occupied. Restart n8n container, then try again.`);
|
|
362
376
|
}
|
|
363
377
|
async function stopServer(cfg) {
|
|
364
378
|
const port = getPort(cfg);
|
|
@@ -61,11 +61,20 @@ class WhatsAppConnect {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
else if (operation === 'stopServer') {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 {
|
|
@@ -79,13 +88,14 @@ class WhatsAppConnect {
|
|
|
79
88
|
continue;
|
|
80
89
|
}
|
|
81
90
|
try {
|
|
82
|
-
const
|
|
91
|
+
const serverUrl = (0, WhatsAppApiHelper_1.getServerUrl)(cfg);
|
|
92
|
+
const response = await fetch(`${serverUrl}/connect`, { method: 'POST', signal: AbortSignal.timeout(60000) });
|
|
83
93
|
const result = await response.json();
|
|
84
94
|
returnData.push({ json: { ...result, sessionPath: cfg.sessionPath }, pairedItem: { item: i } });
|
|
85
95
|
}
|
|
86
96
|
catch (err) {
|
|
87
97
|
returnData.push({
|
|
88
|
-
json: { connected: false, error: `
|
|
98
|
+
json: { connected: false, error: `Connect failed: ${err.message}`, sessionPath: cfg.sessionPath },
|
|
89
99
|
pairedItem: { item: i },
|
|
90
100
|
});
|
|
91
101
|
}
|
package/package.json
CHANGED