@builderbot/provider-baileys 1.2.8 → 1.2.10-2.0
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 +22 -1
- package/dist/bailey.d.ts.map +1 -1
- package/dist/baileyWrapper.d.ts +1 -1
- package/dist/baileyWrapper.d.ts.map +1 -1
- package/dist/index.cjs +313 -118
- package/dist/index.js +31779 -0
- package/dist/type.d.ts +2 -0
- package/dist/type.d.ts.map +1 -1
- package/package.json +14 -6
package/dist/bailey.d.ts
CHANGED
|
@@ -9,10 +9,29 @@ 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;
|
|
16
|
+
userDevicesCache?: NodeCache;
|
|
17
|
+
private logger;
|
|
18
|
+
private logStream;
|
|
13
19
|
private idsDuplicates;
|
|
14
20
|
private mapSet;
|
|
15
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
|
+
*/
|
|
32
|
+
private setupCleanupHandlers;
|
|
33
|
+
private setupPeriodicCleanup;
|
|
34
|
+
private cleanup;
|
|
16
35
|
releaseSessionFiles(): Promise<void>;
|
|
17
36
|
protected beforeHttpServerInit(): void;
|
|
18
37
|
protected afterHttpServerInit(): void;
|
|
@@ -40,7 +59,7 @@ declare class BaileysProvider extends ProviderClass<WASocket> {
|
|
|
40
59
|
* @param {string} orderToken
|
|
41
60
|
* @example await getOrderDetails('order-id', 'order-token')
|
|
42
61
|
*/
|
|
43
|
-
getOrderDetails: (orderId: string, orderToken: string) => Promise<import("baileys").OrderDetails>;
|
|
62
|
+
getOrderDetails: (orderId: string, orderToken: string) => Promise<import("@leifermendez/baileys").OrderDetails>;
|
|
44
63
|
/**
|
|
45
64
|
* @param {string} number
|
|
46
65
|
* @param {string} message
|
|
@@ -164,6 +183,8 @@ declare class BaileysProvider extends ProviderClass<WASocket> {
|
|
|
164
183
|
saveFile: (ctx: Partial<WAMessage & BotContext>, options?: {
|
|
165
184
|
path: string;
|
|
166
185
|
}) => Promise<string>;
|
|
186
|
+
private shouldReconnect;
|
|
187
|
+
private delayedReconnect;
|
|
167
188
|
}
|
|
168
189
|
export { BaileysProvider };
|
|
169
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,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AE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,WAAW,EAAE,GAAG,CAAA;KAAE,2CAa9F;IAED;;;;;;OAMG;IAEH,WAAW,GAAU,UAAU,MAAM,EAAE,SAAS,MAAM,EAAE,UAAU,WAAW,KAAG,OAAO,CAAC,GAAG,CAAC,CAM3F;IAED;;;;;;OAMG;IAEH,YAAY,GAAU,WAAW,MAAM,EAAE,UAAU,GAAG,EAAE,WAAW,GAAG,EAAE,WAAU,GAAU;;OAa3F;IAED;;;;;;;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/baileyWrapper.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMultiFileAuthState, DisconnectReason, proto, makeCacheableSignalKeyStore, getAggregateVotesInPollMessage, WASocket, BaileysEventMap, AnyMediaMessageContent, AnyMessageContent, PollMessageOptions, downloadMediaMessage, WAMessage, MessageUpsertType, isJidGroup, isJidBroadcast } from 'baileys';
|
|
1
|
+
import { useMultiFileAuthState, DisconnectReason, proto, makeCacheableSignalKeyStore, getAggregateVotesInPollMessage, WASocket, BaileysEventMap, AnyMediaMessageContent, AnyMessageContent, PollMessageOptions, downloadMediaMessage, WAMessage, MessageUpsertType, isJidGroup, isJidBroadcast } from '@leifermendez/baileys';
|
|
2
2
|
declare const makeWASocketOther: any;
|
|
3
3
|
export { makeWASocketOther, useMultiFileAuthState, DisconnectReason, proto, makeCacheableSignalKeyStore, getAggregateVotesInPollMessage, WASocket, BaileysEventMap, AnyMediaMessageContent, AnyMessageContent, PollMessageOptions, downloadMediaMessage, WAMessage, MessageUpsertType, isJidGroup, isJidBroadcast, };
|
|
4
4
|
//# sourceMappingURL=baileyWrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baileyWrapper.d.ts","sourceRoot":"","sources":["../src/baileyWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,QAAQ,EACR,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,cAAc,EACjB,MAAM,
|
|
1
|
+
{"version":3,"file":"baileyWrapper.d.ts","sourceRoot":"","sources":["../src/baileyWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,QAAQ,EACR,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,cAAc,EACjB,MAAM,uBAAuB,CAAA;AAE9B,QAAA,MAAM,iBAAiB,KAA2C,CAAA;AAElE,OAAO,EACH,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,EACL,2BAA2B,EAC3B,8BAA8B,EAC9B,QAAQ,EACR,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,cAAc,GACjB,CAAA"}
|
package/dist/index.cjs
CHANGED
|
@@ -22,7 +22,7 @@ var require$$1$4 = require('tty');
|
|
|
22
22
|
var require$$0$9 = require('crypto');
|
|
23
23
|
var require$$0$b = require('sharp');
|
|
24
24
|
var require$$0$a = require('fluent-ffmpeg');
|
|
25
|
-
var baileys = require('baileys');
|
|
25
|
+
var baileys = require('@leifermendez/baileys');
|
|
26
26
|
|
|
27
27
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
28
28
|
|
|
@@ -30901,7 +30901,7 @@ function requireDist () {
|
|
|
30901
30901
|
|
|
30902
30902
|
var distExports = requireDist();
|
|
30903
30903
|
|
|
30904
|
-
const makeWASocketOther = require('baileys').default;
|
|
30904
|
+
const makeWASocketOther = require('@leifermendez/baileys').default;
|
|
30905
30905
|
|
|
30906
30906
|
const keepFiles = ['creds.json', 'baileys_store.json', 'app-state-sync', 'session'];
|
|
30907
30907
|
/**
|
|
@@ -30936,9 +30936,6 @@ const releaseTmp = async (sessionName, ms) => {
|
|
|
30936
30936
|
return idTimer;
|
|
30937
30937
|
};
|
|
30938
30938
|
|
|
30939
|
-
const logger = new console$1.Console({
|
|
30940
|
-
stdout: require$$0$5.createWriteStream(`${process.cwd()}/baileys.log`),
|
|
30941
|
-
});
|
|
30942
30939
|
class BaileysProvider extends bot.ProviderClass {
|
|
30943
30940
|
constructor(args) {
|
|
30944
30941
|
super();
|
|
@@ -30946,7 +30943,7 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
30946
30943
|
name: `bot`,
|
|
30947
30944
|
gifPlayback: false,
|
|
30948
30945
|
usePairingCode: false,
|
|
30949
|
-
browser: ['Windows', '
|
|
30946
|
+
browser: ['Windows', 'Chrome', 'Chrome 114.0.5735.198'],
|
|
30950
30947
|
phoneNumber: null,
|
|
30951
30948
|
useBaileysStore: true,
|
|
30952
30949
|
port: 3000,
|
|
@@ -30957,7 +30954,11 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
30957
30954
|
experimentalStore: false,
|
|
30958
30955
|
autoRefresh: 0,
|
|
30959
30956
|
experimentalSyncMessage: undefined,
|
|
30957
|
+
fallBackAction: undefined,
|
|
30960
30958
|
};
|
|
30959
|
+
this.reconnectAttempts = 0;
|
|
30960
|
+
this.maxReconnectAttempts = 10;
|
|
30961
|
+
this.reconnectDelay = 1000; // 1 segundo inicial
|
|
30961
30962
|
this.idsDuplicates = [];
|
|
30962
30963
|
this.mapSet = new Set();
|
|
30963
30964
|
this.indexHome = (req, res) => {
|
|
@@ -31005,13 +31006,13 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31005
31006
|
}
|
|
31006
31007
|
}
|
|
31007
31008
|
catch (e) {
|
|
31008
|
-
logger.log(e);
|
|
31009
|
+
this.logger.log(e);
|
|
31009
31010
|
this.initVendor().then((v) => this.listenOnEvents(v));
|
|
31010
31011
|
}
|
|
31011
31012
|
try {
|
|
31012
31013
|
const sock = makeWASocketOther({
|
|
31013
31014
|
logger: loggerBaileys,
|
|
31014
|
-
version: [2, 3000,
|
|
31015
|
+
version: [2, 3000, 1023223821],
|
|
31015
31016
|
printQRInTerminal: false,
|
|
31016
31017
|
auth: {
|
|
31017
31018
|
creds: state.creds,
|
|
@@ -31023,10 +31024,14 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31023
31024
|
generateHighQualityLinkPreview: true,
|
|
31024
31025
|
getMessage: this.getMessage,
|
|
31025
31026
|
msgRetryCounterCache: this.msgRetryCounterCache,
|
|
31026
|
-
|
|
31027
|
-
|
|
31028
|
-
|
|
31029
|
-
|
|
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
|
|
31030
31035
|
shouldIgnoreJid: (jid) => {
|
|
31031
31036
|
if (this.globalVendorArgs.groupsIgnore) {
|
|
31032
31037
|
return baileys.isJidGroup(jid) || baileys.isJidBroadcast(jid);
|
|
@@ -31075,22 +31080,40 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31075
31080
|
}
|
|
31076
31081
|
sock.ev.on('connection.update', async (update) => {
|
|
31077
31082
|
const { connection, lastDisconnect, qr } = update;
|
|
31083
|
+
this.logger.log(`[${new Date().toISOString()}] Connection update: ${connection}`);
|
|
31078
31084
|
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
31085
|
+
const reason = lastDisconnect?.error?.message;
|
|
31079
31086
|
/** Connection closed for various reasons */
|
|
31080
31087
|
if (connection === 'close') {
|
|
31081
|
-
|
|
31082
|
-
|
|
31083
|
-
return;
|
|
31084
|
-
}
|
|
31088
|
+
this.logger.log(`[${new Date().toISOString()}] Connection closed. Status: ${statusCode}, Reason: ${reason}`);
|
|
31089
|
+
// Casos donde NO debemos reconectar
|
|
31085
31090
|
if (statusCode === baileys.DisconnectReason.loggedOut) {
|
|
31086
|
-
|
|
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`);
|
|
31087
31093
|
await emptyDirSessions(PATH_BASE);
|
|
31088
|
-
this.
|
|
31094
|
+
this.reconnectAttempts = 0;
|
|
31095
|
+
await this.delayedReconnect();
|
|
31096
|
+
return;
|
|
31097
|
+
}
|
|
31098
|
+
// Casos donde debemos reconectar con backoff
|
|
31099
|
+
if (this.shouldReconnect(statusCode)) {
|
|
31100
|
+
await this.delayedReconnect();
|
|
31089
31101
|
return;
|
|
31090
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
|
+
]);
|
|
31091
31111
|
}
|
|
31092
31112
|
/** Connection opened successfully */
|
|
31093
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
|
|
31094
31117
|
const parseNumber = `${sock?.user?.id}`.split(':').shift();
|
|
31095
31118
|
const host = { ...sock?.user, phone: parseNumber };
|
|
31096
31119
|
this.globalVendorArgs.host = host;
|
|
@@ -31099,6 +31122,7 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31099
31122
|
}
|
|
31100
31123
|
/** QR Code */
|
|
31101
31124
|
if (qr && !this.globalVendorArgs.usePairingCode) {
|
|
31125
|
+
this.logger.log(`[${new Date().toISOString()}] QR Code received`);
|
|
31102
31126
|
this.emit('require_action', {
|
|
31103
31127
|
title: '⚡⚡ ACTION REQUIRED ⚡⚡',
|
|
31104
31128
|
instructions: [
|
|
@@ -31117,7 +31141,7 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31117
31141
|
return sock.ev;
|
|
31118
31142
|
}
|
|
31119
31143
|
catch (e) {
|
|
31120
|
-
logger.log(e);
|
|
31144
|
+
this.logger.log(e);
|
|
31121
31145
|
this.emit('auth_failure', [
|
|
31122
31146
|
`Something unexpected has occurred, do not panic`,
|
|
31123
31147
|
`Restart the BOT`,
|
|
@@ -31147,112 +31171,145 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31147
31171
|
await this.vendor.sendMessage(jid, { text: this.globalVendorArgs.experimentalSyncMessage });
|
|
31148
31172
|
}
|
|
31149
31173
|
catch (e) {
|
|
31150
|
-
logger.log(e);
|
|
31174
|
+
this.logger.log(e);
|
|
31151
31175
|
}
|
|
31152
31176
|
}
|
|
31153
31177
|
};
|
|
31154
|
-
const
|
|
31155
|
-
|
|
31156
|
-
|
|
31157
|
-
|
|
31158
|
-
messageCtx
|
|
31159
|
-
|
|
31160
|
-
|
|
31161
|
-
messageCtx
|
|
31162
|
-
|
|
31163
|
-
|
|
31164
|
-
messageCtx
|
|
31165
|
-
|
|
31166
|
-
this.globalVendorArgs.
|
|
31167
|
-
|
|
31168
|
-
|
|
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;
|
|
31198
|
+
}
|
|
31199
|
+
if (this.globalVendorArgs.experimentalSyncMessage &&
|
|
31200
|
+
this.globalVendorArgs.experimentalSyncMessage.length) {
|
|
31201
|
+
if (baileyIsValidNumber(messageCtx?.key?.remoteJid)) {
|
|
31202
|
+
await pingMessageSync(messageCtx);
|
|
31203
|
+
}
|
|
31204
|
+
continue;
|
|
31169
31205
|
}
|
|
31206
|
+
continue;
|
|
31170
31207
|
}
|
|
31171
|
-
|
|
31172
|
-
|
|
31173
|
-
|
|
31174
|
-
|
|
31175
|
-
|
|
31176
|
-
|
|
31177
|
-
|
|
31178
|
-
|
|
31179
|
-
|
|
31180
|
-
|
|
31181
|
-
|
|
31182
|
-
|
|
31183
|
-
|
|
31184
|
-
|
|
31185
|
-
|
|
31186
|
-
|
|
31187
|
-
|
|
31188
|
-
|
|
31189
|
-
|
|
31190
|
-
|
|
31191
|
-
|
|
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
|
+
}
|
|
31192
31240
|
}
|
|
31193
|
-
|
|
31194
|
-
|
|
31195
|
-
|
|
31196
|
-
|
|
31197
|
-
|
|
31198
|
-
|
|
31199
|
-
|
|
31200
|
-
|
|
31201
|
-
|
|
31202
|
-
|
|
31203
|
-
|
|
31204
|
-
|
|
31205
|
-
|
|
31206
|
-
//Detectar file
|
|
31207
|
-
if (messageCtx.message?.documentMessage || messageCtx.message?.documentWithCaptionMessage) {
|
|
31208
|
-
payload = { ...payload, body: bot.utils.generateRefProvider('_event_document_') };
|
|
31209
|
-
}
|
|
31210
|
-
//Detectar voice note
|
|
31211
|
-
if (messageCtx.message?.audioMessage) {
|
|
31212
|
-
payload = { ...payload, body: bot.utils.generateRefProvider('_event_voice_note_') };
|
|
31213
|
-
}
|
|
31214
|
-
//Detectar order message
|
|
31215
|
-
if (messageCtx.message?.orderMessage) {
|
|
31216
|
-
payload = { ...payload, body: bot.utils.generateRefProvider('_event_order_') };
|
|
31217
|
-
}
|
|
31218
|
-
if (payload.from === 'status@broadcast')
|
|
31219
|
-
return;
|
|
31220
|
-
payload.from = baileyCleanNumber(payload.from, true);
|
|
31221
|
-
if (this.globalVendorArgs.writeMyself === 'none' && payload?.key?.fromMe)
|
|
31222
|
-
return;
|
|
31223
|
-
if (this.globalVendorArgs.host?.phone !== payload.from &&
|
|
31224
|
-
payload?.key?.fromMe &&
|
|
31225
|
-
!['both'].includes(this.globalVendorArgs.writeMyself))
|
|
31226
|
-
return;
|
|
31227
|
-
if (this.globalVendorArgs.host?.phone === payload.from &&
|
|
31228
|
-
!['both', 'host'].includes(this.globalVendorArgs.writeMyself))
|
|
31229
|
-
return;
|
|
31230
|
-
if (!baileyIsValidNumber(payload.from)) {
|
|
31231
|
-
return;
|
|
31232
|
-
}
|
|
31233
|
-
const btnCtx = payload?.message?.buttonsResponseMessage?.selectedDisplayText;
|
|
31234
|
-
if (btnCtx)
|
|
31235
|
-
payload.body = btnCtx;
|
|
31236
|
-
const listRowId = payload?.message?.listResponseMessage?.title;
|
|
31237
|
-
if (listRowId)
|
|
31238
|
-
payload.body = listRowId;
|
|
31239
|
-
const processDuplicate = () => {
|
|
31240
|
-
if (messageCtx?.key?.id) {
|
|
31241
|
-
const idWs = `${messageCtx.key.id}__${payload.from}`;
|
|
31242
|
-
const isDuplicate = this.idsDuplicates.includes(idWs);
|
|
31243
|
-
if (isDuplicate) {
|
|
31244
|
-
this.idsDuplicates = [];
|
|
31245
|
-
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
|
+
};
|
|
31246
31254
|
}
|
|
31247
|
-
|
|
31248
|
-
|
|
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);
|
|
31249
31307
|
}
|
|
31250
|
-
|
|
31308
|
+
return true;
|
|
31309
|
+
};
|
|
31310
|
+
if (processDuplicate()) {
|
|
31311
|
+
this.emit('message', payload);
|
|
31251
31312
|
}
|
|
31252
|
-
return true;
|
|
31253
|
-
};
|
|
31254
|
-
if (processDuplicate()) {
|
|
31255
|
-
this.emit('message', payload);
|
|
31256
31313
|
}
|
|
31257
31314
|
},
|
|
31258
31315
|
},
|
|
@@ -31274,7 +31331,6 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31274
31331
|
messageCtx.update.pollUpdates.length === 0) {
|
|
31275
31332
|
continue;
|
|
31276
31333
|
}
|
|
31277
|
-
messageCtx?.update?.pollUpdates[0]?.pollUpdateMessageKey;
|
|
31278
31334
|
const payload = {
|
|
31279
31335
|
...messageCtx,
|
|
31280
31336
|
body: pollMessage.find((poll) => poll.voters.length > 0)?.name || '',
|
|
@@ -31564,8 +31620,107 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31564
31620
|
await promises.writeFile(pathFile, buffer);
|
|
31565
31621
|
return require$$1$1.resolve(pathFile);
|
|
31566
31622
|
};
|
|
31567
|
-
this.
|
|
31623
|
+
this.logStream = require$$0$5.createWriteStream(`${process.cwd()}/baileys.log`, {
|
|
31624
|
+
flags: 'a',
|
|
31625
|
+
autoClose: true,
|
|
31626
|
+
emitClose: true,
|
|
31627
|
+
});
|
|
31628
|
+
this.logger = new console$1.Console({
|
|
31629
|
+
stdout: this.logStream,
|
|
31630
|
+
stderr: this.logStream,
|
|
31631
|
+
});
|
|
31632
|
+
this.msgRetryCounterCache = new NodeCache({
|
|
31633
|
+
stdTTL: 1800, // 30 minutos (más tiempo para reintentos)
|
|
31634
|
+
checkperiod: 300, // Limpieza cada 5 minutos (menos frecuente)
|
|
31635
|
+
maxKeys: 50000, // 50K entradas (más espacio)
|
|
31636
|
+
deleteOnExpire: true,
|
|
31637
|
+
useClones: false,
|
|
31638
|
+
forceString: false,
|
|
31639
|
+
errorOnMissing: false,
|
|
31640
|
+
});
|
|
31641
|
+
this.userDevicesCache = new NodeCache({
|
|
31642
|
+
stdTTL: 7200, // 2 horas (dispositivos cambian poco)
|
|
31643
|
+
checkperiod: 600, // Limpieza cada 10 minutos
|
|
31644
|
+
maxKeys: 5000, // Más dispositivos
|
|
31645
|
+
deleteOnExpire: true,
|
|
31646
|
+
useClones: false,
|
|
31647
|
+
forceString: false,
|
|
31648
|
+
errorOnMissing: false,
|
|
31649
|
+
});
|
|
31568
31650
|
this.globalVendorArgs = { ...this.globalVendorArgs, ...args };
|
|
31651
|
+
this.setupCleanupHandlers();
|
|
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
|
+
*/
|
|
31664
|
+
setupCleanupHandlers() {
|
|
31665
|
+
const cleanup = () => {
|
|
31666
|
+
this.logger.log(`[${new Date().toISOString()}] Iniciando limpieza de recursos...`);
|
|
31667
|
+
this.cleanup();
|
|
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');
|
|
31676
|
+
process.on('SIGINT', cleanup);
|
|
31677
|
+
process.on('SIGTERM', cleanup);
|
|
31678
|
+
process.on('SIGUSR1', cleanup);
|
|
31679
|
+
process.on('SIGUSR2', cleanup);
|
|
31680
|
+
process.on('uncaughtException', (error) => {
|
|
31681
|
+
this.logger.log(`[${new Date().toISOString()}] Uncaught Exception:`, error);
|
|
31682
|
+
this.cleanup();
|
|
31683
|
+
process.exit(1);
|
|
31684
|
+
});
|
|
31685
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
31686
|
+
this.logger.log(`[${new Date().toISOString()}] Unhandled Rejection at:`, promise, 'reason:', reason);
|
|
31687
|
+
});
|
|
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
|
+
}
|
|
31704
|
+
cleanup() {
|
|
31705
|
+
try {
|
|
31706
|
+
if (this.msgRetryCounterCache) {
|
|
31707
|
+
this.msgRetryCounterCache.close();
|
|
31708
|
+
this.msgRetryCounterCache = undefined;
|
|
31709
|
+
}
|
|
31710
|
+
if (this.userDevicesCache) {
|
|
31711
|
+
this.userDevicesCache.close();
|
|
31712
|
+
this.userDevicesCache = undefined;
|
|
31713
|
+
}
|
|
31714
|
+
this.mapSet.clear();
|
|
31715
|
+
this.idsDuplicates.length = 0;
|
|
31716
|
+
if (this.logStream && typeof this.logStream.end === 'function') {
|
|
31717
|
+
this.logStream.end();
|
|
31718
|
+
}
|
|
31719
|
+
this.logger.log(`[${new Date().toISOString()}] Recursos limpiados correctamente`);
|
|
31720
|
+
}
|
|
31721
|
+
catch (error) {
|
|
31722
|
+
console.error('Error durante cleanup:', error);
|
|
31723
|
+
}
|
|
31569
31724
|
}
|
|
31570
31725
|
async releaseSessionFiles() {
|
|
31571
31726
|
const NAME_DIR_SESSION = `${this.globalVendorArgs.name}_sessions`;
|
|
@@ -31581,6 +31736,46 @@ class BaileysProvider extends bot.ProviderClass {
|
|
|
31581
31736
|
.get('/', this.indexHome);
|
|
31582
31737
|
}
|
|
31583
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
|
+
}
|
|
31584
31779
|
}
|
|
31585
31780
|
|
|
31586
31781
|
exports.BaileysProvider = BaileysProvider;
|