@realvare/based 2.7.1 → 2.7.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/lib/Socket/messages-recv.js +47 -21
- package/lib/Utils/decode-wa-message.js +9 -0
- package/package.json +16 -15
|
@@ -62,6 +62,16 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
62
62
|
logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
|
|
63
63
|
await sendNode(stanza);
|
|
64
64
|
};
|
|
65
|
+
|
|
66
|
+
// Add withAck wrapper for guaranteed acknowledgments
|
|
67
|
+
const withAck = (processFn) => async (node) => {
|
|
68
|
+
try {
|
|
69
|
+
await processFn(node);
|
|
70
|
+
} finally {
|
|
71
|
+
// Always send ack even on failure to allow potential retry
|
|
72
|
+
await sendMessageAck(node);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
65
75
|
const offerCall = async (toJid, isVideo = false) => {
|
|
66
76
|
const callId = (0, crypto_1.randomBytes)(16).toString('hex').toUpperCase().substring(0, 64);
|
|
67
77
|
const offerContent = [];
|
|
@@ -235,12 +245,22 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
235
245
|
}
|
|
236
246
|
}
|
|
237
247
|
};
|
|
238
|
-
const handleGroupNotification = (participant, child, msg) => {
|
|
248
|
+
const handleGroupNotification = async (participant, child, groupJid, msg) => {
|
|
239
249
|
var _a, _b, _c, _d;
|
|
240
|
-
const participantJid =
|
|
250
|
+
const participantJid = (((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(child, 'participant')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.jid) || participant);
|
|
241
251
|
switch (child === null || child === void 0 ? void 0 : child.tag) {
|
|
242
252
|
case 'create':
|
|
243
|
-
|
|
253
|
+
let metadata = (0, groups_1.extractGroupMetadata)(child);
|
|
254
|
+
const fullMetadata = await groupMetadata(groupJid);
|
|
255
|
+
if (metadata.owner && metadata.owner.endsWith('@lid')) {
|
|
256
|
+
const found = fullMetadata.participants.find(p => p.id === metadata.owner);
|
|
257
|
+
metadata.owner = found?.jid || (0, WABinary_1.lidToJid)(metadata.owner);
|
|
258
|
+
}
|
|
259
|
+
let resolvedAuthor = participant;
|
|
260
|
+
if (participant.endsWith('@lid')) {
|
|
261
|
+
const found = fullMetadata.participants.find(p => p.id === participant);
|
|
262
|
+
resolvedAuthor = found?.jid || (0, WABinary_1.lidToJid)(participant);
|
|
263
|
+
}
|
|
244
264
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CREATE;
|
|
245
265
|
msg.messageStubParameters = [metadata.subject];
|
|
246
266
|
msg.key = { participant: metadata.owner };
|
|
@@ -251,7 +271,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
251
271
|
}]);
|
|
252
272
|
ev.emit('groups.upsert', [{
|
|
253
273
|
...metadata,
|
|
254
|
-
author:
|
|
274
|
+
author: resolvedAuthor
|
|
255
275
|
}]);
|
|
256
276
|
break;
|
|
257
277
|
case 'ephemeral':
|
|
@@ -265,7 +285,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
265
285
|
break;
|
|
266
286
|
case 'modify':
|
|
267
287
|
const oldNumber = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
|
|
268
|
-
msg.messageStubParameters = oldNumber
|
|
288
|
+
msg.messageStubParameters = oldNumber || [];
|
|
269
289
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
|
|
270
290
|
break;
|
|
271
291
|
case 'promote':
|
|
@@ -283,7 +303,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
283
303
|
child.tag === 'remove') {
|
|
284
304
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
|
|
285
305
|
}
|
|
286
|
-
msg.messageStubParameters = participants
|
|
306
|
+
msg.messageStubParameters = participants;
|
|
287
307
|
break;
|
|
288
308
|
case 'subject':
|
|
289
309
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT;
|
|
@@ -331,10 +351,26 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
331
351
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
332
352
|
msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
|
|
333
353
|
break;
|
|
334
|
-
break;
|
|
335
354
|
default:
|
|
336
355
|
// console.log("BAILEYS-DEBUG:", JSON.stringify({ ...child, content: Buffer.isBuffer(child.content) ? child.content.toString() : child.content, participant }, null, 2))
|
|
337
356
|
}
|
|
357
|
+
// Resolve LIDs to real JIDs for all messageStubParameters
|
|
358
|
+
if (msg.messageStubParameters) {
|
|
359
|
+
const metadata = await groupMetadata(groupJid);
|
|
360
|
+
msg.messageStubParameters = await Promise.all(msg.messageStubParameters.map(async (param) => {
|
|
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')) {
|
|
370
|
+
const metadata = await groupMetadata(groupJid);
|
|
371
|
+
const found = metadata.participants.find(p => p.id === msg.key.participant);
|
|
372
|
+
msg.key.participant = found?.jid || (0, WABinary_1.lidToJid)(msg.key.participant);
|
|
373
|
+
}
|
|
338
374
|
};
|
|
339
375
|
const handleNewsletterNotification = (id, node) => {
|
|
340
376
|
const messages = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
@@ -407,7 +443,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
407
443
|
handleMexNewsletterNotification(node.attrs.from, child);
|
|
408
444
|
break;
|
|
409
445
|
case 'w:gp2':
|
|
410
|
-
handleGroupNotification(node.attrs.participant, child, result);
|
|
446
|
+
await handleGroupNotification(node.attrs.participant, child, from, result);
|
|
411
447
|
break;
|
|
412
448
|
case 'mediaretry':
|
|
413
449
|
const event = (0, Utils_1.decodeMediaRetryNode)(node);
|
|
@@ -659,7 +695,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
659
695
|
update: { status: WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK }
|
|
660
696
|
})));
|
|
661
697
|
}
|
|
662
|
-
|
|
663
698
|
if (attrs.type === 'retry') {
|
|
664
699
|
// correctly set who is asking for the retry
|
|
665
700
|
key.participant = key.participant || attrs.from;
|
|
@@ -722,23 +757,20 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
722
757
|
await sendMessageAck(node);
|
|
723
758
|
}
|
|
724
759
|
};
|
|
725
|
-
const handleMessage = async (node) => {
|
|
760
|
+
const handleMessage = withAck(async (node) => {
|
|
726
761
|
var _a, _b, _c;
|
|
727
762
|
if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
|
|
728
763
|
logger.debug({ key: node.attrs.key }, 'ignored message');
|
|
729
|
-
await sendMessageAck(node);
|
|
730
764
|
return;
|
|
731
765
|
}
|
|
732
766
|
const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
|
|
733
767
|
// TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
|
|
734
768
|
if (encNode && encNode.attrs.type === 'msmsg') {
|
|
735
769
|
logger.debug({ key: node.attrs.key }, 'ignored msmsg');
|
|
736
|
-
await sendMessageAck(node);
|
|
737
770
|
return;
|
|
738
771
|
}
|
|
739
772
|
let response;
|
|
740
773
|
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !encNode) {
|
|
741
|
-
await sendMessageAck(node);
|
|
742
774
|
const { key } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
|
|
743
775
|
response = await requestPlaceholderResend(key);
|
|
744
776
|
if (response === 'RESOLVED') {
|
|
@@ -824,7 +856,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
824
856
|
}
|
|
825
857
|
}
|
|
826
858
|
(0, Utils_1.cleanMessage)(msg, authState.creds.me.id);
|
|
827
|
-
await sendMessageAck(node);
|
|
828
859
|
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
|
829
860
|
})
|
|
830
861
|
]);
|
|
@@ -832,7 +863,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
832
863
|
catch (error) {
|
|
833
864
|
logger.error({ error, node }, 'error in handling message');
|
|
834
865
|
}
|
|
835
|
-
};
|
|
866
|
+
});
|
|
836
867
|
const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
|
|
837
868
|
var _a;
|
|
838
869
|
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
@@ -1051,11 +1082,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1051
1082
|
});
|
|
1052
1083
|
ev.on('connection.update', (update) => {
|
|
1053
1084
|
const { connection, lastDisconnect } = update;
|
|
1054
|
-
|
|
1055
1085
|
if (connection === 'close') {
|
|
1056
1086
|
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
1057
1087
|
const shouldReconnect = statusCode !== Types_1.DisconnectReason.loggedOut;
|
|
1058
|
-
|
|
1059
1088
|
if (shouldReconnect) {
|
|
1060
1089
|
logger.info('Connection closed, will handle reconnection automatically');
|
|
1061
1090
|
} else {
|
|
@@ -1064,14 +1093,12 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1064
1093
|
} else if (connection === 'open') {
|
|
1065
1094
|
sendActiveReceipts = true;
|
|
1066
1095
|
}
|
|
1067
|
-
|
|
1068
1096
|
// Update sendActiveReceipts based on connection status
|
|
1069
1097
|
if (typeof update.isOnline !== 'undefined') {
|
|
1070
1098
|
sendActiveReceipts = update.isOnline;
|
|
1071
1099
|
logger.trace(`sendActiveReceipts set to "${sendActiveReceipts}"`);
|
|
1072
1100
|
}
|
|
1073
1101
|
});
|
|
1074
|
-
|
|
1075
1102
|
// Enhanced retry logic for stuck pending messages with anti-ban delays
|
|
1076
1103
|
ev.on('messages.update', (updates) => {
|
|
1077
1104
|
const config = (0, performance_config_1.getPerformanceConfig)();
|
|
@@ -1079,7 +1106,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1079
1106
|
if (update.update.status === WAProto_1.proto.WebMessageInfo.Status.PENDING &&
|
|
1080
1107
|
Date.now() - (update.update.timestamp || 0) > 30000) { // 30 seconds
|
|
1081
1108
|
logger.debug({ key: update.key }, 'retrying stuck pending message with anti-ban delay');
|
|
1082
|
-
|
|
1083
1109
|
// Apply anti-ban delay before retry
|
|
1084
1110
|
setTimeout(async () => {
|
|
1085
1111
|
try {
|
|
@@ -1104,4 +1130,4 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
1104
1130
|
requestPlaceholderResend,
|
|
1105
1131
|
};
|
|
1106
1132
|
};
|
|
1107
|
-
exports.makeMessagesRecvSocket = makeMessagesRecvSocket;
|
|
1133
|
+
exports.makeMessagesRecvSocket = makeMessagesRecvSocket;
|
|
@@ -29,11 +29,20 @@ exports.NACK_REASONS = {
|
|
|
29
29
|
*/
|
|
30
30
|
function decodeMessageNode(stanza, meId, meLid) {
|
|
31
31
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
32
|
+
if (!stanza || !stanza.attrs) {
|
|
33
|
+
throw new boom_1.Boom('Invalid stanza or missing attributes', { statusCode: 400 });
|
|
34
|
+
}
|
|
32
35
|
let msgType;
|
|
33
36
|
let chatId;
|
|
34
37
|
let author;
|
|
35
38
|
const msgId = stanza.attrs.id;
|
|
39
|
+
if (!msgId) {
|
|
40
|
+
throw new boom_1.Boom('Missing message ID', { statusCode: 400 });
|
|
41
|
+
}
|
|
36
42
|
const from = stanza.attrs.from;
|
|
43
|
+
if (!from) {
|
|
44
|
+
throw new boom_1.Boom('Missing sender JID', { statusCode: 400 });
|
|
45
|
+
}
|
|
37
46
|
const senderPn = (_a = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _a === void 0 ? void 0 : _a.sender_pn;
|
|
38
47
|
const senderLid = (_b = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _b === void 0 ? void 0 : _b.sender_lid;
|
|
39
48
|
const participant = stanza.attrs.participant;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realvare/based",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.3",
|
|
4
4
|
"description": "whatsapp api by sam",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"whatsapp-web",
|
|
10
10
|
"whatsapp-bot",
|
|
11
11
|
"automation",
|
|
12
|
-
"multi-device"
|
|
12
|
+
"multi-device",
|
|
13
|
+
"based"
|
|
13
14
|
],
|
|
14
15
|
"homepage": "https://github.com/realvare/based.git",
|
|
15
16
|
"repository": {
|
|
@@ -44,20 +45,20 @@
|
|
|
44
45
|
"@cacheable/node-cache": "^1.4.0",
|
|
45
46
|
"@hapi/boom": "^10.0.1",
|
|
46
47
|
"async-mutex": "^0.5.0",
|
|
47
|
-
"axios": "^1.
|
|
48
|
-
"cache-manager": "^
|
|
48
|
+
"axios": "^1.13.2",
|
|
49
|
+
"cache-manager": "^7.2.5",
|
|
49
50
|
"chalk": "^4.1.2",
|
|
50
|
-
"cheerio": "^1.
|
|
51
|
+
"cheerio": "^1.1.2",
|
|
51
52
|
"gradient-string": "^2.0.2",
|
|
52
|
-
"jimp": "^
|
|
53
|
-
"libphonenumber-js": "^1.
|
|
54
|
-
"libsignal": "github:
|
|
53
|
+
"jimp": "^1.6.0",
|
|
54
|
+
"libphonenumber-js": "^1.12.31",
|
|
55
|
+
"libsignal": "github:whiskeysockets/libsignal-node",
|
|
55
56
|
"lodash": "^4.17.21",
|
|
56
|
-
"music-metadata": "^7.
|
|
57
|
-
"pino": "^
|
|
58
|
-
"protobufjs": "^7.
|
|
59
|
-
"uuid": "^
|
|
60
|
-
"ws": "^8.18.
|
|
57
|
+
"music-metadata": "^11.7.0",
|
|
58
|
+
"pino": "^10.1.0",
|
|
59
|
+
"protobufjs": "^7.5.4",
|
|
60
|
+
"uuid": "^13.0.0",
|
|
61
|
+
"ws": "^8.18.3"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",
|
|
@@ -69,7 +70,7 @@
|
|
|
69
70
|
"conventional-changelog-cli": "^2.2.2",
|
|
70
71
|
"eslint": "^8.57.0",
|
|
71
72
|
"jest": "^29.7.0",
|
|
72
|
-
"jimp": "^
|
|
73
|
+
"jimp": "^1.6.0",
|
|
73
74
|
"json": "^11.0.0",
|
|
74
75
|
"link-preview-js": "^3.0.0",
|
|
75
76
|
"open": "^10.1.0",
|
|
@@ -79,7 +80,7 @@
|
|
|
79
80
|
"ts-jest": "^29.1.2",
|
|
80
81
|
"ts-node": "^10.9.2",
|
|
81
82
|
"typedoc": "^0.25.12",
|
|
82
|
-
"typescript": "^5.
|
|
83
|
+
"typescript": "^5.9.3"
|
|
83
84
|
},
|
|
84
85
|
"peerDependencies": {
|
|
85
86
|
"audio-decode": "^2.1.3",
|