@raevon/n8n-nodes-whatsapp 1.0.11 → 1.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.
|
@@ -89,6 +89,7 @@ let qrResolve = null;
|
|
|
89
89
|
let latestQr = null;
|
|
90
90
|
let generation = 0; // #10: Generation counter — prevents stale handlers on reconnect
|
|
91
91
|
let credsSavedPromise = null; // Track credential save completion
|
|
92
|
+
let lastDisconnectError = null; // Track last disconnect reason for output
|
|
92
93
|
function todayStartIso() {
|
|
93
94
|
return new Date().toISOString().slice(0, 10) + 'T00:00:00.000Z';
|
|
94
95
|
}
|
|
@@ -168,7 +169,7 @@ async function initSocket(cfg, authPath) {
|
|
|
168
169
|
});
|
|
169
170
|
});
|
|
170
171
|
sock.ev.on('connection.update', async (update) => {
|
|
171
|
-
var _a, _b;
|
|
172
|
+
var _a, _b, _c;
|
|
172
173
|
if (gen !== generation)
|
|
173
174
|
return; // #10: Ignore stale connection events
|
|
174
175
|
const { connection, lastDisconnect, qr } = update;
|
|
@@ -186,22 +187,27 @@ async function initSocket(cfg, authPath) {
|
|
|
186
187
|
socketStatus = 'connected';
|
|
187
188
|
reconnectAttempts = 0;
|
|
188
189
|
latestQr = null;
|
|
189
|
-
|
|
190
|
+
lastDisconnectError = null;
|
|
190
191
|
return;
|
|
191
192
|
}
|
|
192
193
|
if (connection === 'close') {
|
|
193
194
|
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;
|
|
195
|
+
const errorMsg = ((_c = lastDisconnect === null || lastDisconnect === void 0 ? void 0 : lastDisconnect.error) === null || _c === void 0 ? void 0 : _c.message) || 'Unknown error';
|
|
194
196
|
const reason = baileys_1.DisconnectReason[code] || 'Unknown';
|
|
195
|
-
|
|
197
|
+
// Store error for output in nodes
|
|
198
|
+
lastDisconnectError = `Code: ${code} (${reason}), Error: ${errorMsg}`;
|
|
196
199
|
if (code === baileys_1.DisconnectReason.loggedOut) {
|
|
197
200
|
socketStatus = 'logged_out';
|
|
198
201
|
socketInstance = null;
|
|
199
|
-
++generation;
|
|
202
|
+
++generation;
|
|
200
203
|
}
|
|
201
204
|
else {
|
|
202
205
|
socketStatus = 'disconnected';
|
|
203
206
|
socketInstance = null;
|
|
204
|
-
|
|
207
|
+
// Don't auto-reconnect if we're in a loop — let the node handle it
|
|
208
|
+
if (reconnectAttempts < 3) {
|
|
209
|
+
scheduleReconnect(cfg);
|
|
210
|
+
}
|
|
205
211
|
}
|
|
206
212
|
}
|
|
207
213
|
});
|
|
@@ -476,6 +482,7 @@ function getConnectionStatus() {
|
|
|
476
482
|
queueSize: queue ? queue.size + queue.pending : 0,
|
|
477
483
|
sentToday: sentTodayCount,
|
|
478
484
|
dailyLimit: (_a = socketConfig === null || socketConfig === void 0 ? void 0 : socketConfig.dailySendLimit) !== null && _a !== void 0 ? _a : 0,
|
|
485
|
+
lastError: lastDisconnectError,
|
|
479
486
|
};
|
|
480
487
|
}
|
|
481
488
|
function parseIncomingMessage(msg) {
|
package/package.json
CHANGED