lordceaser-baileys 1.0.20 → 1.0.21
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/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +235 -3
- package/lib/Defaults/index.js +22 -6
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/libsignal.js +9 -18
- package/lib/Socket/Client/{types.d.ts → 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 +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -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 +40 -38
- package/lib/Socket/chats.d.ts +23 -25
- package/lib/Socket/chats.js +78 -79
- package/lib/Socket/groups.d.ts +29 -30
- package/lib/Socket/groups.js +3 -4
- package/lib/Socket/index.d.ts +48 -44
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +37 -37
- package/lib/Socket/messages-recv.js +44 -98
- package/lib/Socket/messages-send.d.ts +31 -33
- package/lib/Socket/messages-send.js +70 -82
- package/lib/Socket/registration.d.ts +242 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +10 -9
- package/lib/Socket/socket.js +23 -28
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +422 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +7 -0
- package/lib/Types/Chat.d.ts +7 -12
- package/lib/Types/Contact.d.ts +1 -1
- package/lib/Types/GroupMetadata.d.ts +0 -2
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +10 -9
- package/lib/Types/Message.js +3 -1
- package/lib/Types/Socket.d.ts +11 -16
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -7
- package/lib/Utils/business.js +5 -13
- package/lib/Utils/chat-utils.d.ts +14 -13
- package/lib/Utils/chat-utils.js +31 -36
- package/lib/Utils/crypto.d.ts +15 -14
- package/lib/Utils/crypto.js +30 -70
- package/lib/Utils/decode-wa-message.d.ts +2 -18
- package/lib/Utils/decode-wa-message.js +19 -23
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +7 -7
- package/lib/Utils/generics.d.ts +14 -15
- package/lib/Utils/generics.js +29 -33
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/history.js +1 -1
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +3 -10
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +24 -20
- package/lib/Utils/messages-media.js +76 -79
- package/lib/Utils/messages.d.ts +9 -7
- package/lib/Utils/messages.js +30 -29
- package/lib/Utils/noise-handler.d.ts +11 -9
- package/lib/Utils/noise-handler.js +22 -17
- package/lib/Utils/process-message.d.ts +5 -4
- package/lib/Utils/process-message.js +40 -68
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +19 -11
- package/lib/Utils/use-multi-file-auth-state.js +14 -46
- package/lib/Utils/validate-connection.d.ts +3 -2
- package/lib/Utils/validate-connection.js +46 -16
- package/lib/WABinary/constants.js +5 -5
- package/lib/WABinary/decode.d.ts +3 -2
- package/lib/WABinary/decode.js +9 -20
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +18 -38
- package/lib/WABinary/generic-utils.d.ts +2 -1
- package/lib/WABinary/generic-utils.js +3 -3
- package/lib/WABinary/jid-utils.d.ts +3 -7
- package/lib/WABinary/jid-utils.js +2 -9
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/constants.d.ts +2 -3
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAM/encode.js +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +2 -2
- package/lib/Socket/usync.d.ts +0 -36
- package/lib/Socket/usync.js +0 -70
- package/lib/Types/USync.d.ts +0 -25
- package/lib/Types/USync.js +0 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
- package/lib/WAUSync/Protocols/index.d.ts +0 -4
- package/lib/WAUSync/Protocols/index.js +0 -20
- package/lib/WAUSync/USyncQuery.d.ts +0 -28
- package/lib/WAUSync/USyncQuery.js +0 -89
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/USyncUser.js +0 -26
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/WAUSync/index.js +0 -19
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
|
@@ -4,13 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeMessagesRecvSocket = void 0;
|
|
7
|
-
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
8
7
|
const boom_1 = require("@hapi/boom");
|
|
9
8
|
const crypto_1 = require("crypto");
|
|
10
|
-
const
|
|
9
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
10
|
+
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 Utils_2 = require("../Utils");
|
|
14
15
|
const make_mutex_1 = require("../Utils/make-mutex");
|
|
15
16
|
const WABinary_1 = require("../WABinary");
|
|
16
17
|
const groups_1 = require("./groups");
|
|
@@ -22,37 +23,34 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
22
23
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
|
23
24
|
const retryMutex = (0, make_mutex_1.makeMutex)();
|
|
24
25
|
const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
|
|
25
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
26
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
26
27
|
useClones: false
|
|
27
28
|
});
|
|
28
29
|
const callOfferCache = config.callOfferCache || new node_cache_1.default({
|
|
29
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER,
|
|
30
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER,
|
|
30
31
|
useClones: false
|
|
31
32
|
});
|
|
32
33
|
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
|
33
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
34
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
|
34
35
|
useClones: false
|
|
35
36
|
});
|
|
36
37
|
let sendActiveReceipts = false;
|
|
37
|
-
const sendMessageAck = async ({ tag, attrs, content }
|
|
38
|
+
const sendMessageAck = async ({ tag, attrs, content }) => {
|
|
38
39
|
const stanza = {
|
|
39
40
|
tag: 'ack',
|
|
40
41
|
attrs: {
|
|
41
42
|
id: attrs.id,
|
|
42
43
|
to: attrs.from,
|
|
43
|
-
class: tag
|
|
44
|
+
class: tag,
|
|
44
45
|
}
|
|
45
46
|
};
|
|
46
|
-
if (!!errorCode) {
|
|
47
|
-
stanza.attrs.error = errorCode.toString();
|
|
48
|
-
}
|
|
49
47
|
if (!!attrs.participant) {
|
|
50
48
|
stanza.attrs.participant = attrs.participant;
|
|
51
49
|
}
|
|
52
50
|
if (!!attrs.recipient) {
|
|
53
51
|
stanza.attrs.recipient = attrs.recipient;
|
|
54
52
|
}
|
|
55
|
-
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'))) {
|
|
56
54
|
stanza.attrs.type = attrs.type;
|
|
57
55
|
}
|
|
58
56
|
if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
|
|
@@ -371,7 +369,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
371
369
|
const companionSharedKey = Utils_1.Curve.sharedKey(authState.creds.pairingEphemeralKeyPair.private, codePairingPublicKey);
|
|
372
370
|
const random = (0, crypto_1.randomBytes)(32);
|
|
373
371
|
const linkCodeSalt = (0, crypto_1.randomBytes)(32);
|
|
374
|
-
const linkCodePairingExpanded =
|
|
372
|
+
const linkCodePairingExpanded = (0, Utils_1.hkdf)(companionSharedKey, 32, {
|
|
375
373
|
salt: linkCodeSalt,
|
|
376
374
|
info: 'link_code_pairing_key_bundle_encryption_key'
|
|
377
375
|
});
|
|
@@ -381,7 +379,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
381
379
|
const encryptedPayload = Buffer.concat([linkCodeSalt, encryptIv, encrypted]);
|
|
382
380
|
const identitySharedKey = Utils_1.Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
|
|
383
381
|
const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random]);
|
|
384
|
-
authState.creds.advSecretKey = (
|
|
382
|
+
authState.creds.advSecretKey = (0, Utils_1.hkdf)(identityPayload, 32, { info: 'adv_secret' }).toString('base64');
|
|
385
383
|
await query({
|
|
386
384
|
tag: 'iq',
|
|
387
385
|
attrs: {
|
|
@@ -450,7 +448,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
450
448
|
};
|
|
451
449
|
const sendMessagesAgain = async (key, ids, retryNode) => {
|
|
452
450
|
var _a;
|
|
453
|
-
// todo: implement a cache to store the last 256 sent messages (copy whatsmeow)
|
|
454
451
|
const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
|
|
455
452
|
const remoteJid = key.remoteJid;
|
|
456
453
|
const participant = key.participant || remoteJid;
|
|
@@ -463,7 +460,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
463
460
|
await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
|
|
464
461
|
}
|
|
465
462
|
logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
|
|
466
|
-
for (
|
|
463
|
+
for (let i = 0; i < msgs.length; i++) {
|
|
464
|
+
const msg = msgs[i];
|
|
467
465
|
if (msg) {
|
|
468
466
|
updateSendMessageAgainCount(ids[i], participant);
|
|
469
467
|
const msgRelayOpts = { messageId: ids[i] };
|
|
@@ -489,8 +487,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
489
487
|
const isLid = attrs.from.includes('lid');
|
|
490
488
|
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);
|
|
491
489
|
const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
|
|
492
|
-
const fromMe = !attrs.recipient || (
|
|
493
|
-
&& isNodeFromMe);
|
|
490
|
+
const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe);
|
|
494
491
|
const key = {
|
|
495
492
|
remoteJid,
|
|
496
493
|
id: '',
|
|
@@ -515,7 +512,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
515
512
|
(
|
|
516
513
|
// basically, we only want to know when a message from us has been delivered to/read by the other person
|
|
517
514
|
// or another device of ours has read some messages
|
|
518
|
-
status
|
|
515
|
+
status > WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ||
|
|
519
516
|
!isNodeFromMe)) {
|
|
520
517
|
if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
|
|
521
518
|
if (attrs.participant) {
|
|
@@ -605,15 +602,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
605
602
|
await sendMessageAck(node);
|
|
606
603
|
return;
|
|
607
604
|
}
|
|
608
|
-
const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
|
|
609
|
-
// TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
|
|
610
|
-
if (encNode && encNode.attrs.type === 'msmsg') {
|
|
611
|
-
logger.debug({ key: node.attrs.key }, 'ignored msmsg');
|
|
612
|
-
await sendMessageAck(node);
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
605
|
let response;
|
|
616
|
-
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !
|
|
606
|
+
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !(0, WABinary_1.getBinaryNodeChild)(node, 'enc')) {
|
|
617
607
|
await sendMessageAck(node);
|
|
618
608
|
const { key } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
|
|
619
609
|
response = await requestPlaceholderResend(key);
|
|
@@ -631,19 +621,17 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
631
621
|
if (response && ((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT) {
|
|
632
622
|
msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
|
|
633
623
|
}
|
|
634
|
-
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER
|
|
635
|
-
|
|
624
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER) {
|
|
625
|
+
if (node.attrs.sender_pn) {
|
|
626
|
+
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
|
|
627
|
+
}
|
|
636
628
|
}
|
|
637
629
|
try {
|
|
638
630
|
await Promise.all([
|
|
639
631
|
processingMutex.mutex(async () => {
|
|
640
|
-
var _a;
|
|
641
632
|
await decrypt();
|
|
642
633
|
// message failed to decrypt
|
|
643
634
|
if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
|
644
|
-
if (((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.MISSING_KEYS_ERROR_TEXT) {
|
|
645
|
-
return sendMessageAck(node, Utils_1.NACK_REASONS.ParsingError);
|
|
646
|
-
}
|
|
647
635
|
retryMutex.mutex(async () => {
|
|
648
636
|
if (ws.isOpen) {
|
|
649
637
|
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable')) {
|
|
@@ -685,14 +673,13 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
685
673
|
await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
|
|
686
674
|
}
|
|
687
675
|
}
|
|
688
|
-
(0,
|
|
689
|
-
await sendMessageAck(node);
|
|
676
|
+
(0, Utils_2.cleanMessage)(msg, authState.creds.me.id);
|
|
690
677
|
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
|
691
678
|
})
|
|
692
679
|
]);
|
|
693
680
|
}
|
|
694
|
-
|
|
695
|
-
|
|
681
|
+
finally {
|
|
682
|
+
await sendMessageAck(node);
|
|
696
683
|
}
|
|
697
684
|
};
|
|
698
685
|
const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
|
|
@@ -718,7 +705,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
718
705
|
throw new boom_1.Boom('Not authenticated');
|
|
719
706
|
}
|
|
720
707
|
if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
|
721
|
-
logger.debug(
|
|
708
|
+
logger.debug('already requested resend', { messageKey });
|
|
722
709
|
return;
|
|
723
710
|
}
|
|
724
711
|
else {
|
|
@@ -726,7 +713,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
726
713
|
}
|
|
727
714
|
await (0, Utils_1.delay)(5000);
|
|
728
715
|
if (!placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
|
729
|
-
logger.debug(
|
|
716
|
+
logger.debug('message received while resend requested', { messageKey });
|
|
730
717
|
return 'RESOLVED';
|
|
731
718
|
}
|
|
732
719
|
const pdoMessage = {
|
|
@@ -737,7 +724,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
737
724
|
};
|
|
738
725
|
setTimeout(() => {
|
|
739
726
|
if (placeholderResendCache.get(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id)) {
|
|
740
|
-
logger.debug(
|
|
727
|
+
logger.debug('PDO message without response after 15 seconds. Phone possibly offline', { messageKey });
|
|
741
728
|
placeholderResendCache.del(messageKey === null || messageKey === void 0 ? void 0 : messageKey.id);
|
|
742
729
|
}
|
|
743
730
|
}, 15000);
|
|
@@ -778,19 +765,19 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
778
765
|
};
|
|
779
766
|
const handleBadAck = async ({ attrs }) => {
|
|
780
767
|
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
|
|
781
|
-
//
|
|
782
|
-
//
|
|
783
|
-
//
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
768
|
+
// current hypothesis is that if pash is sent in the ack
|
|
769
|
+
// it means -- the message hasn't reached all devices yet
|
|
770
|
+
// we'll retry sending the message here
|
|
771
|
+
if (attrs.phash) {
|
|
772
|
+
logger.info({ attrs }, 'received phash in ack, resending message...');
|
|
773
|
+
const msg = await getMessage(key);
|
|
774
|
+
if (msg) {
|
|
775
|
+
await relayMessage(key.remoteJid, msg, { messageId: key.id, useUserDevicesCache: false });
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
logger.warn({ attrs }, 'could not send message again, as it was not found');
|
|
779
|
+
}
|
|
780
|
+
}
|
|
794
781
|
// error in acknowledgement,
|
|
795
782
|
// device could not display the message
|
|
796
783
|
if (attrs.error) {
|
|
@@ -815,63 +802,22 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
815
802
|
await execTask();
|
|
816
803
|
ev.flush();
|
|
817
804
|
function execTask() {
|
|
818
|
-
return exec(node
|
|
805
|
+
return exec(node)
|
|
819
806
|
.catch(err => onUnexpectedError(err, identifier));
|
|
820
807
|
}
|
|
821
808
|
};
|
|
822
|
-
const makeOfflineNodeProcessor = () => {
|
|
823
|
-
const nodeProcessorMap = new Map([
|
|
824
|
-
['message', handleMessage],
|
|
825
|
-
['call', handleCall],
|
|
826
|
-
['receipt', handleReceipt],
|
|
827
|
-
['notification', handleNotification]
|
|
828
|
-
]);
|
|
829
|
-
const nodes = [];
|
|
830
|
-
let isProcessing = false;
|
|
831
|
-
const enqueue = (type, node) => {
|
|
832
|
-
nodes.push({ type, node });
|
|
833
|
-
if (isProcessing) {
|
|
834
|
-
return;
|
|
835
|
-
}
|
|
836
|
-
isProcessing = true;
|
|
837
|
-
const promise = async () => {
|
|
838
|
-
while (nodes.length && ws.isOpen) {
|
|
839
|
-
const { type, node } = nodes.shift();
|
|
840
|
-
const nodeProcessor = nodeProcessorMap.get(type);
|
|
841
|
-
if (!nodeProcessor) {
|
|
842
|
-
onUnexpectedError(new Error(`unknown offline node type: ${type}`), 'processing offline node');
|
|
843
|
-
continue;
|
|
844
|
-
}
|
|
845
|
-
await nodeProcessor(node);
|
|
846
|
-
}
|
|
847
|
-
isProcessing = false;
|
|
848
|
-
};
|
|
849
|
-
promise().catch(error => onUnexpectedError(error, 'processing offline nodes'));
|
|
850
|
-
};
|
|
851
|
-
return { enqueue };
|
|
852
|
-
};
|
|
853
|
-
const offlineNodeProcessor = makeOfflineNodeProcessor();
|
|
854
|
-
const processNode = (type, node, identifier, exec) => {
|
|
855
|
-
const isOffline = !!node.attrs.offline;
|
|
856
|
-
if (isOffline) {
|
|
857
|
-
offlineNodeProcessor.enqueue(type, node);
|
|
858
|
-
}
|
|
859
|
-
else {
|
|
860
|
-
processNodeWithBuffer(node, identifier, exec);
|
|
861
|
-
}
|
|
862
|
-
};
|
|
863
809
|
// recv a message
|
|
864
810
|
ws.on('CB:message', (node) => {
|
|
865
|
-
|
|
811
|
+
processNodeWithBuffer(node, 'processing message', handleMessage);
|
|
866
812
|
});
|
|
867
813
|
ws.on('CB:call', async (node) => {
|
|
868
|
-
|
|
814
|
+
processNodeWithBuffer(node, 'handling call', handleCall);
|
|
869
815
|
});
|
|
870
816
|
ws.on('CB:receipt', node => {
|
|
871
|
-
|
|
817
|
+
processNodeWithBuffer(node, 'handling receipt', handleReceipt);
|
|
872
818
|
});
|
|
873
819
|
ws.on('CB:notification', async (node) => {
|
|
874
|
-
|
|
820
|
+
processNodeWithBuffer(node, 'handling notification', handleNotification);
|
|
875
821
|
});
|
|
876
822
|
ws.on('CB:ack,class:message', (node) => {
|
|
877
823
|
handleBadAck(node)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Boom } from '@hapi/boom';
|
|
2
3
|
import { proto } from '../../WAProto';
|
|
3
4
|
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
|
|
4
5
|
import { BinaryNode, JidWithDevice } from '../WABinary';
|
|
5
|
-
import { USyncQuery } from '../WAUSync';
|
|
6
6
|
export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
7
|
-
getPrivacyTokens: (jids: string[]) => Promise<
|
|
7
|
+
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
|
8
8
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
9
9
|
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
|
10
10
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
|
@@ -16,7 +16,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
16
16
|
[_: string]: string;
|
|
17
17
|
}>;
|
|
18
18
|
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
19
|
-
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode[
|
|
19
|
+
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
|
|
20
20
|
nodes: BinaryNode[];
|
|
21
21
|
shouldIncludeDeviceIdentity: boolean;
|
|
22
22
|
}>;
|
|
@@ -30,7 +30,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
30
30
|
groupRequestParticipantsList: (jid: string) => Promise<{
|
|
31
31
|
[key: string]: string;
|
|
32
32
|
}[]>;
|
|
33
|
-
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "
|
|
33
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
|
|
34
34
|
status: string;
|
|
35
35
|
jid: string;
|
|
36
36
|
}[]>;
|
|
@@ -39,44 +39,43 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
39
39
|
jid: string;
|
|
40
40
|
content: BinaryNode;
|
|
41
41
|
}[]>;
|
|
42
|
-
groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
|
42
|
+
groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
|
43
43
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
44
44
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
45
45
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
46
46
|
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
47
|
-
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<
|
|
47
|
+
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
|
|
48
48
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
49
49
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
50
|
-
groupSettingUpdate: (jid: string, setting: "announcement" | "
|
|
51
|
-
groupMemberAddMode: (jid: string, mode: "
|
|
50
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
51
|
+
groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
|
|
52
52
|
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
53
53
|
groupFetchAllParticipating: () => Promise<{
|
|
54
54
|
[_: string]: import("../Types").GroupMetadata;
|
|
55
55
|
}>;
|
|
56
|
-
getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
|
|
57
56
|
processingMutex: {
|
|
58
|
-
mutex<T>(code: () =>
|
|
57
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
|
59
58
|
};
|
|
60
59
|
upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
61
60
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
62
|
-
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
|
63
|
-
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
64
|
-
profilePictureUrl: (jid: string, type?: "
|
|
61
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
|
|
62
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
|
|
63
|
+
profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
|
|
65
64
|
onWhatsApp: (...jids: string[]) => Promise<{
|
|
65
|
+
exists: boolean;
|
|
66
66
|
jid: string;
|
|
67
|
-
|
|
68
|
-
lid: unknown;
|
|
69
|
-
}[] | undefined>;
|
|
67
|
+
}[]>;
|
|
70
68
|
fetchBlocklist: () => Promise<string[]>;
|
|
71
|
-
fetchStatus: (
|
|
72
|
-
|
|
69
|
+
fetchStatus: (jid: string) => Promise<{
|
|
70
|
+
status: string | undefined;
|
|
71
|
+
setAt: Date;
|
|
72
|
+
} | undefined>;
|
|
73
73
|
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
|
74
74
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
75
75
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
76
76
|
updateProfileName: (name: string) => Promise<void>;
|
|
77
77
|
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
|
|
78
78
|
updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
|
|
79
|
-
updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
|
|
80
79
|
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
81
80
|
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
|
|
82
81
|
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
@@ -84,10 +83,10 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
84
83
|
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
85
84
|
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
|
86
85
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
87
|
-
getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile
|
|
86
|
+
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
|
88
87
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
89
88
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
90
|
-
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number |
|
|
89
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
|
91
90
|
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
92
91
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
93
92
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
@@ -95,16 +94,15 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
95
94
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
96
95
|
star: (jid: string, messages: {
|
|
97
96
|
id: string;
|
|
98
|
-
fromMe?: boolean;
|
|
97
|
+
fromMe?: boolean | undefined;
|
|
99
98
|
}[], star: boolean) => Promise<void>;
|
|
100
|
-
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
|
101
99
|
type: "md";
|
|
102
|
-
ws:
|
|
100
|
+
ws: any;
|
|
103
101
|
ev: import("../Types").BaileysEventEmitter & {
|
|
104
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (
|
|
102
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
105
103
|
buffer(): void;
|
|
106
|
-
createBufferedFunction<A extends any[],
|
|
107
|
-
flush(force?: boolean): boolean;
|
|
104
|
+
createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
|
|
105
|
+
flush(force?: boolean | undefined): boolean;
|
|
108
106
|
isBuffering(): boolean;
|
|
109
107
|
};
|
|
110
108
|
authState: {
|
|
@@ -114,17 +112,17 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
114
112
|
signalRepository: import("../Types").SignalRepository;
|
|
115
113
|
user: import("../Types").Contact | undefined;
|
|
116
114
|
generateMessageTag: () => string;
|
|
117
|
-
query: (node: BinaryNode, timeoutMs?: number) => Promise<
|
|
118
|
-
waitForMessage: <
|
|
115
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
|
|
116
|
+
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
|
|
119
117
|
waitForSocketOpen: () => Promise<void>;
|
|
120
118
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
121
119
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
122
|
-
logout: (msg?: string) => Promise<void>;
|
|
120
|
+
logout: (msg?: string | undefined) => Promise<void>;
|
|
123
121
|
end: (error: Error | undefined) => void;
|
|
124
|
-
onUnexpectedError: (err: Error | Boom
|
|
122
|
+
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
|
125
123
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
126
124
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
127
125
|
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
128
|
-
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) =>
|
|
129
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
|
126
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
127
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
130
128
|
};
|