@realvare/based 2.6.1 → 2.6.22
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/README.MD +364 -364
- package/lib/Socket/messages-recv.js +34 -10
- package/lib/Socket/messages-send.js +38 -17
- package/lib/Socket/socket.js +1 -2
- package/lib/Types/Socket.d.ts +1 -1
- package/lib/Utils/cache-manager.js +7 -3
- package/lib/Utils/link-preview.js +22 -6
- package/lib/Utils/logger.js +53 -1
- package/lib/Utils/messages-media.js +2 -15
- package/lib/Utils/messages.js +40 -170
- package/lib/Utils/performance-config.js +16 -18
- package/lib/Utils/thumbnail.js +35 -0
- package/lib/Utils/use-multi-file-auth-state.js +5 -1
- package/package.json +6 -6
|
@@ -11,6 +11,7 @@ const WAProto_1 = require("../../WAProto");
|
|
|
11
11
|
const Defaults_1 = require("../Defaults");
|
|
12
12
|
const Types_1 = require("../Types");
|
|
13
13
|
const Utils_1 = require("../Utils");
|
|
14
|
+
const performance_config_1 = require("../Utils/performance-config");
|
|
14
15
|
const make_mutex_1 = require("../Utils/make-mutex");
|
|
15
16
|
const WABinary_1 = require("../WABinary");
|
|
16
17
|
const groups_1 = require("./groups");
|
|
@@ -1048,25 +1049,48 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1048
1049
|
upsertMessage(protoMsg, call.offline ? 'append' : 'notify');
|
|
1049
1050
|
}
|
|
1050
1051
|
});
|
|
1051
|
-
ev.on('connection.update', (
|
|
1052
|
-
|
|
1053
|
-
|
|
1052
|
+
ev.on('connection.update', (update) => {
|
|
1053
|
+
const { connection, lastDisconnect } = update;
|
|
1054
|
+
|
|
1055
|
+
if (connection === 'close') {
|
|
1056
|
+
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
1057
|
+
const shouldReconnect = statusCode !== Types_1.DisconnectReason.loggedOut;
|
|
1058
|
+
|
|
1059
|
+
if (shouldReconnect) {
|
|
1060
|
+
logger.info('Connection closed, will handle reconnection automatically');
|
|
1061
|
+
} else {
|
|
1062
|
+
logger.warn('Logged out, manual re-authentication required');
|
|
1063
|
+
}
|
|
1064
|
+
} else if (connection === 'open') {
|
|
1065
|
+
sendActiveReceipts = true;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
// Update sendActiveReceipts based on connection status
|
|
1069
|
+
if (typeof update.isOnline !== 'undefined') {
|
|
1070
|
+
sendActiveReceipts = update.isOnline;
|
|
1054
1071
|
logger.trace(`sendActiveReceipts set to "${sendActiveReceipts}"`);
|
|
1055
1072
|
}
|
|
1056
1073
|
});
|
|
1057
1074
|
|
|
1058
|
-
//
|
|
1075
|
+
// Enhanced retry logic for stuck pending messages with anti-ban delays
|
|
1059
1076
|
ev.on('messages.update', (updates) => {
|
|
1077
|
+
const config = getPerformanceConfig();
|
|
1060
1078
|
updates.forEach(update => {
|
|
1061
1079
|
if (update.update.status === WAProto_1.proto.WebMessageInfo.Status.PENDING &&
|
|
1062
1080
|
Date.now() - (update.update.timestamp || 0) > 30000) { // 30 seconds
|
|
1063
|
-
logger.debug({ key: update.key }, 'retrying stuck pending message');
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1081
|
+
logger.debug({ key: update.key }, 'retrying stuck pending message with anti-ban delay');
|
|
1082
|
+
|
|
1083
|
+
// Apply anti-ban delay before retry
|
|
1084
|
+
setTimeout(async () => {
|
|
1085
|
+
try {
|
|
1086
|
+
const msg = await getMessage(update.key);
|
|
1087
|
+
if (msg) {
|
|
1088
|
+
await relayMessage(update.key.remoteJid, msg, { messageId: update.key.id });
|
|
1089
|
+
}
|
|
1090
|
+
} catch (err) {
|
|
1091
|
+
logger.error({ err, key: update.key }, 'failed to retry stuck message');
|
|
1068
1092
|
}
|
|
1069
|
-
}
|
|
1093
|
+
}, config.security?.messageDelay?.min || 1000);
|
|
1070
1094
|
}
|
|
1071
1095
|
});
|
|
1072
1096
|
});
|
|
@@ -16,10 +16,12 @@ const WABinary_1 = require("../WABinary");
|
|
|
16
16
|
const WAUSync_1 = require("../WAUSync");
|
|
17
17
|
const newsletter_1 = require("./newsletter");
|
|
18
18
|
const rate_limiter_1 = __importDefault(require("../Utils/rate-limiter"));
|
|
19
|
+
const { generateThumbnail } = require("../Utils/thumbnail");
|
|
19
20
|
const makeMessagesSocket = (config) => {
|
|
20
21
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
|
|
21
22
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
|
22
23
|
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, } = sock;
|
|
24
|
+
|
|
23
25
|
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
|
24
26
|
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
25
27
|
useClones: false
|
|
@@ -275,6 +277,26 @@ const makeMessagesSocket = (config) => {
|
|
|
275
277
|
const isStatus = jid === statusJid;
|
|
276
278
|
const isLid = server === 'lid';
|
|
277
279
|
msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
|
|
280
|
+
if(message.contextInfo?.externalAdReply?.thumbnailUrl) {
|
|
281
|
+
try {
|
|
282
|
+
const { externalAdReply } = message.contextInfo;
|
|
283
|
+
const thumbnail = await generateThumbnail(externalAdReply.thumbnailUrl);
|
|
284
|
+
message.contextInfo.externalAdReply = {
|
|
285
|
+
...externalAdReply,
|
|
286
|
+
thumbnail,
|
|
287
|
+
renderLargerThumbnail: false,
|
|
288
|
+
};
|
|
289
|
+
delete message.contextInfo.externalAdReply.thumbnailUrl;
|
|
290
|
+
logger?.debug('Successfully generated thumbnail for external ad reply');
|
|
291
|
+
} catch(err) {
|
|
292
|
+
logger?.warn({ trace: err.stack, msg: message.contextInfo.externalAdReply }, 'failed to generate thumbnail for external ad reply, keeping thumbnailUrl as fallback');
|
|
293
|
+
// Ensure renderLargerThumbnail is set to false even on failure
|
|
294
|
+
if (message.contextInfo.externalAdReply.renderLargerThumbnail === undefined) {
|
|
295
|
+
message.contextInfo.externalAdReply.renderLargerThumbnail = false;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
278
300
|
useUserDevicesCache = useUserDevicesCache !== false;
|
|
279
301
|
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
|
280
302
|
const participants = [];
|
|
@@ -766,9 +788,9 @@ const makeMessagesSocket = (config) => {
|
|
|
766
788
|
parentMessageKey: albumMsg.key
|
|
767
789
|
}
|
|
768
790
|
};
|
|
769
|
-
await relayMessage(jid, mediaMsg.message, {
|
|
791
|
+
await rateLimiter.add(() => relayMessage(jid, mediaMsg.message, {
|
|
770
792
|
messageId: mediaMsg.key.id
|
|
771
|
-
});
|
|
793
|
+
}));
|
|
772
794
|
await new Promise(resolve => setTimeout(resolve, 800));
|
|
773
795
|
}
|
|
774
796
|
}
|
|
@@ -878,7 +900,7 @@ const makeMessagesSocket = (config) => {
|
|
|
878
900
|
parentMessageKey: packMsg.key
|
|
879
901
|
}
|
|
880
902
|
};
|
|
881
|
-
await relayMessage(jid, stickerMsg.message, { messageId: stickerMsg.key.id });
|
|
903
|
+
await rateLimiter.add(() => relayMessage(jid, stickerMsg.message, { messageId: stickerMsg.key.id }));
|
|
882
904
|
lastMsg = stickerMsg;
|
|
883
905
|
// Add delay between stickers to avoid rate limiting
|
|
884
906
|
await new Promise(resolve => setTimeout(resolve, 800));
|
|
@@ -1128,9 +1150,9 @@ const makeMessagesSocket = (config) => {
|
|
|
1128
1150
|
expectedVideoCount: album.filter(item => 'video' in item).length
|
|
1129
1151
|
}
|
|
1130
1152
|
}, { userJid, ...options });
|
|
1131
|
-
await relayMessage(jid, albumMsg.message, {
|
|
1153
|
+
await rateLimiter.add(() => relayMessage(jid, albumMsg.message, {
|
|
1132
1154
|
messageId: albumMsg.key.id
|
|
1133
|
-
});
|
|
1155
|
+
}));
|
|
1134
1156
|
for (const i in album) {
|
|
1135
1157
|
const media = album[i];
|
|
1136
1158
|
if ('image' in media) {
|
|
@@ -1291,18 +1313,17 @@ const makeMessagesSocket = (config) => {
|
|
|
1291
1313
|
messageId: (0, Utils_1.generateMessageIDV2)((_c = sock.user) === null || _c === void 0 ? void 0 : _c.id),
|
|
1292
1314
|
...options,
|
|
1293
1315
|
});
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
await new Promise(resolve => setTimeout(resolve, 800));
|
|
1316
|
+
// Associate sticker with the pack message
|
|
1317
|
+
stickerMsg.message.messageContextInfo = {
|
|
1318
|
+
messageSecret: (0, crypto_1.randomBytes)(32),
|
|
1319
|
+
messageAssociation: {
|
|
1320
|
+
associationType: 1,
|
|
1321
|
+
parentMessageKey: packMsg.key
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
await rateLimiter.add(() => relayMessage(jid, stickerMsg.message, { messageId: stickerMsg.key.id }));
|
|
1325
|
+
lastMsg = stickerMsg;
|
|
1326
|
+
await new Promise(resolve => setTimeout(resolve, 800));
|
|
1306
1327
|
}
|
|
1307
1328
|
return lastMsg;
|
|
1308
1329
|
}
|
package/lib/Socket/socket.js
CHANGED
|
@@ -698,8 +698,7 @@ const makeSocket = (config) => {
|
|
|
698
698
|
values,
|
|
699
699
|
selectableCount: selectableCount || 1,
|
|
700
700
|
};
|
|
701
|
-
|
|
702
|
-
return ws.sendMessage(jid, { poll: pollCreation });
|
|
701
|
+
return sock.sendMessage(jid, { poll: pollCreation });
|
|
703
702
|
},
|
|
704
703
|
// lid related functions
|
|
705
704
|
assertLid: (jid) => {
|
package/lib/Types/Socket.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type SocketConfig = {
|
|
|
29
29
|
connectTimeoutMs: number;
|
|
30
30
|
/** Default timeout for queries, undefined for no timeout */
|
|
31
31
|
defaultQueryTimeoutMs: number | undefined;
|
|
32
|
-
/** ping-
|
|
32
|
+
/** ping- inpongterval for WS connection */
|
|
33
33
|
keepAliveIntervalMs: number;
|
|
34
34
|
/** should baileys use the mobile api instead of the multi device api
|
|
35
35
|
* @deprecated This feature has been removed
|
|
@@ -7,20 +7,24 @@ class CacheManager {
|
|
|
7
7
|
const config = getPerformanceConfig();
|
|
8
8
|
this.caches = {};
|
|
9
9
|
this.memoryCheckInterval = null;
|
|
10
|
-
|
|
10
|
+
this.msgStore = null;
|
|
11
|
+
|
|
11
12
|
// Inizializza le cache con TTL
|
|
12
13
|
Object.entries(config.cache).forEach(([name, options]) => {
|
|
13
14
|
this.caches[name] = new NodeCache({
|
|
14
|
-
stdTTL: options.ttl / 1000,
|
|
15
|
+
stdTTL: options.ttl / 1000,
|
|
15
16
|
checkperiod: options.cleanupInterval / 1000,
|
|
16
17
|
maxKeys: options.maxSize
|
|
17
18
|
});
|
|
18
19
|
});
|
|
19
|
-
|
|
20
|
+
|
|
20
21
|
if (config.performance.enableMetrics) {
|
|
21
22
|
this.startMemoryMonitoring(config.performance.memoryThreshold);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
setMessageStore(msgStore) {
|
|
26
|
+
this.msgStore = msgStore;
|
|
27
|
+
}
|
|
24
28
|
|
|
25
29
|
startMemoryMonitoring(threshold) {
|
|
26
30
|
this.memoryCheckInterval = setInterval(() => {
|
|
@@ -36,12 +36,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.getUrlInfo = void 0;
|
|
37
37
|
const messages_1 = require("./messages");
|
|
38
38
|
const messages_media_1 = require("./messages-media");
|
|
39
|
-
const THUMBNAIL_WIDTH_PX =
|
|
39
|
+
const THUMBNAIL_WIDTH_PX = 1200;
|
|
40
40
|
/** Fetches an image and generates a thumbnail for it */
|
|
41
|
-
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts, logger }) => {
|
|
42
|
+
try {
|
|
43
|
+
const stream = await (0, messages_media_1.getHttpStream)(url, fetchOpts);
|
|
44
|
+
const result = await (0, messages_media_1.extractImageThumb)(stream, thumbnailWidth);
|
|
45
|
+
logger?.debug({ url, thumbnailWidth }, 'Successfully generated compressed JPEG thumbnail');
|
|
46
|
+
return result;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
logger?.warn({ url, thumbnailWidth, error: error.message }, 'Failed to generate compressed JPEG thumbnail, attempting fallback');
|
|
49
|
+
// Fallback to lower quality if high quality fails
|
|
50
|
+
try {
|
|
51
|
+
const stream = await (0, messages_media_1.getHttpStream)(url, fetchOpts);
|
|
52
|
+
const result = await (0, messages_media_1.extractImageThumb)(stream, Math.min(thumbnailWidth, 512));
|
|
53
|
+
logger?.debug({ url, fallbackWidth: Math.min(thumbnailWidth, 512) }, 'Successfully generated fallback thumbnail');
|
|
54
|
+
return result;
|
|
55
|
+
} catch (fallbackError) {
|
|
56
|
+
logger?.error({ url, error: fallbackError.message }, 'Failed to generate fallback thumbnail');
|
|
57
|
+
throw fallbackError;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
45
60
|
};
|
|
46
61
|
/**
|
|
47
62
|
* Given a piece of text, checks for any URL present, generates link preview for the same and returns it
|
|
@@ -86,6 +101,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
86
101
|
});
|
|
87
102
|
if (info && 'title' in info && info.title) {
|
|
88
103
|
const [image] = info.images;
|
|
104
|
+
opts.logger?.debug({ url: previewLink, title: info.title, imageCount: info.images.length }, 'Fetched link preview info');
|
|
89
105
|
const urlInfo = {
|
|
90
106
|
'canonical-url': info.url,
|
|
91
107
|
'matched-text': text,
|
|
@@ -107,7 +123,7 @@ const getUrlInfo = async (text, opts = {
|
|
|
107
123
|
else {
|
|
108
124
|
try {
|
|
109
125
|
urlInfo.jpegThumbnail = image
|
|
110
|
-
? (await getCompressedJpegThumbnail(image, opts)).buffer
|
|
126
|
+
? (await getCompressedJpegThumbnail(image, { ...opts, logger: opts.logger })).buffer
|
|
111
127
|
: undefined;
|
|
112
128
|
}
|
|
113
129
|
catch (error) {
|
package/lib/Utils/logger.js
CHANGED
|
@@ -4,4 +4,56 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const pino_1 = __importDefault(require("pino"));
|
|
7
|
-
|
|
7
|
+
const { getPerformanceConfig } = require('./performance-config');
|
|
8
|
+
const defaultLogger = (0, pino_1.default)({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
|
|
9
|
+
class EnhancedLogger {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.config = getPerformanceConfig();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static error(...args) {
|
|
15
|
+
if (defaultLogger.isLevelEnabled('error')) {
|
|
16
|
+
defaultLogger.error(...args);
|
|
17
|
+
}
|
|
18
|
+
// Additional error tracking if enabled
|
|
19
|
+
if (this.config?.debug?.enableErrorTracking) {
|
|
20
|
+
// Could send to external monitoring service
|
|
21
|
+
console.error('[ERROR TRACK]', ...args);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static warn(...args) {
|
|
26
|
+
if (defaultLogger.isLevelEnabled('warn')) {
|
|
27
|
+
defaultLogger.warn(...args);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static info(...args) {
|
|
32
|
+
if (this.config?.debug?.enableInfoLogging && defaultLogger.isLevelEnabled('info')) {
|
|
33
|
+
defaultLogger.info(...args);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static debug(...args) {
|
|
38
|
+
if (this.config?.debug?.enableDebugLogging && defaultLogger.isLevelEnabled('debug')) {
|
|
39
|
+
defaultLogger.debug(...args);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
static createBaileysLogger(level = 'info', prefix = 'Based') {
|
|
43
|
+
return {
|
|
44
|
+
level,
|
|
45
|
+
debug: (...args) => this.debug(`[${prefix}]`, ...args),
|
|
46
|
+
info: (...args) => this.info(`[${prefix}]`, ...args),
|
|
47
|
+
warn: (...args) => this.warn(`[${prefix}]`, ...args),
|
|
48
|
+
error: (...args) => this.error(`[${prefix}]`, ...args),
|
|
49
|
+
trace: (...args) => this.debug(`[${prefix} TRACE]`, ...args),
|
|
50
|
+
child: (bindings) => ({
|
|
51
|
+
...this.createBaileysLogger(level, prefix),
|
|
52
|
+
bindings
|
|
53
|
+
})
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.EnhancedLogger = EnhancedLogger;
|
|
59
|
+
exports.default = defaultLogger;
|
|
@@ -479,21 +479,8 @@ async function generateThumbnail(file, mediaType, options) {
|
|
|
479
479
|
};
|
|
480
480
|
}
|
|
481
481
|
const getHttpStream = async (url, options = {}) => {
|
|
482
|
-
const {
|
|
483
|
-
|
|
484
|
-
while (retries < maxMsgRetryCount) {
|
|
485
|
-
try {
|
|
486
|
-
const fetched = await axios_1.default.get(url.toString(), { ...options, responseType: 'stream' });
|
|
487
|
-
return fetched.data;
|
|
488
|
-
}
|
|
489
|
-
catch (error) {
|
|
490
|
-
retries++;
|
|
491
|
-
if (retries >= maxMsgRetryCount) {
|
|
492
|
-
throw error;
|
|
493
|
-
}
|
|
494
|
-
await (0, generics_1.delay)(retryRequestDelayMs || 1000);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
482
|
+
const fetched = await axios_1.default.get(url.toString(), { ...options, responseType: 'stream' });
|
|
483
|
+
return fetched.data;
|
|
497
484
|
};
|
|
498
485
|
exports.getHttpStream = getHttpStream;
|
|
499
486
|
const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
package/lib/Utils/messages.js
CHANGED
|
@@ -245,14 +245,14 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
245
245
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
246
246
|
var _p, _q;
|
|
247
247
|
|
|
248
|
-
//
|
|
248
|
+
// Cross-platform externalAdReply thumbnail handling
|
|
249
249
|
if (message.contextInfo?.externalAdReply) {
|
|
250
250
|
const externalAdReply = message.contextInfo.externalAdReply;
|
|
251
251
|
|
|
252
|
-
// If thumbnailUrl is provided but no thumbnail binary data, try to fetch and convert for
|
|
252
|
+
// If thumbnailUrl is provided but no thumbnail binary data, try to fetch and convert for all platforms
|
|
253
253
|
if (externalAdReply.thumbnailUrl && !externalAdReply.thumbnail) {
|
|
254
254
|
try {
|
|
255
|
-
// Attempt to download the thumbnail image for
|
|
255
|
+
// Attempt to download the thumbnail image for cross-platform compatibility
|
|
256
256
|
const axiosResponse = await axios_1.default.get(externalAdReply.thumbnailUrl, {
|
|
257
257
|
responseType: 'arraybuffer',
|
|
258
258
|
timeout: 5000,
|
|
@@ -265,13 +265,20 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
265
265
|
externalAdReply.thumbnail = Buffer.from(axiosResponse.data);
|
|
266
266
|
// Clear thumbnailUrl since we now have binary data
|
|
267
267
|
delete externalAdReply.thumbnailUrl;
|
|
268
|
+
options.logger?.debug('Successfully downloaded externalAdReply thumbnail for cross-platform compatibility');
|
|
268
269
|
}
|
|
269
270
|
} catch (error) {
|
|
270
|
-
// If thumbnail download fails, keep thumbnailUrl as
|
|
271
|
-
options.logger?.warn('Failed to download externalAdReply thumbnail for
|
|
271
|
+
// If thumbnail download fails, keep thumbnailUrl as fallback
|
|
272
|
+
options.logger?.warn('Failed to download externalAdReply thumbnail for cross-platform compatibility:', error.message);
|
|
272
273
|
}
|
|
273
274
|
}
|
|
274
275
|
|
|
276
|
+
// Ensure renderLargerThumbnail is set for better display across platforms
|
|
277
|
+
if (externalAdReply.renderLargerThumbnail === undefined) {
|
|
278
|
+
externalAdReply.renderLargerThumbnail = false;
|
|
279
|
+
options.logger?.debug('Set renderLargerThumbnail=false for improved cross-platform display');
|
|
280
|
+
}
|
|
281
|
+
|
|
275
282
|
// Update the contextInfo with modified externalAdReply
|
|
276
283
|
message.contextInfo.externalAdReply = externalAdReply;
|
|
277
284
|
}
|
|
@@ -557,7 +564,7 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
557
564
|
thumbnail: extAdReply.thumbnail,
|
|
558
565
|
sourceUrl: extAdReply.sourceUrl,
|
|
559
566
|
showAdAttribution: extAdReply.showAdAttribution || false,
|
|
560
|
-
renderLargerThumbnail: extAdReply.renderLargerThumbnail
|
|
567
|
+
renderLargerThumbnail: extAdReply.renderLargerThumbnail !== false
|
|
561
568
|
}
|
|
562
569
|
}
|
|
563
570
|
};
|
|
@@ -1187,187 +1194,50 @@ const assertMediaContent = (content) => {
|
|
|
1187
1194
|
return mediaContent;
|
|
1188
1195
|
};
|
|
1189
1196
|
exports.assertMediaContent = assertMediaContent;
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
const jidCache = new Map();
|
|
1194
|
-
const CACHE_TTL = 5 * 60 * 1000; // 5 minuti
|
|
1195
|
-
const MAX_CACHE_SIZE = 10000; // Massimo 10k entries
|
|
1196
|
-
|
|
1197
|
-
// Funzione per pulire cache scadute
|
|
1198
|
-
const cleanExpiredCache = (cache) => {
|
|
1199
|
-
const now = Date.now();
|
|
1200
|
-
for (const [key, value] of cache.entries()) {
|
|
1201
|
-
if (now - value.timestamp > CACHE_TTL) {
|
|
1202
|
-
cache.delete(key);
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
// Se la cache è troppo grande, rimuovi le entry più vecchie
|
|
1207
|
-
if (cache.size > MAX_CACHE_SIZE) {
|
|
1208
|
-
const entries = Array.from(cache.entries());
|
|
1209
|
-
entries.sort((a, b) => a[1].timestamp - b[1].timestamp);
|
|
1210
|
-
const toRemove = entries.slice(0, Math.floor(MAX_CACHE_SIZE * 0.2));
|
|
1211
|
-
toRemove.forEach(([key]) => cache.delete(key));
|
|
1212
|
-
}
|
|
1197
|
+
const getNormalizedJid = (jid) => {
|
|
1198
|
+
if (!jid) return jid;
|
|
1199
|
+
return (0, WABinary_1.jidNormalizedUser)(jid);
|
|
1213
1200
|
};
|
|
1201
|
+
exports.getNormalizedJid = getNormalizedJid;
|
|
1214
1202
|
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
}, 2 * 60 * 1000);
|
|
1203
|
+
const isLidFormat = (jid) => {
|
|
1204
|
+
return (0, WABinary_1.isLidUser)(jid);
|
|
1205
|
+
};
|
|
1206
|
+
exports.isLidFormat = isLidFormat;
|
|
1220
1207
|
|
|
1208
|
+
// Legacy compatibility functions - deprecated, use native APIs
|
|
1221
1209
|
const toJid = (id) => {
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
return '';
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
// Controlla cache
|
|
1228
|
-
if (jidCache.has(id)) {
|
|
1229
|
-
const cached = jidCache.get(id);
|
|
1230
|
-
if (Date.now() - cached.timestamp < CACHE_TTL) {
|
|
1231
|
-
return cached.result;
|
|
1232
|
-
} else {
|
|
1233
|
-
jidCache.delete(id);
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
let result = '';
|
|
1238
|
-
|
|
1239
|
-
if (id.endsWith('@lid')) {
|
|
1240
|
-
result = id.replace('@lid', '@s.whatsapp.net');
|
|
1241
|
-
} else if (id.includes('@')) {
|
|
1242
|
-
result = id;
|
|
1243
|
-
} else {
|
|
1244
|
-
result = `${id}@s.whatsapp.net`;
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
// Salva in cache
|
|
1248
|
-
jidCache.set(id, {
|
|
1249
|
-
result,
|
|
1250
|
-
timestamp: Date.now()
|
|
1251
|
-
});
|
|
1252
|
-
|
|
1253
|
-
return result;
|
|
1254
|
-
} catch (error) {
|
|
1255
|
-
console.error('Error in toJid:', error.message, 'Input:', id);
|
|
1256
|
-
return id || '';
|
|
1257
|
-
}
|
|
1210
|
+
console.warn('toJid is deprecated. Use getNormalizedJid instead.');
|
|
1211
|
+
return getNormalizedJid(id);
|
|
1258
1212
|
};
|
|
1259
1213
|
exports.toJid = toJid;
|
|
1260
1214
|
|
|
1261
1215
|
const getSenderLid = (message) => {
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
const sender = message.key.participant || message.key.remoteJid;
|
|
1268
|
-
if (!sender) {
|
|
1269
|
-
throw new Error('Invalid message: missing sender information');
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
// Controlla cache
|
|
1273
|
-
if (lidCache.has(sender)) {
|
|
1274
|
-
const cached = lidCache.get(sender);
|
|
1275
|
-
if (Date.now() - cached.timestamp < CACHE_TTL) {
|
|
1276
|
-
return cached.result;
|
|
1277
|
-
} else {
|
|
1278
|
-
lidCache.delete(sender);
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
const decoded = (0, WABinary_1.jidDecode)(sender);
|
|
1283
|
-
if (!decoded?.user) {
|
|
1284
|
-
throw new Error(`Invalid JID format: ${sender}`);
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
const user = decoded.user;
|
|
1288
|
-
const lid = (0, WABinary_1.jidEncode)(user, 'lid');
|
|
1289
|
-
|
|
1290
|
-
const result = {
|
|
1291
|
-
jid: sender,
|
|
1292
|
-
lid,
|
|
1293
|
-
isValid: true,
|
|
1294
|
-
user,
|
|
1295
|
-
timestamp: Date.now()
|
|
1296
|
-
};
|
|
1297
|
-
|
|
1298
|
-
// Log solo in debug mode
|
|
1299
|
-
if (process.env.DEBUG_LID === 'true') {
|
|
1300
|
-
console.log('sender lid:', lid, 'user:', user);
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
// Salva in cache
|
|
1304
|
-
lidCache.set(sender, {
|
|
1305
|
-
result,
|
|
1306
|
-
timestamp: Date.now()
|
|
1307
|
-
});
|
|
1308
|
-
|
|
1309
|
-
return result;
|
|
1310
|
-
|
|
1311
|
-
} catch (error) {
|
|
1312
|
-
console.error('Error in getSenderLid:', error.message, 'Message:', message?.key);
|
|
1313
|
-
|
|
1314
|
-
// Ritorna un oggetto di fallback valido
|
|
1315
|
-
return {
|
|
1316
|
-
jid: message?.key?.remoteJid || 'unknown',
|
|
1317
|
-
lid: 'unknown@lid',
|
|
1318
|
-
isValid: false,
|
|
1319
|
-
user: 'unknown',
|
|
1320
|
-
error: error.message,
|
|
1321
|
-
timestamp: Date.now()
|
|
1322
|
-
};
|
|
1323
|
-
}
|
|
1324
|
-
};
|
|
1325
|
-
exports.getSenderLid = getSenderLid;
|
|
1216
|
+
console.warn('getSenderLid is deprecated. Use getNormalizedJid and isLidFormat instead.');
|
|
1217
|
+
const sender = message?.key?.participant || message?.key?.remoteJid;
|
|
1218
|
+
if (!sender) return null;
|
|
1326
1219
|
|
|
1327
|
-
|
|
1328
|
-
const getCacheStats = () => {
|
|
1220
|
+
const normalized = getNormalizedJid(sender);
|
|
1329
1221
|
return {
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
},
|
|
1335
|
-
jidCache: {
|
|
1336
|
-
size: jidCache.size,
|
|
1337
|
-
maxSize: MAX_CACHE_SIZE,
|
|
1338
|
-
ttl: CACHE_TTL
|
|
1339
|
-
}
|
|
1222
|
+
jid: sender,
|
|
1223
|
+
lid: normalized,
|
|
1224
|
+
isValid: true,
|
|
1225
|
+
user: (0, WABinary_1.jidDecode)(normalized)?.user || 'unknown'
|
|
1340
1226
|
};
|
|
1341
1227
|
};
|
|
1342
|
-
exports.
|
|
1343
|
-
|
|
1344
|
-
const clearCache = () => {
|
|
1345
|
-
lidCache.clear();
|
|
1346
|
-
jidCache.clear();
|
|
1347
|
-
console.log(chalk.bold.magenta('- 🎐 | Cache cancellata correttamente'));
|
|
1348
|
-
};
|
|
1349
|
-
exports.clearCache = clearCache;
|
|
1228
|
+
exports.getSenderLid = getSenderLid;
|
|
1350
1229
|
|
|
1351
1230
|
const validateJid = (jid) => {
|
|
1231
|
+
console.warn('validateJid is deprecated. Use native Baileys validation.');
|
|
1352
1232
|
if (!jid || typeof jid !== 'string') {
|
|
1353
1233
|
return { isValid: false, error: 'Invalid JID: must be a non-empty string' };
|
|
1354
1234
|
}
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
return { isValid:
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
const [user, server] = parts;
|
|
1362
|
-
if (!user || !server) {
|
|
1363
|
-
return { isValid: false, error: 'Invalid JID: user and server parts cannot be empty' };
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
|
-
const validServers = ['s.whatsapp.net', 'g.us', 'broadcast', 'newsletter', 'lid', 'c.us'];
|
|
1367
|
-
if (!validServers.includes(server)) {
|
|
1368
|
-
return { isValid: false, error: `Invalid server: ${server}. Must be one of: ${validServers.join(', ')}` };
|
|
1235
|
+
|
|
1236
|
+
try {
|
|
1237
|
+
const decoded = (0, WABinary_1.jidDecode)(jid);
|
|
1238
|
+
return { isValid: !!decoded };
|
|
1239
|
+
} catch {
|
|
1240
|
+
return { isValid: false, error: 'Invalid JID format' };
|
|
1369
1241
|
}
|
|
1370
|
-
|
|
1371
|
-
return { isValid: true };
|
|
1372
1242
|
};
|
|
1373
1243
|
exports.validateJid = validateJid;
|