@builderbot/provider-baileys 1.2.10-alpha.0 → 1.2.10-alpha.3
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.
- package/dist/bailey.d.ts +16 -0
- package/dist/bailey.d.ts.map +1 -1
- package/dist/index.cjs +244 -111
- package/dist/type.d.ts +2 -0
- package/dist/type.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/bailey.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ import { BaileysEventMap, WAMessage, WASocket, proto } from './baileyWrapper';
|
|
|
9
9
|
import type { BaileyGlobalVendorArgs } from './type';
|
|
10
10
|
declare class BaileysProvider extends ProviderClass<WASocket> {
|
|
11
11
|
globalVendorArgs: BaileyGlobalVendorArgs;
|
|
12
|
+
private reconnectAttempts;
|
|
13
|
+
private maxReconnectAttempts;
|
|
14
|
+
private reconnectDelay;
|
|
12
15
|
msgRetryCounterCache?: NodeCache;
|
|
13
16
|
userDevicesCache?: NodeCache;
|
|
14
17
|
private logger;
|
|
@@ -16,7 +19,18 @@ declare class BaileysProvider extends ProviderClass<WASocket> {
|
|
|
16
19
|
private idsDuplicates;
|
|
17
20
|
private mapSet;
|
|
18
21
|
constructor(args: Partial<BaileyGlobalVendorArgs>);
|
|
22
|
+
/**
|
|
23
|
+
* Setup cleanup handlers
|
|
24
|
+
* @description
|
|
25
|
+
* - Remove existing listeners to prevent duplicates
|
|
26
|
+
* - Add new listeners
|
|
27
|
+
* - Add cleanup function to all listeners
|
|
28
|
+
* - Add cleanup function to uncaughtException and unhandledRejection
|
|
29
|
+
* - Add cleanup function to SIGINT, SIGTERM, SIGUSR1, SIGUSR2
|
|
30
|
+
* - Add cleanup function to process.exit
|
|
31
|
+
*/
|
|
19
32
|
private setupCleanupHandlers;
|
|
33
|
+
private setupPeriodicCleanup;
|
|
20
34
|
private cleanup;
|
|
21
35
|
releaseSessionFiles(): Promise<void>;
|
|
22
36
|
protected beforeHttpServerInit(): void;
|
|
@@ -169,6 +183,8 @@ declare class BaileysProvider extends ProviderClass<WASocket> {
|
|
|
169
183
|
saveFile: (ctx: Partial<WAMessage & BotContext>, options?: {
|
|
170
184
|
path: string;
|
|
171
185
|
}) => Promise<string>;
|
|
186
|
+
private shouldReconnect;
|
|
187
|
+
private delayedReconnect;
|
|
172
188
|
}
|
|
173
189
|
export { BaileysProvider };
|
|
174
190
|
//# sourceMappingURL=bailey.d.ts.map
|
package/dist/bailey.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bailey.d.ts","sourceRoot":"","sources":["../src/bailey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAS,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAGjF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,IAAI,CAAA;AAI9C,OAAO,SAAS,MAAM,YAAY,CAAA;AAIlC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAG3D,OAAO,EAGH,eAAe,EAEf,SAAS,EACT,QAAQ,EASR,KAAK,EAER,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAGpD,cAAM,eAAgB,SAAQ,aAAa,CAAC,QAAQ,CAAC;IAC1C,gBAAgB,EAAE,sBAAsB,
|
|
1
|
+
{"version":3,"file":"bailey.d.ts","sourceRoot":"","sources":["../src/bailey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAS,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAGjF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,IAAI,CAAA;AAI9C,OAAO,SAAS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ED;;;;;;;OAOG;IAEH,WAAW,GACP,WAAW,GAAG,EACd,eAAe;QAAE,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,GAAG,CAAA;KAAE,EAClE,aAAa,MAAM,EACnB,SAAS,MAAM,EACf,WAAU,GAAU;;OAyBvB;IAED;;;;OAIG;IACH,kBAAkB,GAAU,WAAW,GAAG,EAAE,YAAY,GAAG,mBAE1D;IAED;;;;;;OAMG;IAEH,WAAW,GACP,WAAW,GAAG,EACd,KAAK,MAAM,GAAG,MAAM,EACpB,gBAAgB,OAAO,CAAC,eAAe,CAAC,EACxC,WAAU,GAAU,mBAWvB;IAED,OAAO,CAAC,WAAW,CAYlB;IAED,OAAO,CAAC,gBAAgB,CAAmE;IAE3F;;;;;OAKG;IACH,QAAQ,GAAU,KAAK,OAAO,CAAC,SAAS,GAAG,UAAU,CAAC,EAAE,UAAU;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,KAAG,OAAO,CAAC,MAAM,CAAC,CAUnG;IAED,OAAO,CAAC,eAAe;YAmBT,gBAAgB;CA+BjC;AAED,OAAO,EAAE,eAAe,EAAE,CAAA"}
|
package/dist/index.cjs
CHANGED
|
@@ -30954,7 +30954,11 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
30954
30954
|
experimentalStore: false,
|
|
30955
30955
|
autoRefresh: 0,
|
|
30956
30956
|
experimentalSyncMessage: undefined,
|
|
30957
|
+
fallBackAction: undefined,
|
|
30957
30958
|
};
|
|
30959
|
+
this.reconnectAttempts = 0;
|
|
30960
|
+
this.maxReconnectAttempts = 10;
|
|
30961
|
+
this.reconnectDelay = 1000; // 1 segundo inicial
|
|
30958
30962
|
this.idsDuplicates = [];
|
|
30959
30963
|
this.mapSet = new Set();
|
|
30960
30964
|
this.indexHome = (req, res) => {
|
|
@@ -31020,10 +31024,14 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31020
31024
|
generateHighQualityLinkPreview: true,
|
|
31021
31025
|
getMessage: this.getMessage,
|
|
31022
31026
|
msgRetryCounterCache: this.msgRetryCounterCache,
|
|
31023
|
-
|
|
31024
|
-
|
|
31025
|
-
|
|
31026
|
-
|
|
31027
|
+
userDevicesCache: this.userDevicesCache,
|
|
31028
|
+
retryRequestDelayMs: 1000, // Mayor delay entre reintentos
|
|
31029
|
+
maxMsgRetryCount: 8, // Más intentos de reenvío
|
|
31030
|
+
connectTimeoutMs: 60_000, // 1 minuto timeout conexión
|
|
31031
|
+
keepAliveIntervalMs: 10_000, // Keep alive cada 10 segundos
|
|
31032
|
+
qrTimeout: 40_000, // 40 segundos para QR
|
|
31033
|
+
defaultQueryTimeoutMs: 60_000, // 1 minuto para queries
|
|
31034
|
+
emitOwnEvents: false, // No emitir eventos propios
|
|
31027
31035
|
shouldIgnoreJid: (jid) => {
|
|
31028
31036
|
if (this.globalVendorArgs.groupsIgnore) {
|
|
31029
31037
|
return baileys.isJidGroup(jid) || baileys.isJidBroadcast(jid);
|
|
@@ -31072,22 +31080,40 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31072
31080
|
}
|
|
31073
31081
|
sock.ev.on('connection.update', async (update) => {
|
|
31074
31082
|
const { connection, lastDisconnect, qr } = update;
|
|
31083
|
+
this.logger.log(`[${new Date().toISOString()}] Connection update: ${connection}`);
|
|
31075
31084
|
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
31085
|
+
const reason = lastDisconnect?.error?.message;
|
|
31076
31086
|
/** Connection closed for various reasons */
|
|
31077
31087
|
if (connection === 'close') {
|
|
31078
|
-
|
|
31079
|
-
|
|
31080
|
-
return;
|
|
31081
|
-
}
|
|
31088
|
+
this.logger.log(`[${new Date().toISOString()}] Connection closed. Status: ${statusCode}, Reason: ${reason}`);
|
|
31089
|
+
// Casos donde NO debemos reconectar
|
|
31082
31090
|
if (statusCode === baileys.DisconnectReason.loggedOut) {
|
|
31083
|
-
|
|
31091
|
+
this.logger.log(`[${new Date().toISOString()}] Logged out, clearing session and restarting...`);
|
|
31092
|
+
const PATH_BASE = require$$1$1.join(process.cwd(), `${this.globalVendorArgs.name}_sessions`);
|
|
31084
31093
|
await emptyDirSessions(PATH_BASE);
|
|
31085
|
-
this.
|
|
31094
|
+
this.reconnectAttempts = 0;
|
|
31095
|
+
await this.delayedReconnect();
|
|
31086
31096
|
return;
|
|
31087
31097
|
}
|
|
31098
|
+
// Casos donde debemos reconectar con backoff
|
|
31099
|
+
if (this.shouldReconnect(statusCode)) {
|
|
31100
|
+
await this.delayedReconnect();
|
|
31101
|
+
return;
|
|
31102
|
+
}
|
|
31103
|
+
// Casos críticos - emitir error
|
|
31104
|
+
this.logger.log(`[${new Date().toISOString()}] Critical error, stopping reconnection attempts`);
|
|
31105
|
+
this.emit('auth_failure', [
|
|
31106
|
+
`Critical connection error: ${reason}`,
|
|
31107
|
+
`Status code: ${statusCode}`,
|
|
31108
|
+
`Check baileys.log for details`,
|
|
31109
|
+
`Need help: https://link.codigoencasa.com/DISCORD`,
|
|
31110
|
+
]);
|
|
31088
31111
|
}
|
|
31089
31112
|
/** Connection opened successfully */
|
|
31090
31113
|
if (connection === 'open') {
|
|
31114
|
+
this.logger.log(`[${new Date().toISOString()}] Connection opened successfully`);
|
|
31115
|
+
this.reconnectAttempts = 0; // Reset counter on successful connection
|
|
31116
|
+
this.reconnectDelay = 1000; // Reset delay
|
|
31091
31117
|
const parseNumber = `${sock?.user?.id}`.split(':').shift();
|
|
31092
31118
|
const host = { ...sock?.user, phone: parseNumber };
|
|
31093
31119
|
this.globalVendorArgs.host = host;
|
|
@@ -31096,6 +31122,7 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31096
31122
|
}
|
|
31097
31123
|
/** QR Code */
|
|
31098
31124
|
if (qr && !this.globalVendorArgs.usePairingCode) {
|
|
31125
|
+
this.logger.log(`[${new Date().toISOString()}] QR Code received`);
|
|
31099
31126
|
this.emit('require_action', {
|
|
31100
31127
|
title: '⚡⚡ ACTION REQUIRED ⚡⚡',
|
|
31101
31128
|
instructions: [
|
|
@@ -31148,108 +31175,141 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31148
31175
|
}
|
|
31149
31176
|
}
|
|
31150
31177
|
};
|
|
31151
|
-
const
|
|
31152
|
-
|
|
31153
|
-
|
|
31154
|
-
|
|
31155
|
-
messageCtx
|
|
31156
|
-
|
|
31157
|
-
|
|
31158
|
-
messageCtx
|
|
31159
|
-
|
|
31160
|
-
|
|
31161
|
-
messageCtx
|
|
31162
|
-
|
|
31163
|
-
this.globalVendorArgs.
|
|
31164
|
-
|
|
31165
|
-
|
|
31178
|
+
for (const messageCtx of messages) {
|
|
31179
|
+
if (messageCtx?.messageStubParameters?.length &&
|
|
31180
|
+
messageCtx.messageStubParameters[0].includes('absent'))
|
|
31181
|
+
continue;
|
|
31182
|
+
if (messageCtx?.messageStubParameters?.length &&
|
|
31183
|
+
messageCtx.messageStubParameters[0].includes('No session'))
|
|
31184
|
+
continue;
|
|
31185
|
+
if (messageCtx?.messageStubParameters?.length &&
|
|
31186
|
+
messageCtx.messageStubParameters[0].includes('Bad MAC'))
|
|
31187
|
+
continue;
|
|
31188
|
+
if (messageCtx?.messageStubParameters?.length &&
|
|
31189
|
+
messageCtx.messageStubParameters[0].includes('Invalid')) {
|
|
31190
|
+
if (this.globalVendorArgs.fallBackAction) {
|
|
31191
|
+
try {
|
|
31192
|
+
await this.globalVendorArgs.fallBackAction(messageCtx);
|
|
31193
|
+
}
|
|
31194
|
+
catch (error) {
|
|
31195
|
+
continue;
|
|
31196
|
+
}
|
|
31197
|
+
continue;
|
|
31166
31198
|
}
|
|
31199
|
+
if (this.globalVendorArgs.experimentalSyncMessage &&
|
|
31200
|
+
this.globalVendorArgs.experimentalSyncMessage.length) {
|
|
31201
|
+
if (baileyIsValidNumber(messageCtx?.key?.remoteJid)) {
|
|
31202
|
+
await pingMessageSync(messageCtx);
|
|
31203
|
+
}
|
|
31204
|
+
continue;
|
|
31205
|
+
}
|
|
31206
|
+
continue;
|
|
31167
31207
|
}
|
|
31168
|
-
|
|
31169
|
-
|
|
31170
|
-
|
|
31171
|
-
|
|
31172
|
-
|
|
31173
|
-
|
|
31174
|
-
|
|
31175
|
-
|
|
31176
|
-
|
|
31177
|
-
|
|
31178
|
-
|
|
31179
|
-
|
|
31180
|
-
|
|
31181
|
-
|
|
31182
|
-
|
|
31183
|
-
|
|
31184
|
-
|
|
31185
|
-
|
|
31186
|
-
|
|
31187
|
-
|
|
31188
|
-
|
|
31208
|
+
// if (((messageCtx?.message?.protocolMessage?.type) as unknown as string) === 'EPHEMERAL_SETTING') continue
|
|
31209
|
+
const textToBody = messageCtx?.message?.ephemeralMessage?.message?.extendedTextMessage?.text ??
|
|
31210
|
+
messageCtx?.message?.extendedTextMessage?.text ??
|
|
31211
|
+
messageCtx?.message?.conversation;
|
|
31212
|
+
if (textToBody) {
|
|
31213
|
+
if (textToBody === 'requestPlaceholder' && !messageCtx.requestId) {
|
|
31214
|
+
try {
|
|
31215
|
+
if (this.vendor.requestPlaceholderResend) {
|
|
31216
|
+
const messageId = await this.vendor.requestPlaceholderResend(messageCtx.key);
|
|
31217
|
+
this.logger.log(`[${new Date().toISOString()}] Requested placeholder resync, id=${messageId}`);
|
|
31218
|
+
}
|
|
31219
|
+
continue; // No procesar como mensaje normal
|
|
31220
|
+
}
|
|
31221
|
+
catch (e) {
|
|
31222
|
+
this.logger.log(`[${new Date().toISOString()}] Error requesting placeholder resync:`, e);
|
|
31223
|
+
}
|
|
31224
|
+
}
|
|
31225
|
+
if (textToBody === 'onDemandHistSync') {
|
|
31226
|
+
try {
|
|
31227
|
+
if (this.vendor.fetchMessageHistory) {
|
|
31228
|
+
const messageId = await this.vendor.fetchMessageHistory(50, messageCtx.key, messageCtx.messageTimestamp);
|
|
31229
|
+
this.logger.log(`[${new Date().toISOString()}] Requested on-demand sync, id=${messageId}`);
|
|
31230
|
+
}
|
|
31231
|
+
continue; // No procesar como mensaje normal
|
|
31232
|
+
}
|
|
31233
|
+
catch (e) {
|
|
31234
|
+
this.logger.log(`[${new Date().toISOString()}] Error requesting history sync:`, e);
|
|
31235
|
+
}
|
|
31236
|
+
}
|
|
31237
|
+
if (messageCtx.requestId) {
|
|
31238
|
+
this.logger.log(`[${new Date().toISOString()}] Message received from phone, id=${messageCtx.requestId}`, messageCtx);
|
|
31239
|
+
}
|
|
31189
31240
|
}
|
|
31190
|
-
|
|
31191
|
-
|
|
31192
|
-
|
|
31193
|
-
|
|
31194
|
-
|
|
31195
|
-
|
|
31196
|
-
|
|
31197
|
-
|
|
31198
|
-
|
|
31199
|
-
|
|
31200
|
-
|
|
31201
|
-
|
|
31202
|
-
|
|
31203
|
-
//Detectar file
|
|
31204
|
-
if (messageCtx.message?.documentMessage || messageCtx.message?.documentWithCaptionMessage) {
|
|
31205
|
-
payload = { ...payload, body: bot.utils.generateRefProvider('_event_document_') };
|
|
31206
|
-
}
|
|
31207
|
-
//Detectar voice note
|
|
31208
|
-
if (messageCtx.message?.audioMessage) {
|
|
31209
|
-
payload = { ...payload, body: bot.utils.generateRefProvider('_event_voice_note_') };
|
|
31210
|
-
}
|
|
31211
|
-
//Detectar order message
|
|
31212
|
-
if (messageCtx.message?.orderMessage) {
|
|
31213
|
-
payload = { ...payload, body: bot.utils.generateRefProvider('_event_order_') };
|
|
31214
|
-
}
|
|
31215
|
-
if (payload.from === 'status@broadcast')
|
|
31216
|
-
return;
|
|
31217
|
-
payload.from = baileyCleanNumber(payload.from, true);
|
|
31218
|
-
if (this.globalVendorArgs.writeMyself === 'none' && payload?.key?.fromMe)
|
|
31219
|
-
return;
|
|
31220
|
-
if (this.globalVendorArgs.host?.phone !== payload.from &&
|
|
31221
|
-
payload?.key?.fromMe &&
|
|
31222
|
-
!['both'].includes(this.globalVendorArgs.writeMyself))
|
|
31223
|
-
return;
|
|
31224
|
-
if (this.globalVendorArgs.host?.phone === payload.from &&
|
|
31225
|
-
!['both', 'host'].includes(this.globalVendorArgs.writeMyself))
|
|
31226
|
-
return;
|
|
31227
|
-
if (!baileyIsValidNumber(payload.from)) {
|
|
31228
|
-
return;
|
|
31229
|
-
}
|
|
31230
|
-
const btnCtx = payload?.message?.buttonsResponseMessage?.selectedDisplayText;
|
|
31231
|
-
if (btnCtx)
|
|
31232
|
-
payload.body = btnCtx;
|
|
31233
|
-
const listRowId = payload?.message?.listResponseMessage?.title;
|
|
31234
|
-
if (listRowId)
|
|
31235
|
-
payload.body = listRowId;
|
|
31236
|
-
const processDuplicate = () => {
|
|
31237
|
-
if (messageCtx?.key?.id) {
|
|
31238
|
-
const idWs = `${messageCtx.key.id}__${payload.from}`;
|
|
31239
|
-
const isDuplicate = this.idsDuplicates.includes(idWs);
|
|
31240
|
-
if (isDuplicate) {
|
|
31241
|
-
this.idsDuplicates = [];
|
|
31242
|
-
return false;
|
|
31241
|
+
let payload = {
|
|
31242
|
+
...messageCtx,
|
|
31243
|
+
body: textToBody,
|
|
31244
|
+
name: messageCtx?.pushName,
|
|
31245
|
+
from: messageCtx?.key?.remoteJid,
|
|
31246
|
+
};
|
|
31247
|
+
if (messageCtx.message?.locationMessage) {
|
|
31248
|
+
const { degreesLatitude, degreesLongitude } = messageCtx.message.locationMessage;
|
|
31249
|
+
if (typeof degreesLatitude === 'number' && typeof degreesLongitude === 'number') {
|
|
31250
|
+
payload = {
|
|
31251
|
+
...payload,
|
|
31252
|
+
body: bot.utils.generateRefProvider('_event_location_'),
|
|
31253
|
+
};
|
|
31243
31254
|
}
|
|
31244
|
-
|
|
31245
|
-
|
|
31255
|
+
}
|
|
31256
|
+
if (messageCtx.message?.videoMessage) {
|
|
31257
|
+
payload = { ...payload, body: bot.utils.generateRefProvider('_event_media_') };
|
|
31258
|
+
}
|
|
31259
|
+
if (messageCtx.message?.stickerMessage) {
|
|
31260
|
+
payload = { ...payload, body: bot.utils.generateRefProvider('_event_media_') };
|
|
31261
|
+
}
|
|
31262
|
+
if (messageCtx.message?.imageMessage) {
|
|
31263
|
+
payload = { ...payload, body: bot.utils.generateRefProvider('_event_media_') };
|
|
31264
|
+
}
|
|
31265
|
+
if (messageCtx.message?.documentMessage || messageCtx.message?.documentWithCaptionMessage) {
|
|
31266
|
+
payload = { ...payload, body: bot.utils.generateRefProvider('_event_document_') };
|
|
31267
|
+
}
|
|
31268
|
+
if (messageCtx.message?.audioMessage) {
|
|
31269
|
+
payload = { ...payload, body: bot.utils.generateRefProvider('_event_voice_note_') };
|
|
31270
|
+
}
|
|
31271
|
+
if (messageCtx.message?.orderMessage) {
|
|
31272
|
+
payload = { ...payload, body: bot.utils.generateRefProvider('_event_order_') };
|
|
31273
|
+
}
|
|
31274
|
+
if (payload.from === 'status@broadcast')
|
|
31275
|
+
continue;
|
|
31276
|
+
payload.from = baileyCleanNumber(payload.from, true);
|
|
31277
|
+
if (this.globalVendorArgs.writeMyself === 'none' && payload?.key?.fromMe)
|
|
31278
|
+
continue;
|
|
31279
|
+
if (this.globalVendorArgs.host?.phone !== payload.from &&
|
|
31280
|
+
payload?.key?.fromMe &&
|
|
31281
|
+
!['both'].includes(this.globalVendorArgs.writeMyself))
|
|
31282
|
+
continue;
|
|
31283
|
+
if (this.globalVendorArgs.host?.phone === payload.from &&
|
|
31284
|
+
!['both', 'host'].includes(this.globalVendorArgs.writeMyself))
|
|
31285
|
+
continue;
|
|
31286
|
+
if (!baileyIsValidNumber(payload.from)) {
|
|
31287
|
+
continue;
|
|
31288
|
+
}
|
|
31289
|
+
const btnCtx = payload?.message?.buttonsResponseMessage?.selectedDisplayText;
|
|
31290
|
+
if (btnCtx)
|
|
31291
|
+
payload.body = btnCtx;
|
|
31292
|
+
const listRowId = payload?.message?.listResponseMessage?.title;
|
|
31293
|
+
if (listRowId)
|
|
31294
|
+
payload.body = listRowId;
|
|
31295
|
+
const processDuplicate = () => {
|
|
31296
|
+
if (messageCtx?.key?.id) {
|
|
31297
|
+
const idWs = `${messageCtx.key.id}__${payload.from}`;
|
|
31298
|
+
const isDuplicate = this.idsDuplicates.includes(idWs);
|
|
31299
|
+
if (isDuplicate) {
|
|
31300
|
+
this.idsDuplicates = [];
|
|
31301
|
+
return false;
|
|
31302
|
+
}
|
|
31303
|
+
if (this.idsDuplicates.length > 10) {
|
|
31304
|
+
this.idsDuplicates = [];
|
|
31305
|
+
}
|
|
31306
|
+
this.idsDuplicates.push(idWs);
|
|
31246
31307
|
}
|
|
31247
|
-
|
|
31308
|
+
return true;
|
|
31309
|
+
};
|
|
31310
|
+
if (processDuplicate()) {
|
|
31311
|
+
this.emit('message', payload);
|
|
31248
31312
|
}
|
|
31249
|
-
return true;
|
|
31250
|
-
};
|
|
31251
|
-
if (processDuplicate()) {
|
|
31252
|
-
this.emit('message', payload);
|
|
31253
31313
|
}
|
|
31254
31314
|
},
|
|
31255
31315
|
},
|
|
@@ -31563,11 +31623,11 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31563
31623
|
this.logStream = require$$0$5.createWriteStream(`${process.cwd()}/baileys.log`, {
|
|
31564
31624
|
flags: 'a',
|
|
31565
31625
|
autoClose: true,
|
|
31566
|
-
emitClose: true
|
|
31626
|
+
emitClose: true,
|
|
31567
31627
|
});
|
|
31568
31628
|
this.logger = new console$1.Console({
|
|
31569
31629
|
stdout: this.logStream,
|
|
31570
|
-
stderr: this.logStream
|
|
31630
|
+
stderr: this.logStream,
|
|
31571
31631
|
});
|
|
31572
31632
|
this.msgRetryCounterCache = new NodeCache({
|
|
31573
31633
|
stdTTL: 1800, // 30 minutos (más tiempo para reintentos)
|
|
@@ -31576,7 +31636,7 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31576
31636
|
deleteOnExpire: true,
|
|
31577
31637
|
useClones: false,
|
|
31578
31638
|
forceString: false,
|
|
31579
|
-
errorOnMissing: false
|
|
31639
|
+
errorOnMissing: false,
|
|
31580
31640
|
});
|
|
31581
31641
|
this.userDevicesCache = new NodeCache({
|
|
31582
31642
|
stdTTL: 7200, // 2 horas (dispositivos cambian poco)
|
|
@@ -31585,16 +31645,34 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31585
31645
|
deleteOnExpire: true,
|
|
31586
31646
|
useClones: false,
|
|
31587
31647
|
forceString: false,
|
|
31588
|
-
errorOnMissing: false
|
|
31648
|
+
errorOnMissing: false,
|
|
31589
31649
|
});
|
|
31590
31650
|
this.globalVendorArgs = { ...this.globalVendorArgs, ...args };
|
|
31591
31651
|
this.setupCleanupHandlers();
|
|
31592
|
-
|
|
31652
|
+
this.setupPeriodicCleanup();
|
|
31653
|
+
}
|
|
31654
|
+
/**
|
|
31655
|
+
* Setup cleanup handlers
|
|
31656
|
+
* @description
|
|
31657
|
+
* - Remove existing listeners to prevent duplicates
|
|
31658
|
+
* - Add new listeners
|
|
31659
|
+
* - Add cleanup function to all listeners
|
|
31660
|
+
* - Add cleanup function to uncaughtException and unhandledRejection
|
|
31661
|
+
* - Add cleanup function to SIGINT, SIGTERM, SIGUSR1, SIGUSR2
|
|
31662
|
+
* - Add cleanup function to process.exit
|
|
31663
|
+
*/
|
|
31593
31664
|
setupCleanupHandlers() {
|
|
31594
31665
|
const cleanup = () => {
|
|
31595
31666
|
this.logger.log(`[${new Date().toISOString()}] Iniciando limpieza de recursos...`);
|
|
31596
31667
|
this.cleanup();
|
|
31597
31668
|
};
|
|
31669
|
+
// Remove existing listeners to prevent duplicates
|
|
31670
|
+
process.removeAllListeners('SIGINT');
|
|
31671
|
+
process.removeAllListeners('SIGTERM');
|
|
31672
|
+
process.removeAllListeners('SIGUSR1');
|
|
31673
|
+
process.removeAllListeners('SIGUSR2');
|
|
31674
|
+
process.removeAllListeners('uncaughtException');
|
|
31675
|
+
process.removeAllListeners('unhandledRejection');
|
|
31598
31676
|
process.on('SIGINT', cleanup);
|
|
31599
31677
|
process.on('SIGTERM', cleanup);
|
|
31600
31678
|
process.on('SIGUSR1', cleanup);
|
|
@@ -31608,6 +31686,21 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31608
31686
|
this.logger.log(`[${new Date().toISOString()}] Unhandled Rejection at:`, promise, 'reason:', reason);
|
|
31609
31687
|
});
|
|
31610
31688
|
}
|
|
31689
|
+
setupPeriodicCleanup() {
|
|
31690
|
+
// Limpiar duplicados cada 10 minutos para evitar memory leaks
|
|
31691
|
+
setInterval(() => {
|
|
31692
|
+
const maxSize = 1000;
|
|
31693
|
+
if (this.idsDuplicates.length > maxSize) {
|
|
31694
|
+
this.logger.log(`[${new Date().toISOString()}] Cleaning duplicates array: ${this.idsDuplicates.length} -> ${maxSize}`);
|
|
31695
|
+
this.idsDuplicates = this.idsDuplicates.slice(-1e3); // Mantener solo los últimos 1000
|
|
31696
|
+
}
|
|
31697
|
+
// Limpiar mapSet si tiene demasiadas entradas
|
|
31698
|
+
if (this.mapSet.size > maxSize) {
|
|
31699
|
+
this.logger.log(`[${new Date().toISOString()}] Cleaning mapSet: ${this.mapSet.size} -> 0`);
|
|
31700
|
+
this.mapSet.clear();
|
|
31701
|
+
}
|
|
31702
|
+
}, 600000); // 10 minutos
|
|
31703
|
+
}
|
|
31611
31704
|
cleanup() {
|
|
31612
31705
|
try {
|
|
31613
31706
|
if (this.msgRetryCounterCache) {
|
|
@@ -31643,6 +31736,46 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31643
31736
|
.get('/', this.indexHome);
|
|
31644
31737
|
}
|
|
31645
31738
|
afterHttpServerInit() { }
|
|
31739
|
+
shouldReconnect(statusCode) {
|
|
31740
|
+
// Lista de códigos donde SÍ debemos reconectar
|
|
31741
|
+
const reconnectableCodes = [
|
|
31742
|
+
baileys.DisconnectReason.connectionClosed,
|
|
31743
|
+
baileys.DisconnectReason.connectionLost,
|
|
31744
|
+
baileys.DisconnectReason.connectionReplaced,
|
|
31745
|
+
baileys.DisconnectReason.timedOut,
|
|
31746
|
+
baileys.DisconnectReason.badSession,
|
|
31747
|
+
baileys.DisconnectReason.restartRequired,
|
|
31748
|
+
429, // Rate limited
|
|
31749
|
+
500, // Server error
|
|
31750
|
+
502, // Bad gateway
|
|
31751
|
+
503, // Service unavailable
|
|
31752
|
+
504, // Gateway timeout
|
|
31753
|
+
];
|
|
31754
|
+
return reconnectableCodes.includes(statusCode) && this.reconnectAttempts < this.maxReconnectAttempts;
|
|
31755
|
+
}
|
|
31756
|
+
async delayedReconnect() {
|
|
31757
|
+
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
31758
|
+
this.logger.log(`[${new Date().toISOString()}] Max reconnection attempts reached (${this.maxReconnectAttempts})`);
|
|
31759
|
+
this.emit('auth_failure', [
|
|
31760
|
+
`Maximum reconnection attempts reached`,
|
|
31761
|
+
`Please check your internet connection`,
|
|
31762
|
+
`Check baileys.log for details`,
|
|
31763
|
+
`Need help: https://link.codigoencasa.com/DISCORD`,
|
|
31764
|
+
]);
|
|
31765
|
+
return;
|
|
31766
|
+
}
|
|
31767
|
+
this.reconnectAttempts++;
|
|
31768
|
+
const delay = Math.min(this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1), 30000); // Max 30 segundos
|
|
31769
|
+
this.logger.log(`[${new Date().toISOString()}] Reconnection attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}ms`);
|
|
31770
|
+
setTimeout(async () => {
|
|
31771
|
+
try {
|
|
31772
|
+
this.initVendor().then((v) => this.listenOnEvents(v));
|
|
31773
|
+
}
|
|
31774
|
+
catch (error) {
|
|
31775
|
+
this.logger.log(`[${new Date().toISOString()}] Reconnection failed:`, error);
|
|
31776
|
+
}
|
|
31777
|
+
}, delay);
|
|
31778
|
+
}
|
|
31646
31779
|
}
|
|
31647
31780
|
|
|
31648
31781
|
exports.BaileysProvider = BaileysProvider;
|
package/dist/type.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { GlobalVendorArgs } from '@builderbot/bot/dist/types';
|
|
2
|
+
import { proto } from 'baileys';
|
|
2
3
|
export interface BaileyGlobalVendorArgs extends GlobalVendorArgs {
|
|
3
4
|
gifPlayback: boolean;
|
|
4
5
|
usePairingCode: boolean;
|
|
5
6
|
phoneNumber: string | null;
|
|
6
7
|
browser: string[];
|
|
7
8
|
experimentalSyncMessage?: string;
|
|
9
|
+
fallBackAction?: (ctx: proto.IWebMessageInfo) => Promise<void>;
|
|
8
10
|
useBaileysStore: boolean;
|
|
9
11
|
timeRelease?: number;
|
|
10
12
|
experimentalStore?: boolean;
|
package/dist/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC5D,WAAW,EAAE,OAAO,CAAA;IACpB,cAAc,EAAE,OAAO,CAAA;IACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9D,eAAe,EAAE,OAAO,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,YAAY,EAAE,OAAO,CAAA;IACrB,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,GAAG,CAAA;CACb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builderbot/provider-baileys",
|
|
3
|
-
"version": "1.2.10-alpha.
|
|
3
|
+
"version": "1.2.10-alpha.3",
|
|
4
4
|
"description": "Now I'm the model of a modern major general / The venerated Virginian veteran whose men are all / Lining up, to put me up on a pedestal / Writin' letters to relatives / Embellishin' my elegance and eloquence / But the elephant is in the room / The truth is in ya face when ya hear the British cannons go / BOOM",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Leifer Mendez <leifer33@gmail.com>",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/codigoencasa/bot-whatsapp#readme",
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@builderbot/bot": "^1.2.10-alpha.
|
|
33
|
+
"@builderbot/bot": "^1.2.10-alpha.3",
|
|
34
34
|
"@hapi/boom": "^10.0.1",
|
|
35
35
|
"@jest/globals": "^29.7.0",
|
|
36
36
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"fs-extra": "^11.2.0",
|
|
67
67
|
"node-cache": "^5.1.2"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "dace4eac9d90f82218ec1ce68fd649bb2b3c4fa5"
|
|
70
70
|
}
|