@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.
@@ -60,5 +60,6 @@ export declare function getConnectionStatus(): {
60
60
  dailyLimit: number;
61
61
  lastError: string | null;
62
62
  };
63
+ export declare function disconnect(): Promise<void>;
63
64
  export declare function parseIncomingMessage(msg: any): Record<string, any> | null;
64
65
  export {};
@@ -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 reconnects automatically',
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raevon/n8n-nodes-whatsapp",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
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",