naya-flore 4.7.2 → 4.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/README.md +0 -104
- package/WAProto/WAProto.proto +89 -1195
- package/WAProto/index.d.ts +1256 -13195
- package/WAProto/index.js +11405 -32544
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +0 -231
- package/lib/Defaults/index.js +102 -92
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Signal/libsignal.js +9 -18
- package/lib/Socket/Client/abstract-socket-client.d.ts +2 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +1 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -2
- package/lib/Socket/business.d.ts +43 -42
- package/lib/Socket/chats.d.ts +8 -9
- package/lib/Socket/chats.js +34 -41
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +4 -2
- package/lib/Socket/index.d.ts +52 -51
- package/lib/Socket/messages-recv.d.ts +42 -41
- package/lib/Socket/messages-recv.js +127 -190
- package/lib/Socket/messages-send.d.ts +9 -16
- package/lib/Socket/messages-send.js +316 -467
- package/lib/Socket/newsletter.d.ts +28 -26
- package/lib/Socket/newsletter.js +3 -3
- package/lib/Socket/registration.d.ts +52 -49
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +0 -1
- package/lib/Socket/socket.js +23 -49
- package/lib/Socket/usync.d.ts +10 -11
- package/lib/Store/index.d.ts +2 -2
- package/lib/Store/index.js +2 -2
- package/lib/Store/make-cache-manager-store.d.ts +0 -1
- package/lib/Store/make-in-memory-store.js +1 -5
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -12
- package/lib/Types/Events.d.ts +2 -17
- package/lib/Types/GroupMetadata.d.ts +2 -3
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +10 -170
- package/lib/Types/Newsletter.js +3 -3
- package/lib/Types/Socket.d.ts +4 -7
- package/lib/Types/index.d.ts +0 -9
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +3 -3
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +12 -11
- package/lib/Utils/chat-utils.js +26 -42
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +23 -35
- package/lib/Utils/decode-wa-message.d.ts +0 -17
- package/lib/Utils/decode-wa-message.js +15 -43
- package/lib/Utils/generics.d.ts +17 -13
- package/lib/Utils/generics.js +15 -25
- package/lib/Utils/history.d.ts +2 -6
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/logger.d.ts +3 -1
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +28 -25
- package/lib/Utils/messages-media.js +47 -38
- package/lib/Utils/messages.js +41 -454
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/process-message.js +2 -2
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +19 -11
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +3 -11
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +1 -1
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.js +7 -17
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +17 -33
- package/lib/WABinary/generic-utils.d.ts +3 -2
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/USyncQuery.d.ts +2 -0
- package/lib/WAUSync/USyncQuery.js +10 -0
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/WAUSync/USyncUser.js +4 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +19 -32
- package/lib/Socket/Client/types.d.ts +0 -17
- package/lib/Socket/Client/types.js +0 -13
@@ -19,41 +19,38 @@ const messages_send_1 = require("./messages-send");
|
|
19
19
|
const makeMessagesRecvSocket = (config) => {
|
20
20
|
const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
|
21
21
|
const sock = (0, messages_send_1.makeMessagesSocket)(config);
|
22
|
-
const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, getUSyncDevices,
|
22
|
+
const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, getUSyncDevices, createParticipantNodes, sendPeerDataOperationMessage } = sock;
|
23
23
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
24
24
|
const retryMutex = (0, make_mutex_1.makeMutex)();
|
25
25
|
const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
|
26
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
27
|
-
useClones: false
|
28
|
-
});
|
29
|
-
const callOfferCache = config.callOfferCache || new node_cache_1.default({
|
30
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins
|
26
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
31
27
|
useClones: false
|
32
28
|
});
|
33
29
|
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
34
30
|
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
35
31
|
useClones: false
|
36
32
|
});
|
33
|
+
const callOfferCache = config.callOfferCache || new node_cache_1.default({
|
34
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER,
|
35
|
+
useClones: false
|
36
|
+
});
|
37
37
|
let sendActiveReceipts = false;
|
38
|
-
const sendMessageAck = async ({ tag, attrs, content }
|
38
|
+
const sendMessageAck = async ({ tag, attrs, content }) => {
|
39
39
|
const stanza = {
|
40
40
|
tag: 'ack',
|
41
41
|
attrs: {
|
42
42
|
id: attrs.id,
|
43
43
|
to: attrs.from,
|
44
|
-
class: tag
|
44
|
+
class: tag,
|
45
45
|
}
|
46
46
|
};
|
47
|
-
if (!!errorCode) {
|
48
|
-
stanza.attrs.error = errorCode.toString();
|
49
|
-
}
|
50
47
|
if (!!attrs.participant) {
|
51
48
|
stanza.attrs.participant = attrs.participant;
|
52
49
|
}
|
53
50
|
if (!!attrs.recipient) {
|
54
51
|
stanza.attrs.recipient = attrs.recipient;
|
55
52
|
}
|
56
|
-
if (!!attrs.type && (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')
|
53
|
+
if (!!attrs.type && (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable'))) {
|
57
54
|
stanza.attrs.type = attrs.type;
|
58
55
|
}
|
59
56
|
if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
|
@@ -135,23 +132,16 @@ const makeMessagesRecvSocket = (config) => {
|
|
135
132
|
};
|
136
133
|
const sendRetryRequest = async (node, forceIncludeKeys = false) => {
|
137
134
|
const { fullMessage } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '');
|
138
|
-
const
|
139
|
-
|
140
|
-
const key = `${msgId}:${msgKey === null || msgKey === void 0 ? void 0 : msgKey.participant}`;
|
141
|
-
let retryCount = msgRetryCache.get(key) || 0;
|
135
|
+
const msgId = node.attrs.id;
|
136
|
+
let retryCount = msgRetryCache.get(msgId) || 0;
|
142
137
|
if (retryCount >= maxMsgRetryCount) {
|
143
138
|
logger.debug({ retryCount, msgId }, 'reached retry limit, clearing');
|
144
|
-
msgRetryCache.del(
|
139
|
+
msgRetryCache.del(msgId);
|
145
140
|
return;
|
146
141
|
}
|
147
142
|
retryCount += 1;
|
148
|
-
msgRetryCache.set(
|
143
|
+
msgRetryCache.set(msgId, retryCount);
|
149
144
|
const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds;
|
150
|
-
if (retryCount === 1) {
|
151
|
-
//request a resend via phone
|
152
|
-
const msgId = await requestPlaceholderResend(msgKey);
|
153
|
-
logger.debug(`sendRetryRequest: requested placeholder resend for message ${msgId}`);
|
154
|
-
}
|
155
145
|
const deviceIdentity = (0, Utils_1.encodeSignedDeviceIdentity)(account, true);
|
156
146
|
await authState.keys.transaction(async () => {
|
157
147
|
const receipt = {
|
@@ -230,8 +220,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
230
220
|
}
|
231
221
|
};
|
232
222
|
const handleGroupNotification = (participant, child, msg) => {
|
233
|
-
var _a, _b, _c, _d;
|
234
|
-
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;
|
235
223
|
switch (child === null || child === void 0 ? void 0 : child.tag) {
|
236
224
|
case 'create':
|
237
225
|
const metadata = (0, groups_1.extractGroupMetadata)(child);
|
@@ -257,11 +245,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
257
245
|
}
|
258
246
|
};
|
259
247
|
break;
|
260
|
-
case 'modify':
|
261
|
-
const oldNumber = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
|
262
|
-
msg.messageStubParameters = oldNumber || [];
|
263
|
-
msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
|
264
|
-
break;
|
265
248
|
case 'promote':
|
266
249
|
case 'demote':
|
267
250
|
case 'remove':
|
@@ -283,11 +266,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
283
266
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT;
|
284
267
|
msg.messageStubParameters = [child.attrs.subject];
|
285
268
|
break;
|
286
|
-
case 'description':
|
287
|
-
const description = (_d = (_c = (0, WABinary_1.getBinaryNodeChild)(child, 'body')) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.toString();
|
288
|
-
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
|
289
|
-
msg.messageStubParameters = description ? [description] : undefined;
|
290
|
-
break;
|
291
269
|
case 'announcement':
|
292
270
|
case 'not_announcement':
|
293
271
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
|
@@ -316,15 +294,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
316
294
|
msg.messageStubParameters = [approvalMode.attrs.state];
|
317
295
|
}
|
318
296
|
break;
|
319
|
-
case 'created_membership_requests':
|
320
|
-
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
321
|
-
msg.messageStubParameters = [participantJid, 'created', child.attrs.request_method];
|
322
|
-
break;
|
323
|
-
case 'revoked_membership_requests':
|
324
|
-
const isDenied = (0, WABinary_1.areJidsSameUser)(participantJid, participant);
|
325
|
-
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
326
|
-
msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
|
327
|
-
break;
|
328
297
|
}
|
329
298
|
};
|
330
299
|
const processNotification = async (node) => {
|
@@ -357,6 +326,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
357
326
|
case 'encrypt':
|
358
327
|
await handleEncryptNotification(node);
|
359
328
|
break;
|
329
|
+
case 'newsletter':
|
330
|
+
// TO DO
|
331
|
+
break;
|
360
332
|
case 'devices':
|
361
333
|
const devices = (0, WABinary_1.getBinaryNodeChildren)(child, 'device');
|
362
334
|
if ((0, WABinary_1.areJidsSameUser)(child.attrs.jid, authState.creds.me.id)) {
|
@@ -375,7 +347,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
375
347
|
const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
|
376
348
|
const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
|
377
349
|
ev.emit('contacts.update', [{
|
378
|
-
id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.
|
350
|
+
id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.jid) || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
|
379
351
|
imgUrl: setPicture ? 'changed' : 'removed'
|
380
352
|
}]);
|
381
353
|
if ((0, WABinary_1.isJidGroup)(from)) {
|
@@ -420,7 +392,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
420
392
|
const ref = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_ref'));
|
421
393
|
const primaryIdentityPublicKey = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'primary_identity_pub'));
|
422
394
|
const primaryEphemeralPublicKeyWrapped = toRequiredBuffer((0, WABinary_1.getBinaryNodeChildBuffer)(linkCodeCompanionReg, 'link_code_pairing_wrapped_primary_ephemeral_pub'));
|
423
|
-
const codePairingPublicKey =
|
395
|
+
const codePairingPublicKey = decipherLinkPublicKey(primaryEphemeralPublicKeyWrapped);
|
424
396
|
const companionSharedKey = Utils_1.Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
|
425
397
|
const random = (0, crypto_1.randomBytes)(32);
|
426
398
|
const linkCodeSalt = (0, crypto_1.randomBytes)(32);
|
@@ -477,10 +449,10 @@ const makeMessagesRecvSocket = (config) => {
|
|
477
449
|
return result;
|
478
450
|
}
|
479
451
|
};
|
480
|
-
|
452
|
+
function decipherLinkPublicKey(data) {
|
481
453
|
const buffer = toRequiredBuffer(data);
|
482
454
|
const salt = buffer.slice(0, 32);
|
483
|
-
const secretKey =
|
455
|
+
const secretKey = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
|
484
456
|
const iv = buffer.slice(32, 48);
|
485
457
|
const payload = buffer.slice(48, 80);
|
486
458
|
return (0, Utils_1.aesDecryptCTR)(payload, secretKey, iv);
|
@@ -515,7 +487,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
515
487
|
await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
|
516
488
|
}
|
517
489
|
logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
|
518
|
-
for (
|
490
|
+
for (let i = 0; i < msgs.length; i++) {
|
491
|
+
const msg = msgs[i];
|
519
492
|
if (msg) {
|
520
493
|
updateSendMessageAgainCount(ids[i], participant);
|
521
494
|
const msgRelayOpts = { messageId: ids[i] };
|
@@ -558,63 +531,59 @@ const makeMessagesRecvSocket = (config) => {
|
|
558
531
|
const items = (0, WABinary_1.getBinaryNodeChildren)(content[0], 'item');
|
559
532
|
ids.push(...items.map(i => i.attrs.id));
|
560
533
|
}
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
if (
|
572
|
-
|
573
|
-
|
574
|
-
ev.emit('message-receipt.update', ids.map(id => ({
|
575
|
-
key: { ...key, id },
|
576
|
-
receipt: {
|
577
|
-
userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
|
578
|
-
[updateKey]: +attrs.t
|
579
|
-
}
|
580
|
-
})));
|
581
|
-
}
|
582
|
-
}
|
583
|
-
else {
|
584
|
-
ev.emit('messages.update', ids.map(id => ({
|
534
|
+
await Promise.all([
|
535
|
+
processingMutex.mutex(async () => {
|
536
|
+
const status = (0, Utils_1.getStatusFromReceiptType)(attrs.type);
|
537
|
+
if (typeof status !== 'undefined' &&
|
538
|
+
(
|
539
|
+
// basically, we only want to know when a message from us has been delivered to/read by the other person
|
540
|
+
// or another device of ours has read some messages
|
541
|
+
status > WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ||
|
542
|
+
!isNodeFromMe)) {
|
543
|
+
if ((0, WABinary_1.isJidGroup)(remoteJid)) {
|
544
|
+
if (attrs.participant) {
|
545
|
+
const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
|
546
|
+
ev.emit('message-receipt.update', ids.map(id => ({
|
585
547
|
key: { ...key, id },
|
586
|
-
|
548
|
+
receipt: {
|
549
|
+
userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
|
550
|
+
[updateKey]: +attrs.t
|
551
|
+
}
|
587
552
|
})));
|
588
553
|
}
|
589
554
|
}
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
555
|
+
else {
|
556
|
+
ev.emit('messages.update', ids.map(id => ({
|
557
|
+
key: { ...key, id },
|
558
|
+
update: { status }
|
559
|
+
})));
|
560
|
+
}
|
561
|
+
}
|
562
|
+
if (attrs.type === 'retry') {
|
563
|
+
// correctly set who is asking for the retry
|
564
|
+
key.participant = key.participant || attrs.from;
|
565
|
+
const retryNode = (0, WABinary_1.getBinaryNodeChild)(node, 'retry');
|
566
|
+
if (willSendMessageAgain(ids[0], key.participant)) {
|
567
|
+
if (key.fromMe) {
|
568
|
+
try {
|
569
|
+
logger.debug({ attrs, key }, 'recv retry request');
|
570
|
+
await sendMessagesAgain(key, ids, retryNode);
|
603
571
|
}
|
604
|
-
|
605
|
-
logger.
|
572
|
+
catch (error) {
|
573
|
+
logger.error({ key, ids, trace: error.stack }, 'error in sending message again');
|
606
574
|
}
|
607
575
|
}
|
608
576
|
else {
|
609
|
-
logger.info({ attrs, key }, '
|
577
|
+
logger.info({ attrs, key }, 'recv retry for not fromMe message');
|
610
578
|
}
|
611
579
|
}
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
580
|
+
else {
|
581
|
+
logger.info({ attrs, key }, 'will not send message again, as sent too many times');
|
582
|
+
}
|
583
|
+
}
|
584
|
+
}),
|
585
|
+
sendMessageAck(node)
|
586
|
+
]);
|
618
587
|
};
|
619
588
|
const handleNotification = async (node) => {
|
620
589
|
const remoteJid = node.attrs.from;
|
@@ -623,31 +592,27 @@ const makeMessagesRecvSocket = (config) => {
|
|
623
592
|
await sendMessageAck(node);
|
624
593
|
return;
|
625
594
|
}
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
}
|
648
|
-
finally {
|
649
|
-
await sendMessageAck(node);
|
650
|
-
}
|
595
|
+
await Promise.all([
|
596
|
+
processingMutex.mutex(async () => {
|
597
|
+
var _a;
|
598
|
+
const msg = await processNotification(node);
|
599
|
+
if (msg) {
|
600
|
+
const fromMe = (0, WABinary_1.areJidsSameUser)(node.attrs.participant || remoteJid, authState.creds.me.id);
|
601
|
+
msg.key = {
|
602
|
+
remoteJid,
|
603
|
+
fromMe,
|
604
|
+
participant: node.attrs.participant,
|
605
|
+
id: node.attrs.id,
|
606
|
+
...(msg.key || {})
|
607
|
+
};
|
608
|
+
(_a = msg.participant) !== null && _a !== void 0 ? _a : (msg.participant = node.attrs.participant);
|
609
|
+
msg.messageTimestamp = +node.attrs.t;
|
610
|
+
const fullMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
|
611
|
+
await upsertMessage(fullMsg, 'append');
|
612
|
+
}
|
613
|
+
}),
|
614
|
+
sendMessageAck(node)
|
615
|
+
]);
|
651
616
|
};
|
652
617
|
const handleMessage = async (node) => {
|
653
618
|
var _a, _b, _c;
|
@@ -656,8 +621,15 @@ const makeMessagesRecvSocket = (config) => {
|
|
656
621
|
await sendMessageAck(node);
|
657
622
|
return;
|
658
623
|
}
|
624
|
+
const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
|
625
|
+
// TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
|
626
|
+
if (encNode && encNode.attrs.type === 'msmsg') {
|
627
|
+
logger.debug({ key: node.attrs.key }, 'ignored msmsg');
|
628
|
+
await sendMessageAck(node);
|
629
|
+
return;
|
630
|
+
}
|
659
631
|
let response;
|
660
|
-
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !
|
632
|
+
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !encNode) {
|
661
633
|
await sendMessageAck(node);
|
662
634
|
const { key } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
|
663
635
|
response = await requestPlaceholderResend(key);
|
@@ -681,7 +653,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
681
653
|
try {
|
682
654
|
await Promise.all([
|
683
655
|
processingMutex.mutex(async () => {
|
684
|
-
var _a;
|
656
|
+
var _a, _b, _c, _d, _e, _f;
|
685
657
|
await decrypt();
|
686
658
|
// message failed to decrypt
|
687
659
|
if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
@@ -729,7 +701,15 @@ const makeMessagesRecvSocket = (config) => {
|
|
729
701
|
await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
|
730
702
|
}
|
731
703
|
}
|
732
|
-
(0,
|
704
|
+
if (((_b = node === null || node === void 0 ? void 0 : node.attrs) === null || _b === void 0 ? void 0 : _b.addressing_mode) === 'lid' && ((0, WABinary_1.jidNormalizedUser)((_c = node === null || node === void 0 ? void 0 : node.attrs) === null || _c === void 0 ? void 0 : _c.participant) === (0, WABinary_1.jidNormalizedUser)(authState.creds.me.lid))) {
|
705
|
+
// @ts-ignore
|
706
|
+
msg.key.jid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
707
|
+
}
|
708
|
+
if (((_d = node === null || node === void 0 ? void 0 : node.attrs) === null || _d === void 0 ? void 0 : _d.addressing_mode) === 'lid' && ((_e = node === null || node === void 0 ? void 0 : node.attrs) === null || _e === void 0 ? void 0 : _e.participant_pn)) {
|
709
|
+
// @ts-ignore
|
710
|
+
msg.key.jid = (0, WABinary_1.jidNormalizedUser)((_f = node === null || node === void 0 ? void 0 : node.attrs) === null || _f === void 0 ? void 0 : _f.participant_pn);
|
711
|
+
}
|
712
|
+
(0, Utils_1.cleanMessage)(msg, authState.creds.me.id);
|
733
713
|
await sendMessageAck(node);
|
734
714
|
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
735
715
|
})
|
@@ -762,7 +742,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
762
742
|
throw new boom_1.Boom('Not authenticated');
|
763
743
|
}
|
764
744
|
if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
765
|
-
logger.debug('already requested resend'
|
745
|
+
logger.debug({ messageKey }, 'already requested resend');
|
766
746
|
return;
|
767
747
|
}
|
768
748
|
else {
|
@@ -770,7 +750,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
770
750
|
}
|
771
751
|
await (0, Utils_1.delay)(5000);
|
772
752
|
if (!placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
773
|
-
logger.debug('message received while resend requested'
|
753
|
+
logger.debug({ messageKey }, 'message received while resend requested');
|
774
754
|
return 'RESOLVED';
|
775
755
|
}
|
776
756
|
const pdoMessage = {
|
@@ -781,7 +761,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
781
761
|
};
|
782
762
|
setTimeout(() => {
|
783
763
|
if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
784
|
-
logger.debug('PDO message without response after 15 seconds. Phone possibly offline'
|
764
|
+
logger.debug({ messageKey }, 'PDO message without response after 15 seconds. Phone possibly offline');
|
785
765
|
placeholderResendCache.del(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id);
|
786
766
|
}
|
787
767
|
}, 15000);
|
@@ -814,7 +794,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
814
794
|
call.isGroup = existingCall.isGroup;
|
815
795
|
}
|
816
796
|
// delete data once call has ended
|
817
|
-
if (status === 'reject' || status === 'accept' || status === 'timeout'
|
797
|
+
if (status === 'reject' || status === 'accept' || status === 'timeout') {
|
818
798
|
callOfferCache.del(call.id);
|
819
799
|
}
|
820
800
|
ev.emit('call', [call]);
|
@@ -822,19 +802,19 @@ const makeMessagesRecvSocket = (config) => {
|
|
822
802
|
};
|
823
803
|
const handleBadAck = async ({ attrs }) => {
|
824
804
|
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
|
825
|
-
//
|
826
|
-
//
|
827
|
-
//
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
805
|
+
// current hypothesis is that if pash is sent in the ack
|
806
|
+
// it means -- the message hasn't reached all devices yet
|
807
|
+
// we'll retry sending the message here
|
808
|
+
if (attrs.phash) {
|
809
|
+
logger.info({ attrs }, 'received phash in ack, resending message...');
|
810
|
+
const msg = await getMessage(key);
|
811
|
+
if (msg) {
|
812
|
+
await relayMessage(key.remoteJid, msg, { messageId: key.id, useUserDevicesCache: false });
|
813
|
+
}
|
814
|
+
else {
|
815
|
+
logger.warn({ attrs }, 'could not send message again, as it was not found');
|
816
|
+
}
|
817
|
+
}
|
838
818
|
// error in acknowledgement,
|
839
819
|
// device could not display the message
|
840
820
|
if (attrs.error) {
|
@@ -859,63 +839,22 @@ const makeMessagesRecvSocket = (config) => {
|
|
859
839
|
await execTask();
|
860
840
|
ev.flush();
|
861
841
|
function execTask() {
|
862
|
-
return exec(node
|
842
|
+
return exec(node)
|
863
843
|
.catch(err => onUnexpectedError(err, identifier));
|
864
844
|
}
|
865
845
|
};
|
866
|
-
const makeOfflineNodeProcessor = () => {
|
867
|
-
const nodeProcessorMap = new Map([
|
868
|
-
['message', handleMessage],
|
869
|
-
['call', handleCall],
|
870
|
-
['receipt', handleReceipt],
|
871
|
-
['notification', handleNotification]
|
872
|
-
]);
|
873
|
-
const nodes = [];
|
874
|
-
let isProcessing = false;
|
875
|
-
const enqueue = (type, node) => {
|
876
|
-
nodes.push({ type, node });
|
877
|
-
if (isProcessing) {
|
878
|
-
return;
|
879
|
-
}
|
880
|
-
isProcessing = true;
|
881
|
-
const promise = async () => {
|
882
|
-
while (nodes.length && ws.isOpen) {
|
883
|
-
const { type, node } = nodes.shift();
|
884
|
-
const nodeProcessor = nodeProcessorMap.get(type);
|
885
|
-
if (!nodeProcessor) {
|
886
|
-
onUnexpectedError(new Error(`unknown offline node type: ${type}`), 'processing offline node');
|
887
|
-
continue;
|
888
|
-
}
|
889
|
-
await nodeProcessor(node);
|
890
|
-
}
|
891
|
-
isProcessing = false;
|
892
|
-
};
|
893
|
-
promise().catch(error => onUnexpectedError(error, 'processing offline nodes'));
|
894
|
-
};
|
895
|
-
return { enqueue };
|
896
|
-
};
|
897
|
-
const offlineNodeProcessor = makeOfflineNodeProcessor();
|
898
|
-
const processNode = (type, node, identifier, exec) => {
|
899
|
-
const isOffline = !!node.attrs.offline;
|
900
|
-
if (isOffline) {
|
901
|
-
offlineNodeProcessor.enqueue(type, node);
|
902
|
-
}
|
903
|
-
else {
|
904
|
-
processNodeWithBuffer(node, identifier, exec);
|
905
|
-
}
|
906
|
-
};
|
907
846
|
// recv a message
|
908
847
|
ws.on('CB:message', (node) => {
|
909
|
-
|
848
|
+
processNodeWithBuffer(node, 'processing message', handleMessage);
|
910
849
|
});
|
911
850
|
ws.on('CB:call', async (node) => {
|
912
|
-
|
851
|
+
processNodeWithBuffer(node, 'handling call', handleCall);
|
913
852
|
});
|
914
853
|
ws.on('CB:receipt', node => {
|
915
|
-
|
854
|
+
processNodeWithBuffer(node, 'handling receipt', handleReceipt);
|
916
855
|
});
|
917
856
|
ws.on('CB:notification', async (node) => {
|
918
|
-
|
857
|
+
processNodeWithBuffer(node, 'handling notification', handleNotification);
|
919
858
|
});
|
920
859
|
ws.on('CB:ack,class:message', (node) => {
|
921
860
|
handleBadAck(node)
|
@@ -958,9 +897,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
958
897
|
sendMessageAck,
|
959
898
|
sendRetryRequest,
|
960
899
|
offerCall,
|
961
|
-
rejectCall
|
962
|
-
fetchMessageHistory,
|
963
|
-
requestPlaceholderResend,
|
900
|
+
rejectCall
|
964
901
|
};
|
965
902
|
};
|
966
903
|
exports.makeMessagesRecvSocket = makeMessagesRecvSocket;
|
@@ -1,9 +1,8 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import { Boom } from '@hapi/boom';
|
3
3
|
import { proto } from '../../WAProto';
|
4
|
-
import { AnyMessageContent,
|
4
|
+
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
|
5
5
|
import { BinaryNode, JidWithDevice } from '../WABinary';
|
6
|
-
import { USyncQuery } from '../WAUSync';
|
7
6
|
export declare const makeMessagesSocket: (config: SocketConfig) => {
|
8
7
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
9
8
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
@@ -14,22 +13,16 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
14
13
|
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
15
14
|
refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
|
16
15
|
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
|
17
|
-
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
18
16
|
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
|
19
17
|
nodes: BinaryNode[];
|
20
18
|
shouldIncludeDeviceIdentity: boolean;
|
21
19
|
}>;
|
22
|
-
profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | null | undefined>;
|
23
20
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
24
21
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
25
22
|
[_: string]: string;
|
26
23
|
}>;
|
27
24
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
28
|
-
sendStatusMentions: (content: AnyMessageContent, jids?: string[]) => Promise<proto.WebMessageInfo>;
|
29
|
-
sendAlbumMessage: (jid: string, medias: Media[], options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>;
|
30
25
|
sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
31
|
-
newsletterQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<BinaryNode>;
|
32
|
-
newsletterWMexQuery: (jid: string | undefined, queryId: QueryIds, content?: object | undefined) => Promise<BinaryNode>;
|
33
26
|
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
34
27
|
duration: string;
|
35
28
|
}>;
|
@@ -43,7 +36,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
43
36
|
newsletterUnmute: (jid: string) => Promise<void>;
|
44
37
|
newsletterMute: (jid: string) => Promise<void>;
|
45
38
|
newsletterAction: (jid: string, type: "mute" | "follow" | "unfollow" | "unmute") => Promise<void>;
|
46
|
-
newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
|
39
|
+
newsletterCreate: (name: string, description: string, reaction_codes: string) => Promise<import("../Types").NewsletterMetadata>;
|
47
40
|
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
48
41
|
newsletterAdminCount: (jid: string) => Promise<number>;
|
49
42
|
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
@@ -52,7 +45,6 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
52
45
|
newsletterReactMessage: (jid: string, serverId: string, code?: string | undefined) => Promise<void>;
|
53
46
|
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
54
47
|
newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
55
|
-
groupQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<BinaryNode>;
|
56
48
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
57
49
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
58
50
|
groupLeave: (id: string) => Promise<void>;
|
@@ -82,22 +74,24 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
82
74
|
groupFetchAllParticipating: () => Promise<{
|
83
75
|
[_: string]: import("../Types").GroupMetadata;
|
84
76
|
}>;
|
85
|
-
interactiveQuery: (userNodes: BinaryNode[], queryNode: BinaryNode) => Promise<BinaryNode[]>;
|
86
77
|
processingMutex: {
|
87
78
|
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
88
79
|
};
|
89
80
|
upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
90
81
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
91
|
-
fetchUserLid: (jid: string) => Promise<string | undefined>;
|
92
82
|
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
|
93
83
|
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
|
84
|
+
profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
|
94
85
|
onWhatsApp: (...jids: string[]) => Promise<{
|
95
86
|
jid: string;
|
96
87
|
exists: unknown;
|
88
|
+
lid: unknown;
|
97
89
|
}[] | undefined>;
|
98
90
|
fetchBlocklist: () => Promise<string[]>;
|
99
|
-
fetchStatus: (
|
100
|
-
|
91
|
+
fetchStatus: (jid: string) => Promise<{
|
92
|
+
status: string | undefined;
|
93
|
+
setAt: Date;
|
94
|
+
} | undefined>;
|
101
95
|
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
102
96
|
removeProfilePicture: (jid: string) => Promise<void>;
|
103
97
|
updateProfileStatus: (status: string) => Promise<void>;
|
@@ -122,7 +116,6 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
122
116
|
id: string;
|
123
117
|
fromMe?: boolean | undefined;
|
124
118
|
}[], star: boolean) => Promise<void>;
|
125
|
-
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
126
119
|
type: "md";
|
127
120
|
ws: any;
|
128
121
|
ev: import("../Types").BaileysEventEmitter & {
|
@@ -149,7 +142,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
149
142
|
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
150
143
|
uploadPreKeys: (count?: number) => Promise<void>;
|
151
144
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
152
|
-
requestPairingCode: (phoneNumber: string
|
145
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
153
146
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
154
147
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
155
148
|
};
|