@raevon/n8n-nodes-whatsapp 2.0.3 → 2.0.5
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.
|
@@ -40,6 +40,7 @@ exports.getServerUrl = getServerUrl;
|
|
|
40
40
|
exports.ensureServerRunning = ensureServerRunning;
|
|
41
41
|
exports.disconnect = disconnect;
|
|
42
42
|
exports.getWhatsAppCredentials = getWhatsAppCredentials;
|
|
43
|
+
const node_child_process_1 = require("node:child_process");
|
|
43
44
|
const node_path_1 = __importDefault(require("node:path"));
|
|
44
45
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
45
46
|
const node_net_1 = __importDefault(require("node:net"));
|
|
@@ -344,9 +345,27 @@ async function startServer(cfg) {
|
|
|
344
345
|
}
|
|
345
346
|
async function ensureServerRunning(cfg) {
|
|
346
347
|
const port = getPort(cfg);
|
|
347
|
-
if
|
|
348
|
-
|
|
348
|
+
// Check if server is already running on this port
|
|
349
|
+
if (await isPortOpen(port)) {
|
|
350
|
+
// Port is in use - check if it's our server by hitting /health
|
|
351
|
+
try {
|
|
352
|
+
const res = await fetch(`http://127.0.0.1:${port}/health`);
|
|
353
|
+
if (res.ok) {
|
|
354
|
+
// Server is alive and responding
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
catch { }
|
|
359
|
+
// Port is in use but not responding - kill the stale process
|
|
360
|
+
try {
|
|
361
|
+
const pid = (0, node_child_process_1.execSync)(`lsof -ti:${port}`, { encoding: 'utf-8' }).trim();
|
|
362
|
+
if (pid)
|
|
363
|
+
(0, node_child_process_1.execSync)(`kill -9 ${pid}`);
|
|
364
|
+
await new Promise(r => setTimeout(r, 1000)); // Wait for port to release
|
|
365
|
+
}
|
|
366
|
+
catch { }
|
|
349
367
|
}
|
|
368
|
+
await startServer(cfg);
|
|
350
369
|
}
|
|
351
370
|
async function disconnect() { }
|
|
352
371
|
async function getWhatsAppCredentials(credentials) {
|
|
@@ -52,18 +52,32 @@ class WhatsAppConnect {
|
|
|
52
52
|
for (let i = 0; i < items.length; i++) {
|
|
53
53
|
try {
|
|
54
54
|
if (operation === 'connect') {
|
|
55
|
-
// Start the
|
|
56
|
-
|
|
55
|
+
// Start the WhatsApp server
|
|
56
|
+
try {
|
|
57
|
+
await (0, WhatsAppApiHelper_1.ensureServerRunning)(cfg);
|
|
58
|
+
}
|
|
59
|
+
catch (serverErr) {
|
|
60
|
+
returnData.push({
|
|
61
|
+
json: { connected: false, error: `Server start failed: ${serverErr.message}`, sessionPath: cfg.sessionPath },
|
|
62
|
+
pairedItem: { item: i },
|
|
63
|
+
});
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
57
66
|
// Connect to the server
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
...result,
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
try {
|
|
68
|
+
const response = await fetch(`${(0, WhatsAppApiHelper_1.getServerUrl)(cfg)}/connect`, { method: 'POST' });
|
|
69
|
+
const result = await response.json();
|
|
70
|
+
returnData.push({
|
|
71
|
+
json: { ...result, sessionPath: cfg.sessionPath },
|
|
72
|
+
pairedItem: { item: i },
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
catch (fetchErr) {
|
|
76
|
+
returnData.push({
|
|
77
|
+
json: { connected: false, error: `Fetch failed: ${fetchErr.message}. Server URL: ${(0, WhatsAppApiHelper_1.getServerUrl)(cfg)}`, sessionPath: cfg.sessionPath },
|
|
78
|
+
pairedItem: { item: i },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
67
81
|
}
|
|
68
82
|
else if (operation === 'status') {
|
|
69
83
|
try {
|
package/package.json
CHANGED