@raevon/n8n-nodes-whatsapp 2.0.11 → 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,33 +346,30 @@ async function startServer(cfg) {
|
|
|
345
346
|
}
|
|
346
347
|
async function ensureServerRunning(cfg) {
|
|
347
348
|
const port = getPort(cfg);
|
|
348
|
-
//
|
|
349
|
+
// Just check if server is running — don't start it
|
|
349
350
|
try {
|
|
350
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
|
-
|
|
356
|
-
|
|
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
|
|
357
361
|
try {
|
|
358
|
-
const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(
|
|
362
|
+
const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(3000) });
|
|
359
363
|
if (res.ok)
|
|
360
|
-
return;
|
|
364
|
+
return; // Already running
|
|
361
365
|
}
|
|
362
366
|
catch { }
|
|
363
|
-
// Port
|
|
367
|
+
// Port free — start server
|
|
364
368
|
if (await isPortOpen(port)) {
|
|
365
369
|
await startServer(cfg);
|
|
366
370
|
return;
|
|
367
371
|
}
|
|
368
|
-
// Port occupied
|
|
369
|
-
try {
|
|
370
|
-
const res = await fetch(`http://127.0.0.1:${port}/connect`, { method: 'POST', signal: AbortSignal.timeout(60000) });
|
|
371
|
-
if (res.ok)
|
|
372
|
-
return; // It worked
|
|
373
|
-
}
|
|
374
|
-
catch { }
|
|
372
|
+
// Port occupied by something else
|
|
375
373
|
throw new Error(`Port ${port} occupied. Restart n8n container, then try again.`);
|
|
376
374
|
}
|
|
377
375
|
async function stopServer(cfg) {
|
|
@@ -54,7 +54,7 @@ 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.
|
|
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 },
|
|
@@ -78,7 +78,7 @@ class WhatsAppConnect {
|
|
|
78
78
|
}
|
|
79
79
|
else if (operation === 'connect') {
|
|
80
80
|
try {
|
|
81
|
-
await (0, WhatsAppApiHelper_1.
|
|
81
|
+
await (0, WhatsAppApiHelper_1.startServerIfNeeded)(cfg);
|
|
82
82
|
}
|
|
83
83
|
catch (err) {
|
|
84
84
|
returnData.push({
|
package/package.json
CHANGED