@raevon/n8n-nodes-whatsapp 1.0.8 → 1.0.10

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.
@@ -184,16 +184,20 @@ async function initSocket(cfg, authPath) {
184
184
  socketStatus = 'connected';
185
185
  reconnectAttempts = 0;
186
186
  latestQr = null;
187
+ console.log('[WhatsApp] Connected successfully');
187
188
  return;
188
189
  }
189
190
  if (connection === 'close') {
190
191
  const code = (_b = (_a = lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error) === null || _a === void 0 ? void 0 : _a.output) === null || _b === void 0 ? void 0 : _b.statusCode;
192
+ const reason = baileys_1.DisconnectReason[code] || 'Unknown';
193
+ console.log(`[WhatsApp] Connection closed: ${reason} (code: ${code})`);
191
194
  if (code === baileys_1.DisconnectReason.loggedOut) {
192
195
  socketStatus = 'logged_out';
193
196
  socketInstance = null;
194
197
  ++generation; // #10: Invalidate all handlers from this session
195
198
  }
196
199
  else {
200
+ socketStatus = 'disconnected';
197
201
  socketInstance = null;
198
202
  scheduleReconnect(cfg);
199
203
  }
@@ -218,17 +222,6 @@ async function getWhatsAppCredentials(credentials) {
218
222
  };
219
223
  }
220
224
  async function ensureConnected(cfg) {
221
- // Always try to use existing socket first, but verify it's actually alive
222
- if (socketInstance && socketStatus === 'connected') {
223
- try {
224
- // Quick check — if socket user is set, it's alive
225
- if (socketInstance.user)
226
- return socketInstance;
227
- }
228
- catch {
229
- // Socket is dead, reconnect below
230
- }
231
- }
232
225
  const antiBanCfg = {
233
226
  messageDelayMinMs: cfg.messageDelayMinMs,
234
227
  messageDelayMaxMs: cfg.messageDelayMaxMs,
@@ -245,27 +238,46 @@ async function ensureConnected(cfg) {
245
238
  if (!queue) {
246
239
  queue = new p_queue_1.default({ concurrency: 1 });
247
240
  }
248
- // Check if session already exists on disk
241
+ // Check if session exists on disk
249
242
  const resolvedPath = expandHome(cfg.sessionPath);
250
243
  const hasSession = node_fs_1.default.existsSync(resolvedPath) && node_fs_1.default.readdirSync(resolvedPath).length > 0;
244
+ console.log(`[WhatsApp] Session path: ${resolvedPath}, exists: ${hasSession}`);
251
245
  if (!hasSession) {
252
246
  throw new n8n_workflow_1.NodeApiError({}, {
253
247
  message: 'No WhatsApp session found. Run the WhatsApp Connect node first to scan QR code.',
254
248
  });
255
249
  }
256
- // Session exists connect using saved credentials (no QR needed)
250
+ // Check if current socket is actually alive
251
+ console.log(`[WhatsApp] Current status: ${socketStatus}, socket exists: ${!!socketInstance}`);
252
+ if (socketInstance && socketStatus === 'connected') {
253
+ try {
254
+ if (socketInstance.user) {
255
+ console.log('[WhatsApp] Reusing existing connection');
256
+ return socketInstance;
257
+ }
258
+ }
259
+ catch {
260
+ console.log('[WhatsApp] Existing socket is dead, reconnecting...');
261
+ }
262
+ }
263
+ // Session exists — connect using saved credentials
264
+ console.log('[WhatsApp] Connecting from saved session...');
257
265
  const sock = await initSocket(antiBanCfg, cfg.sessionPath);
258
- // Wait for connection to open (up to 15s)
259
- await new Promise((resolve) => {
266
+ // Wait for connection to open (up to 20s)
267
+ const connected = await new Promise((resolve) => {
260
268
  const check = setInterval(() => {
261
- if (socketStatus === 'connected' || socketStatus === 'error' || socketStatus === 'logged_out') {
269
+ if (socketStatus === 'connected') {
270
+ clearInterval(check);
271
+ resolve(true);
272
+ }
273
+ if (socketStatus === 'logged_out' || socketStatus === 'error') {
262
274
  clearInterval(check);
263
- resolve();
275
+ resolve(false);
264
276
  }
265
277
  }, 500);
266
- setTimeout(() => { clearInterval(check); resolve(); }, 15000);
278
+ setTimeout(() => { clearInterval(check); resolve(false); }, 20000);
267
279
  });
268
- if (socketStatus !== 'connected') {
280
+ if (!connected) {
269
281
  throw new n8n_workflow_1.NodeApiError({}, {
270
282
  message: `WhatsApp connection failed (status: ${socketStatus}). Try running Connect node again.`,
271
283
  });
@@ -133,10 +133,12 @@ class WhatsAppSend {
133
133
  const returnData = [];
134
134
  const credentials = await this.getCredentials('whatsappApi');
135
135
  const cfg = await (0, WhatsAppApiHelper_1.getWhatsAppCredentials)(credentials);
136
+ console.log(`[WhatsApp Send] Starting execution, recipient check: ${cfg.checkRecipientExists}`);
136
137
  for (let i = 0; i < items.length; i++) {
137
138
  try {
138
139
  const operation = this.getNodeParameter('operation', i);
139
140
  const recipient = this.getNodeParameter('recipient', i);
141
+ console.log(`[WhatsApp Send] Operation: ${operation}, To: ${recipient}`);
140
142
  let content = {};
141
143
  switch (operation) {
142
144
  case 'sendText':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raevon/n8n-nodes-whatsapp",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
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",