@realvare/based 2.7.3 → 2.7.4
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/lib/Socket/groups.js +2 -2
- package/lib/Socket/messages-recv.js +59 -42
- package/lib/Utils/messages.js +0 -45
- package/package.json +2 -2
package/lib/Socket/groups.js
CHANGED
|
@@ -320,8 +320,8 @@ const extractGroupMetadata = (result) => {
|
|
|
320
320
|
participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
|
|
321
321
|
return {
|
|
322
322
|
id: attrs.jid,
|
|
323
|
-
jid: attrs.phone_number || attrs.jid,
|
|
324
|
-
lid: attrs.lid || attrs.jid,
|
|
323
|
+
jid: attrs.phone_number || (0, WABinary_1.lidToJid)(attrs.jid),
|
|
324
|
+
lid: attrs.lid || ((0, WABinary_1.isLid)(attrs.jid) ? attrs.jid : undefined),
|
|
325
325
|
admin: (attrs.type || null),
|
|
326
326
|
};
|
|
327
327
|
}),
|
|
@@ -35,6 +35,12 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
35
35
|
useClones: false
|
|
36
36
|
});
|
|
37
37
|
let sendActiveReceipts = false;
|
|
38
|
+
const resolveJid = (jid) => {
|
|
39
|
+
if (typeof jid === 'string' && jid.endsWith('@lid')) {
|
|
40
|
+
return (0, WABinary_1.lidToJid)(jid);
|
|
41
|
+
}
|
|
42
|
+
return jid;
|
|
43
|
+
};
|
|
38
44
|
const sendMessageAck = async ({ tag, attrs, content }, errorCode) => {
|
|
39
45
|
const stanza = {
|
|
40
46
|
tag: 'ack',
|
|
@@ -354,22 +360,28 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
354
360
|
default:
|
|
355
361
|
// console.log("BAILEYS-DEBUG:", JSON.stringify({ ...child, content: Buffer.isBuffer(child.content) ? child.content.toString() : child.content, participant }, null, 2))
|
|
356
362
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (typeof param === 'string' && param.endsWith('@lid')) {
|
|
362
|
-
const found = metadata.participants.find(p => p.id === param);
|
|
363
|
-
return found?.jid || (0, WABinary_1.lidToJid)(param);
|
|
364
|
-
}
|
|
365
|
-
return param;
|
|
366
|
-
}));
|
|
367
|
-
}
|
|
368
|
-
// Also resolve key.participant if needed
|
|
369
|
-
if (msg.key?.participant && msg.key.participant.endsWith('@lid')) {
|
|
363
|
+
const needsResolving = (msg.messageStubParameters && msg.messageStubParameters.some(p => typeof p === 'string' && (0, WABinary_1.isLid)(p))) ||
|
|
364
|
+
(participant && (0, WABinary_1.isLid)(participant)) ||
|
|
365
|
+
(msg.key?.participant && (0, WABinary_1.isLid)(msg.key.participant));
|
|
366
|
+
if(needsResolving) {
|
|
370
367
|
const metadata = await groupMetadata(groupJid);
|
|
371
|
-
|
|
372
|
-
|
|
368
|
+
if (msg.messageStubParameters) {
|
|
369
|
+
msg.messageStubParameters = await Promise.all(msg.messageStubParameters.map(async (param) => {
|
|
370
|
+
if (typeof param === 'string' && (0, WABinary_1.isLid)(param)) {
|
|
371
|
+
const found = metadata.participants.find(p => p.id === param);
|
|
372
|
+
return found?.jid || (0, WABinary_1.lidToJid)(param);
|
|
373
|
+
}
|
|
374
|
+
return param;
|
|
375
|
+
}));
|
|
376
|
+
}
|
|
377
|
+
if(participant && (0, WABinary_1.isLid)(participant)) {
|
|
378
|
+
const found = metadata.participants.find(p => p.id === participant);
|
|
379
|
+
msg.participant = found?.jid || (0, WABinary_1.lidToJid)(participant);
|
|
380
|
+
}
|
|
381
|
+
if (msg.key?.participant && (0, WABinary_1.isLid)(msg.key.participant)) {
|
|
382
|
+
const found = metadata.participants.find(p => p.id === msg.key.participant);
|
|
383
|
+
msg.key.participant = found?.jid || (0, WABinary_1.lidToJid)(msg.key.participant);
|
|
384
|
+
}
|
|
373
385
|
}
|
|
374
386
|
};
|
|
375
387
|
const handleNewsletterNotification = (id, node) => {
|
|
@@ -421,12 +433,12 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
421
433
|
const result = {};
|
|
422
434
|
const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
423
435
|
const nodeType = node.attrs.type;
|
|
424
|
-
const from = (0, WABinary_1.jidNormalizedUser)(node.attrs.from);
|
|
436
|
+
const from = resolveJid((0, WABinary_1.jidNormalizedUser)(node.attrs.from));
|
|
425
437
|
switch (nodeType) {
|
|
426
438
|
case 'privacy_token':
|
|
427
439
|
const tokenList = (0, WABinary_1.getBinaryNodeChildren)(child, 'token');
|
|
428
440
|
for (const { attrs, content } of tokenList) {
|
|
429
|
-
const jid = attrs.jid;
|
|
441
|
+
const jid = resolveJid(attrs.jid);
|
|
430
442
|
ev.emit('chats.update', [
|
|
431
443
|
{
|
|
432
444
|
id: jid,
|
|
@@ -455,7 +467,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
455
467
|
case 'devices':
|
|
456
468
|
const devices = (0, WABinary_1.getBinaryNodeChildren)(child, 'device');
|
|
457
469
|
if ((0, WABinary_1.areJidsSameUser)(child.attrs.jid, authState.creds.me.id)) {
|
|
458
|
-
const deviceJids = devices.map(d => d.attrs.jid);
|
|
470
|
+
const deviceJids = devices.map(d => resolveJid(d.attrs.jid));
|
|
459
471
|
logger.info({ deviceJids }, 'got my own devices');
|
|
460
472
|
}
|
|
461
473
|
break;
|
|
@@ -470,7 +482,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
470
482
|
const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
|
|
471
483
|
const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
|
|
472
484
|
ev.emit('contacts.update', [{
|
|
473
|
-
id: from || ((_b = (_a = (setPicture || delPicture)) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.hash) || '',
|
|
485
|
+
id: resolveJid(from) || ((_b = (_a = (setPicture || delPicture)) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.hash) || '',
|
|
474
486
|
imgUrl: setPicture ? 'changed' : 'removed'
|
|
475
487
|
}]);
|
|
476
488
|
if ((0, WABinary_1.isJidGroup)(from)) {
|
|
@@ -484,6 +496,15 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
484
496
|
...result.key || {},
|
|
485
497
|
participant: setPicture === null || setPicture === void 0 ? void 0 : setPicture.attrs.author
|
|
486
498
|
};
|
|
499
|
+
const metadata = await groupMetadata(from);
|
|
500
|
+
if (result.participant && result.participant.endsWith('@lid')) {
|
|
501
|
+
const found = metadata.participants.find(p => p.id === result.participant);
|
|
502
|
+
result.participant = found?.jid || (0, WABinary_1.lidToJid)(result.participant);
|
|
503
|
+
}
|
|
504
|
+
if (result.key?.participant && result.key.participant.endsWith('@lid')) {
|
|
505
|
+
const found = metadata.participants.find(p => p.id === result.key.participant);
|
|
506
|
+
result.key.participant = found?.jid || (0, WABinary_1.lidToJid)(result.key.participant);
|
|
507
|
+
}
|
|
487
508
|
}
|
|
488
509
|
break;
|
|
489
510
|
case 'account_sync':
|
|
@@ -504,7 +525,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
504
525
|
else if (child.tag === 'blocklist') {
|
|
505
526
|
const blocklists = (0, WABinary_1.getBinaryNodeChildren)(child, 'item');
|
|
506
527
|
for (const { attrs } of blocklists) {
|
|
507
|
-
const blocklist = [attrs.jid];
|
|
528
|
+
const blocklist = [resolveJid(attrs.jid)];
|
|
508
529
|
const type = (attrs.action === 'block') ? 'add' : 'remove';
|
|
509
530
|
ev.emit('blocklist.update', { blocklist, type });
|
|
510
531
|
}
|
|
@@ -635,14 +656,14 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
635
656
|
var _a, _b;
|
|
636
657
|
const { attrs, content } = node;
|
|
637
658
|
const isLid = attrs.from.includes('lid');
|
|
638
|
-
const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(attrs.participant || attrs.from, isLid ? (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.lid : (_b = authState.creds.me) === null || _b === void 0 ? void 0 : _b.id);
|
|
639
|
-
const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
|
|
659
|
+
const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(resolveJid(attrs.participant) || resolveJid(attrs.from), isLid ? (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.lid : (_b = authState.creds.me) === null || _b === void 0 ? void 0 : _b.id);
|
|
660
|
+
const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? resolveJid(attrs.from) : attrs.recipient;
|
|
640
661
|
const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
|
|
641
662
|
const key = {
|
|
642
663
|
remoteJid,
|
|
643
664
|
id: '',
|
|
644
665
|
fromMe,
|
|
645
|
-
participant: attrs.participant
|
|
666
|
+
participant: resolveJid(attrs.participant)
|
|
646
667
|
};
|
|
647
668
|
if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
|
|
648
669
|
logger.debug({ remoteJid }, 'ignoring receipt from jid');
|
|
@@ -670,7 +691,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
670
691
|
ev.emit('message-receipt.update', ids.map(id => ({
|
|
671
692
|
key: { ...key, id },
|
|
672
693
|
receipt: {
|
|
673
|
-
userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
|
|
694
|
+
userJid: (0, WABinary_1.jidNormalizedUser)(resolveJid(attrs.participant)),
|
|
674
695
|
[updateKey]: +attrs.t
|
|
675
696
|
}
|
|
676
697
|
})));
|
|
@@ -725,7 +746,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
725
746
|
}
|
|
726
747
|
};
|
|
727
748
|
const handleNotification = async (node) => {
|
|
728
|
-
const remoteJid = node.attrs.from;
|
|
749
|
+
const remoteJid = resolveJid(node.attrs.from);
|
|
729
750
|
if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
|
|
730
751
|
logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification');
|
|
731
752
|
await sendMessageAck(node);
|
|
@@ -737,15 +758,15 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
737
758
|
var _a;
|
|
738
759
|
const msg = await processNotification(node);
|
|
739
760
|
if (msg) {
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
761
|
+
const participant = msg.participant || resolveJid(node.attrs.participant);
|
|
762
|
+
const fromMe = (0, WABinary_1.areJidsSameUser)(participant || remoteJid, authState.creds.me.id);
|
|
763
|
+
const key = msg.key || {};
|
|
764
|
+
key.remoteJid = remoteJid;
|
|
765
|
+
key.fromMe = fromMe;
|
|
766
|
+
key.id = node.attrs.id;
|
|
767
|
+
key.participant = key.participant || participant;
|
|
768
|
+
msg.key = key;
|
|
769
|
+
msg.participant = participant;
|
|
749
770
|
msg.messageTimestamp = +node.attrs.t;
|
|
750
771
|
const fullMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
|
|
751
772
|
await upsertMessage(fullMsg, 'append');
|
|
@@ -916,10 +937,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
916
937
|
const { attrs } = node;
|
|
917
938
|
const [infoChild] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
918
939
|
const callId = infoChild.attrs['call-id'];
|
|
919
|
-
const from = infoChild.attrs.from || infoChild.attrs['call-creator'];
|
|
940
|
+
const from = resolveJid(infoChild.attrs.from || infoChild.attrs['call-creator']);
|
|
920
941
|
const status = (0, Utils_1.getCallStatusFromNode)(infoChild);
|
|
921
942
|
const call = {
|
|
922
|
-
chatId: attrs.from,
|
|
943
|
+
chatId: resolveJid(attrs.from),
|
|
923
944
|
from,
|
|
924
945
|
id: callId,
|
|
925
946
|
date: new Date(+attrs.t * 1000),
|
|
@@ -929,7 +950,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
929
950
|
if (status === 'offer') {
|
|
930
951
|
call.isVideo = !!(0, WABinary_1.getBinaryNodeChild)(infoChild, 'video');
|
|
931
952
|
call.isGroup = infoChild.attrs.type === 'group' || !!infoChild.attrs['group-jid'];
|
|
932
|
-
call.groupJid = infoChild.attrs['group-jid'];
|
|
953
|
+
call.groupJid = resolveJid(infoChild.attrs['group-jid']);
|
|
933
954
|
callOfferCache.set(call.id, call);
|
|
934
955
|
}
|
|
935
956
|
const existingCall = callOfferCache.get(call.id);
|
|
@@ -1055,7 +1076,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1055
1076
|
.catch(error => onUnexpectedError(error, 'handling bad ack'));
|
|
1056
1077
|
});
|
|
1057
1078
|
ev.on('call', ([call]) => {
|
|
1058
|
-
// missed call + group call notification message generation
|
|
1059
1079
|
if (call.status === 'timeout' || (call.status === 'offer' && call.isGroup)) {
|
|
1060
1080
|
const msg = {
|
|
1061
1081
|
key: {
|
|
@@ -1093,20 +1113,17 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1093
1113
|
} else if (connection === 'open') {
|
|
1094
1114
|
sendActiveReceipts = true;
|
|
1095
1115
|
}
|
|
1096
|
-
// Update sendActiveReceipts based on connection status
|
|
1097
1116
|
if (typeof update.isOnline !== 'undefined') {
|
|
1098
1117
|
sendActiveReceipts = update.isOnline;
|
|
1099
1118
|
logger.trace(`sendActiveReceipts set to "${sendActiveReceipts}"`);
|
|
1100
1119
|
}
|
|
1101
1120
|
});
|
|
1102
|
-
// Enhanced retry logic for stuck pending messages with anti-ban delays
|
|
1103
1121
|
ev.on('messages.update', (updates) => {
|
|
1104
1122
|
const config = (0, performance_config_1.getPerformanceConfig)();
|
|
1105
1123
|
updates.forEach(update => {
|
|
1106
1124
|
if (update.update.status === WAProto_1.proto.WebMessageInfo.Status.PENDING &&
|
|
1107
|
-
Date.now() - (update.update.timestamp || 0) > 30000) {
|
|
1125
|
+
Date.now() - (update.update.timestamp || 0) > 30000) {
|
|
1108
1126
|
logger.debug({ key: update.key }, 'retrying stuck pending message with anti-ban delay');
|
|
1109
|
-
// Apply anti-ban delay before retry
|
|
1110
1127
|
setTimeout(async () => {
|
|
1111
1128
|
try {
|
|
1112
1129
|
const msg = await getMessage(update.key);
|
package/lib/Utils/messages.js
CHANGED
|
@@ -1194,49 +1194,4 @@ const assertMediaContent = (content) => {
|
|
|
1194
1194
|
return mediaContent;
|
|
1195
1195
|
};
|
|
1196
1196
|
exports.assertMediaContent = assertMediaContent;
|
|
1197
|
-
const getNormalizedJid = (jid) => {
|
|
1198
|
-
if (!jid) return jid;
|
|
1199
|
-
return (0, WABinary_1.jidNormalizedUser)(jid);
|
|
1200
|
-
};
|
|
1201
|
-
exports.getNormalizedJid = getNormalizedJid;
|
|
1202
|
-
|
|
1203
|
-
const isLidFormat = (jid) => {
|
|
1204
|
-
return (0, WABinary_1.isLidUser)(jid);
|
|
1205
|
-
};
|
|
1206
|
-
exports.isLidFormat = isLidFormat;
|
|
1207
1197
|
|
|
1208
|
-
// Legacy compatibility functions - deprecated, use native APIs
|
|
1209
|
-
const toJid = (id) => {
|
|
1210
|
-
console.warn('toJid is deprecated. Use getNormalizedJid instead.');
|
|
1211
|
-
return getNormalizedJid(id);
|
|
1212
|
-
};
|
|
1213
|
-
exports.toJid = toJid;
|
|
1214
|
-
|
|
1215
|
-
const getSenderLid = (message) => {
|
|
1216
|
-
const sender = message?.key?.participant || message?.key?.remoteJid;
|
|
1217
|
-
if (!sender) return null;
|
|
1218
|
-
|
|
1219
|
-
const normalized = getNormalizedJid(sender);
|
|
1220
|
-
return {
|
|
1221
|
-
jid: sender,
|
|
1222
|
-
lid: normalized,
|
|
1223
|
-
isValid: true,
|
|
1224
|
-
user: (0, WABinary_1.jidDecode)(normalized)?.user || 'unknown'
|
|
1225
|
-
};
|
|
1226
|
-
};
|
|
1227
|
-
exports.getSenderLid = getSenderLid;
|
|
1228
|
-
|
|
1229
|
-
const validateJid = (jid) => {
|
|
1230
|
-
console.warn('validateJid is deprecated. Use native Baileys validation.');
|
|
1231
|
-
if (!jid || typeof jid !== 'string') {
|
|
1232
|
-
return { isValid: false, error: 'Invalid JID: must be a non-empty string' };
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
try {
|
|
1236
|
-
const decoded = (0, WABinary_1.jidDecode)(jid);
|
|
1237
|
-
return { isValid: !!decoded };
|
|
1238
|
-
} catch {
|
|
1239
|
-
return { isValid: false, error: 'Invalid JID format' };
|
|
1240
|
-
}
|
|
1241
|
-
};
|
|
1242
|
-
exports.validateJid = validateJid;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realvare/based",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.4",
|
|
4
4
|
"description": "whatsapp api by sam",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"gradient-string": "^2.0.2",
|
|
53
53
|
"jimp": "^1.6.0",
|
|
54
54
|
"libphonenumber-js": "^1.12.31",
|
|
55
|
-
"libsignal": "
|
|
55
|
+
"libsignal": "npm:@newfadel/libsignal-node",
|
|
56
56
|
"lodash": "^4.17.21",
|
|
57
57
|
"music-metadata": "^11.7.0",
|
|
58
58
|
"pino": "^10.1.0",
|