@raevon/n8n-nodes-whatsapp 1.0.12 → 1.0.13
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.
|
@@ -42,6 +42,7 @@ exports.connectOrGetQr = connectOrGetQr;
|
|
|
42
42
|
exports.simulateTyping = simulateTyping;
|
|
43
43
|
exports.sendMessageWithAntiBan = sendMessageWithAntiBan;
|
|
44
44
|
exports.getConnectionStatus = getConnectionStatus;
|
|
45
|
+
exports.disconnect = disconnect;
|
|
45
46
|
exports.parseIncomingMessage = parseIncomingMessage;
|
|
46
47
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
47
48
|
const baileys_1 = __importStar(require("@whiskeysockets/baileys"));
|
|
@@ -485,6 +486,20 @@ function getConnectionStatus() {
|
|
|
485
486
|
lastError: lastDisconnectError,
|
|
486
487
|
};
|
|
487
488
|
}
|
|
489
|
+
// Gracefully disconnect — important for n8n queue mode where multiple workers run
|
|
490
|
+
async function disconnect() {
|
|
491
|
+
if (socketInstance) {
|
|
492
|
+
try {
|
|
493
|
+
socketInstance.end(new Error('n8n execution finished'));
|
|
494
|
+
}
|
|
495
|
+
catch {
|
|
496
|
+
// ignore
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
socketInstance = null;
|
|
500
|
+
socketStatus = 'stopped';
|
|
501
|
+
++generation; // Invalidate any pending handlers
|
|
502
|
+
}
|
|
488
503
|
function parseIncomingMessage(msg) {
|
|
489
504
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
490
505
|
if (!msg.message || !msg.key || !msg.key.remoteJid)
|
|
@@ -12,7 +12,7 @@ class WhatsAppConnect {
|
|
|
12
12
|
group: ['transform'],
|
|
13
13
|
version: 1,
|
|
14
14
|
subtitle: '={{$parameter["operation"]}}',
|
|
15
|
-
description: 'Connect to WhatsApp — scan QR code on first run, then
|
|
15
|
+
description: 'Connect to WhatsApp — scan QR code on first run, then disconnects',
|
|
16
16
|
defaults: { name: 'WhatsApp Connect' },
|
|
17
17
|
inputs: ['main'],
|
|
18
18
|
outputs: ['main'],
|
|
@@ -41,8 +41,11 @@ class WhatsAppConnect {
|
|
|
41
41
|
for (let i = 0; i < items.length; i++) {
|
|
42
42
|
try {
|
|
43
43
|
if (operation === 'connect') {
|
|
44
|
-
// Non-blocking: returns QR URL immediately if needed, doesn't wait for scan
|
|
45
44
|
const result = await (0, WhatsAppApiHelper_1.connectOrGetQr)(cfg);
|
|
45
|
+
// If connected, disconnect gracefully to avoid conflict with Send node
|
|
46
|
+
if (result.connected) {
|
|
47
|
+
await (0, WhatsAppApiHelper_1.disconnect)();
|
|
48
|
+
}
|
|
46
49
|
returnData.push({
|
|
47
50
|
json: {
|
|
48
51
|
...result,
|
|
@@ -210,6 +210,8 @@ class WhatsAppSend {
|
|
|
210
210
|
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
|
+
// Disconnect after sending — prevents conflict with other n8n workers
|
|
214
|
+
await (0, WhatsAppApiHelper_1.disconnect)();
|
|
213
215
|
return [returnData];
|
|
214
216
|
}
|
|
215
217
|
}
|
package/package.json
CHANGED