@d0v3riz/baileys 6.7.6 → 6.7.8
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 -10
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +1 -231
- package/lib/Defaults/index.js +1 -17
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
- package/lib/Socket/business.d.ts +10 -1
- package/lib/Socket/chats.d.ts +4 -1
- package/lib/Socket/chats.js +39 -11
- package/lib/Socket/groups.d.ts +3 -1
- package/lib/Socket/index.d.ts +17 -10
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.d.ts +11 -2
- package/lib/Socket/messages-recv.js +127 -118
- package/lib/Socket/messages-send.d.ts +9 -2
- package/lib/Socket/messages-send.js +26 -9
- package/lib/Socket/socket.d.ts +3 -1
- package/lib/Socket/socket.js +9 -14
- package/lib/Store/make-cache-manager-store.d.ts +2 -1
- package/lib/Store/make-in-memory-store.js +8 -10
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +1 -6
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +10 -7
- package/lib/Types/Contact.d.ts +1 -1
- package/lib/Types/Events.d.ts +4 -0
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Message.d.ts +5 -2
- package/lib/Types/Socket.d.ts +3 -3
- package/lib/Utils/auth-utils.js +1 -7
- package/lib/Utils/chat-utils.d.ts +5 -4
- package/lib/Utils/chat-utils.js +41 -20
- package/lib/Utils/crypto.d.ts +1 -0
- package/lib/Utils/decode-wa-message.js +1 -0
- package/lib/Utils/event-buffer.js +14 -8
- package/lib/Utils/generics.d.ts +10 -5
- package/lib/Utils/generics.js +35 -7
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/history.js +1 -1
- package/lib/Utils/link-preview.js +24 -1
- package/lib/Utils/make-mutex.js +1 -0
- package/lib/Utils/messages-media.d.ts +2 -1
- package/lib/Utils/messages-media.js +8 -15
- package/lib/Utils/messages.d.ts +1 -0
- package/lib/Utils/messages.js +7 -11
- package/lib/Utils/noise-handler.d.ts +2 -2
- package/lib/Utils/noise-handler.js +5 -10
- package/lib/Utils/process-message.js +3 -1
- package/lib/Utils/signal.js +2 -0
- package/lib/Utils/use-multi-file-auth-state.js +1 -0
- package/lib/Utils/validate-connection.d.ts +0 -1
- package/lib/Utils/validate-connection.js +10 -44
- package/lib/WABinary/constants.js +5 -5
- package/lib/WABinary/decode.d.ts +1 -0
- package/lib/WABinary/encode.d.ts +1 -0
- package/lib/WABinary/encode.js +7 -5
- package/lib/WABinary/generic-utils.d.ts +1 -0
- package/lib/WABinary/jid-utils.d.ts +2 -2
- package/lib/WABinary/jid-utils.js +1 -1
- package/lib/WAM/BinaryInfo.d.ts +3 -2
- package/lib/WAM/constants.d.ts +3 -2
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +2 -2
- package/package.json +5 -6
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/registration.d.ts +0 -234
- package/lib/Socket/registration.js +0 -166
- /package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +0 -0
- /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { Boom } from '@hapi/boom';
|
|
3
4
|
import { proto } from '../../WAProto';
|
|
4
5
|
import { MessageReceiptType, MessageRelayOptions, SocketConfig, WAMessageKey } from '../Types';
|
|
@@ -8,7 +9,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
8
9
|
sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
|
|
9
10
|
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
10
11
|
fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
|
|
11
|
-
requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<
|
|
12
|
+
requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<string | undefined>;
|
|
12
13
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
|
13
14
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
14
15
|
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
|
@@ -21,6 +22,13 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
21
22
|
[_: string]: string;
|
|
22
23
|
}>;
|
|
23
24
|
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
25
|
+
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: {
|
|
26
|
+
[key: string]: string;
|
|
27
|
+
} | undefined) => Promise<{
|
|
28
|
+
nodes: BinaryNode[];
|
|
29
|
+
shouldIncludeDeviceIdentity: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
|
|
24
32
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
|
25
33
|
sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
|
26
34
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
@@ -87,6 +95,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
87
95
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
88
96
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
89
97
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
|
98
|
+
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
90
99
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
91
100
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
92
101
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
@@ -96,7 +105,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
|
|
|
96
105
|
fromMe?: boolean | undefined;
|
|
97
106
|
}[], star: boolean) => Promise<void>;
|
|
98
107
|
type: "md";
|
|
99
|
-
ws:
|
|
108
|
+
ws: import("./Client").WebSocketClient;
|
|
100
109
|
ev: import("../Types").BaileysEventEmitter & {
|
|
101
110
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
102
111
|
buffer(): void;
|
|
@@ -320,7 +320,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
320
320
|
const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
|
|
321
321
|
const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
|
|
322
322
|
ev.emit('contacts.update', [{
|
|
323
|
-
id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.
|
|
323
|
+
id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.from) || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
|
|
324
324
|
imgUrl: setPicture ? 'changed' : 'removed'
|
|
325
325
|
}]);
|
|
326
326
|
if ((0, WABinary_1.isJidGroup)(from)) {
|
|
@@ -460,8 +460,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
460
460
|
await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
|
|
461
461
|
}
|
|
462
462
|
logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
|
|
463
|
-
for (
|
|
464
|
-
const msg = msgs[i];
|
|
463
|
+
for (const [i, msg] of msgs.entries()) {
|
|
465
464
|
if (msg) {
|
|
466
465
|
updateSendMessageAgainCount(ids[i], participant);
|
|
467
466
|
const msgRelayOpts = { messageId: ids[i] };
|
|
@@ -504,59 +503,63 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
504
503
|
const items = (0, WABinary_1.getBinaryNodeChildren)(content[0], 'item');
|
|
505
504
|
ids.push(...items.map(i => i.attrs.id));
|
|
506
505
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
(
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
if (
|
|
518
|
-
|
|
519
|
-
|
|
506
|
+
try {
|
|
507
|
+
await Promise.all([
|
|
508
|
+
processingMutex.mutex(async () => {
|
|
509
|
+
const status = (0, Utils_1.getStatusFromReceiptType)(attrs.type);
|
|
510
|
+
if (typeof status !== 'undefined' &&
|
|
511
|
+
(
|
|
512
|
+
// basically, we only want to know when a message from us has been delivered to/read by the other person
|
|
513
|
+
// or another device of ours has read some messages
|
|
514
|
+
status > WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ||
|
|
515
|
+
!isNodeFromMe)) {
|
|
516
|
+
if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
|
|
517
|
+
if (attrs.participant) {
|
|
518
|
+
const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
|
|
519
|
+
ev.emit('message-receipt.update', ids.map(id => ({
|
|
520
|
+
key: { ...key, id },
|
|
521
|
+
receipt: {
|
|
522
|
+
userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
|
|
523
|
+
[updateKey]: +attrs.t
|
|
524
|
+
}
|
|
525
|
+
})));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
ev.emit('messages.update', ids.map(id => ({
|
|
520
530
|
key: { ...key, id },
|
|
521
|
-
|
|
522
|
-
userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
|
|
523
|
-
[updateKey]: +attrs.t
|
|
524
|
-
}
|
|
531
|
+
update: { status }
|
|
525
532
|
})));
|
|
526
533
|
}
|
|
527
534
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
try {
|
|
542
|
-
logger.debug({ attrs, key }, 'recv retry request');
|
|
543
|
-
await sendMessagesAgain(key, ids, retryNode);
|
|
535
|
+
if (attrs.type === 'retry') {
|
|
536
|
+
// correctly set who is asking for the retry
|
|
537
|
+
key.participant = key.participant || attrs.from;
|
|
538
|
+
const retryNode = (0, WABinary_1.getBinaryNodeChild)(node, 'retry');
|
|
539
|
+
if (willSendMessageAgain(ids[0], key.participant)) {
|
|
540
|
+
if (key.fromMe) {
|
|
541
|
+
try {
|
|
542
|
+
logger.debug({ attrs, key }, 'recv retry request');
|
|
543
|
+
await sendMessagesAgain(key, ids, retryNode);
|
|
544
|
+
}
|
|
545
|
+
catch (error) {
|
|
546
|
+
logger.error({ key, ids, trace: error.stack }, 'error in sending message again');
|
|
547
|
+
}
|
|
544
548
|
}
|
|
545
|
-
|
|
546
|
-
logger.
|
|
549
|
+
else {
|
|
550
|
+
logger.info({ attrs, key }, 'recv retry for not fromMe message');
|
|
547
551
|
}
|
|
548
552
|
}
|
|
549
553
|
else {
|
|
550
|
-
logger.info({ attrs, key }, '
|
|
554
|
+
logger.info({ attrs, key }, 'will not send message again, as sent too many times');
|
|
551
555
|
}
|
|
552
556
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
]);
|
|
557
|
+
})
|
|
558
|
+
]);
|
|
559
|
+
}
|
|
560
|
+
finally {
|
|
561
|
+
await sendMessageAck(node);
|
|
562
|
+
}
|
|
560
563
|
};
|
|
561
564
|
const handleNotification = async (node) => {
|
|
562
565
|
const remoteJid = node.attrs.from;
|
|
@@ -565,27 +568,31 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
565
568
|
await sendMessageAck(node);
|
|
566
569
|
return;
|
|
567
570
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
571
|
+
try {
|
|
572
|
+
await Promise.all([
|
|
573
|
+
processingMutex.mutex(async () => {
|
|
574
|
+
var _a;
|
|
575
|
+
const msg = await processNotification(node);
|
|
576
|
+
if (msg) {
|
|
577
|
+
const fromMe = (0, WABinary_1.areJidsSameUser)(node.attrs.participant || remoteJid, authState.creds.me.id);
|
|
578
|
+
msg.key = {
|
|
579
|
+
remoteJid,
|
|
580
|
+
fromMe,
|
|
581
|
+
participant: node.attrs.participant,
|
|
582
|
+
id: node.attrs.id,
|
|
583
|
+
...(msg.key || {})
|
|
584
|
+
};
|
|
585
|
+
(_a = msg.participant) !== null && _a !== void 0 ? _a : (msg.participant = node.attrs.participant);
|
|
586
|
+
msg.messageTimestamp = +node.attrs.t;
|
|
587
|
+
const fullMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
|
|
588
|
+
await upsertMessage(fullMsg, 'append');
|
|
589
|
+
}
|
|
590
|
+
})
|
|
591
|
+
]);
|
|
592
|
+
}
|
|
593
|
+
finally {
|
|
594
|
+
await sendMessageAck(node);
|
|
595
|
+
}
|
|
589
596
|
};
|
|
590
597
|
const handleMessage = async (node) => {
|
|
591
598
|
var _a, _b, _c;
|
|
@@ -613,62 +620,64 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
613
620
|
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) {
|
|
614
621
|
msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
|
|
615
622
|
}
|
|
616
|
-
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) {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
623
|
+
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 && node.attrs.sender_pn) {
|
|
624
|
+
ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
|
|
625
|
+
}
|
|
626
|
+
try {
|
|
627
|
+
await Promise.all([
|
|
628
|
+
processingMutex.mutex(async () => {
|
|
629
|
+
await decrypt();
|
|
630
|
+
// message failed to decrypt
|
|
631
|
+
if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
|
632
|
+
retryMutex.mutex(async () => {
|
|
633
|
+
if (ws.isOpen) {
|
|
634
|
+
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable')) {
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
|
|
638
|
+
await sendRetryRequest(node, !encNode);
|
|
639
|
+
if (retryRequestDelayMs) {
|
|
640
|
+
await (0, Utils_1.delay)(retryRequestDelayMs);
|
|
641
|
+
}
|
|
630
642
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
if (retryRequestDelayMs) {
|
|
634
|
-
await (0, Utils_1.delay)(retryRequestDelayMs);
|
|
643
|
+
else {
|
|
644
|
+
logger.debug({ node }, 'connection closed, ignoring retry req');
|
|
635
645
|
}
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
// no type in the receipt => message delivered
|
|
650
|
+
let type = undefined;
|
|
651
|
+
let participant = msg.key.participant;
|
|
652
|
+
if (category === 'peer') { // special peer message
|
|
653
|
+
type = 'peer_msg';
|
|
636
654
|
}
|
|
637
|
-
else {
|
|
638
|
-
|
|
655
|
+
else if (msg.key.fromMe) { // message was sent by us from a different device
|
|
656
|
+
type = 'sender';
|
|
657
|
+
// need to specially handle this case
|
|
658
|
+
if ((0, WABinary_1.isJidUser)(msg.key.remoteJid)) {
|
|
659
|
+
participant = author;
|
|
660
|
+
}
|
|
639
661
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
else if (msg.key.fromMe) { // message was sent by us from a different device
|
|
650
|
-
type = 'sender';
|
|
651
|
-
// need to specially handle this case
|
|
652
|
-
if ((0, WABinary_1.isJidUser)(msg.key.remoteJid)) {
|
|
653
|
-
participant = author;
|
|
662
|
+
else if (!sendActiveReceipts) {
|
|
663
|
+
type = 'inactive';
|
|
664
|
+
}
|
|
665
|
+
await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
|
|
666
|
+
// send ack for history message
|
|
667
|
+
const isAnyHistoryMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
668
|
+
if (isAnyHistoryMsg) {
|
|
669
|
+
const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
|
|
670
|
+
await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
|
|
654
671
|
}
|
|
655
672
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
(0, Utils_2.cleanMessage)(msg, authState.creds.me.id);
|
|
668
|
-
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
|
669
|
-
}),
|
|
670
|
-
sendMessageAck(node)
|
|
671
|
-
]);
|
|
673
|
+
(0, Utils_2.cleanMessage)(msg, authState.creds.me.id);
|
|
674
|
+
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
|
675
|
+
})
|
|
676
|
+
]);
|
|
677
|
+
}
|
|
678
|
+
finally {
|
|
679
|
+
await sendMessageAck(node);
|
|
680
|
+
}
|
|
672
681
|
};
|
|
673
682
|
const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
|
|
674
683
|
var _a;
|
|
@@ -745,7 +754,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
745
754
|
call.isGroup = existingCall.isGroup;
|
|
746
755
|
}
|
|
747
756
|
// delete data once call has ended
|
|
748
|
-
if (status === 'reject' || status === 'accept' || status === 'timeout') {
|
|
757
|
+
if (status === 'reject' || status === 'accept' || status === 'timeout' || status === 'terminate') {
|
|
749
758
|
callOfferCache.del(call.id);
|
|
750
759
|
}
|
|
751
760
|
ev.emit('call', [call]);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { Boom } from '@hapi/boom';
|
|
3
4
|
import { proto } from '../../WAProto';
|
|
4
5
|
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
|
|
5
|
-
import { BinaryNode } from '../WABinary';
|
|
6
|
+
import { BinaryNode, JidWithDevice } from '../WABinary';
|
|
6
7
|
export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
7
8
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
|
8
9
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
|
@@ -16,6 +17,11 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
16
17
|
[_: string]: string;
|
|
17
18
|
}>;
|
|
18
19
|
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
20
|
+
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
|
|
21
|
+
nodes: BinaryNode[];
|
|
22
|
+
shouldIncludeDeviceIdentity: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
|
|
19
25
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
|
20
26
|
sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
|
21
27
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
@@ -82,6 +88,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
82
88
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
83
89
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
84
90
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
|
91
|
+
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
85
92
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
86
93
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
87
94
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
@@ -91,7 +98,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
91
98
|
fromMe?: boolean | undefined;
|
|
92
99
|
}[], star: boolean) => Promise<void>;
|
|
93
100
|
type: "md";
|
|
94
|
-
ws:
|
|
101
|
+
ws: import("./Client").WebSocketClient;
|
|
95
102
|
ev: import("../Types").BaileysEventEmitter & {
|
|
96
103
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
97
104
|
buffer(): void;
|
|
@@ -319,7 +319,7 @@ const makeMessagesSocket = (config) => {
|
|
|
319
319
|
if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
|
|
320
320
|
logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
|
|
321
321
|
}
|
|
322
|
-
else {
|
|
322
|
+
else if (!isStatus) {
|
|
323
323
|
groupData = await groupMetadata(jid);
|
|
324
324
|
}
|
|
325
325
|
return groupData;
|
|
@@ -380,14 +380,13 @@ const makeMessagesSocket = (config) => {
|
|
|
380
380
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
|
381
381
|
}
|
|
382
382
|
else {
|
|
383
|
-
const { user: meUser
|
|
383
|
+
const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
|
|
384
384
|
if (!participant) {
|
|
385
385
|
devices.push({ user });
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
386
|
+
if (user !== meUser) {
|
|
387
|
+
devices.push({ user: meUser });
|
|
388
|
+
}
|
|
389
|
+
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
|
|
391
390
|
const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
|
|
392
391
|
devices.push(...additionalDevices);
|
|
393
392
|
}
|
|
@@ -434,7 +433,7 @@ const makeMessagesSocket = (config) => {
|
|
|
434
433
|
tag: 'message',
|
|
435
434
|
attrs: {
|
|
436
435
|
id: msgId,
|
|
437
|
-
type:
|
|
436
|
+
type: getMessageType(message),
|
|
438
437
|
...(additionalAttributes || {})
|
|
439
438
|
},
|
|
440
439
|
content: binaryNodeContent
|
|
@@ -474,6 +473,12 @@ const makeMessagesSocket = (config) => {
|
|
|
474
473
|
});
|
|
475
474
|
return msgId;
|
|
476
475
|
};
|
|
476
|
+
const getMessageType = (message) => {
|
|
477
|
+
if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
|
|
478
|
+
return 'poll';
|
|
479
|
+
}
|
|
480
|
+
return 'text';
|
|
481
|
+
};
|
|
477
482
|
const getMediaType = (message) => {
|
|
478
483
|
if (message.imageMessage) {
|
|
479
484
|
return 'image';
|
|
@@ -561,6 +566,8 @@ const makeMessagesSocket = (config) => {
|
|
|
561
566
|
waUploadToServer,
|
|
562
567
|
fetchPrivacySettings,
|
|
563
568
|
sendPeerDataOperationMessage,
|
|
569
|
+
createParticipantNodes,
|
|
570
|
+
getUSyncDevices,
|
|
564
571
|
updateMediaMessage: async (message) => {
|
|
565
572
|
const content = (0, Utils_1.assertMediaContent)(message.message);
|
|
566
573
|
const mediaKey = content.mediaKey;
|
|
@@ -641,7 +648,9 @@ const makeMessagesSocket = (config) => {
|
|
|
641
648
|
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
642
649
|
const isEditMsg = 'edit' in content && !!content.edit;
|
|
643
650
|
const isPinMsg = 'pin' in content && !!content.pin;
|
|
651
|
+
const isPollMessage = 'poll' in content && !!content.poll;
|
|
644
652
|
const additionalAttributes = {};
|
|
653
|
+
const additionalNodes = [];
|
|
645
654
|
// required for delete
|
|
646
655
|
if (isDeleteMsg) {
|
|
647
656
|
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
@@ -658,10 +667,18 @@ const makeMessagesSocket = (config) => {
|
|
|
658
667
|
else if (isPinMsg) {
|
|
659
668
|
additionalAttributes.edit = '2';
|
|
660
669
|
}
|
|
670
|
+
else if (isPollMessage) {
|
|
671
|
+
additionalNodes.push({
|
|
672
|
+
tag: 'meta',
|
|
673
|
+
attrs: {
|
|
674
|
+
polltype: 'creation'
|
|
675
|
+
},
|
|
676
|
+
});
|
|
677
|
+
}
|
|
661
678
|
if ('cachedGroupMetadata' in options) {
|
|
662
679
|
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
|
|
663
680
|
}
|
|
664
|
-
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList });
|
|
681
|
+
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList, additionalNodes });
|
|
665
682
|
if (config.emitOwnEvents) {
|
|
666
683
|
process.nextTick(() => {
|
|
667
684
|
processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
|
package/lib/Socket/socket.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { Boom } from '@hapi/boom';
|
|
3
4
|
import { SocketConfig } from '../Types';
|
|
4
5
|
import { BinaryNode } from '../WABinary';
|
|
6
|
+
import { WebSocketClient } from './Client';
|
|
5
7
|
/**
|
|
6
8
|
* Connects to WA servers and performs:
|
|
7
9
|
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
@@ -10,7 +12,7 @@ import { BinaryNode } from '../WABinary';
|
|
|
10
12
|
*/
|
|
11
13
|
export declare const makeSocket: (config: SocketConfig) => {
|
|
12
14
|
type: "md";
|
|
13
|
-
ws:
|
|
15
|
+
ws: WebSocketClient;
|
|
14
16
|
ev: import("../Types").BaileysEventEmitter & {
|
|
15
17
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
16
18
|
buffer(): void;
|
package/lib/Socket/socket.js
CHANGED
|
@@ -20,15 +20,14 @@ const Client_1 = require("./Client");
|
|
|
20
20
|
const makeSocket = (config) => {
|
|
21
21
|
var _a, _b;
|
|
22
22
|
const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
|
|
23
|
+
const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
|
|
24
|
+
if (config.mobile || url.protocol === 'tcp:') {
|
|
25
|
+
throw new boom_1.Boom('Mobile API is not supported anymore', { statusCode: Types_1.DisconnectReason.loggedOut });
|
|
27
26
|
}
|
|
28
|
-
if (
|
|
27
|
+
if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
|
|
29
28
|
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
|
|
30
29
|
}
|
|
31
|
-
const ws =
|
|
30
|
+
const ws = new Client_1.WebSocketClient(url, config);
|
|
32
31
|
ws.connect();
|
|
33
32
|
const ev = (0, Utils_1.makeEventBuffer)(logger);
|
|
34
33
|
/** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
|
|
@@ -36,8 +35,7 @@ const makeSocket = (config) => {
|
|
|
36
35
|
/** WA noise protocol wrapper */
|
|
37
36
|
const noise = (0, Utils_1.makeNoiseHandler)({
|
|
38
37
|
keyPair: ephemeralKeyPair,
|
|
39
|
-
NOISE_HEADER:
|
|
40
|
-
mobile: config.mobile,
|
|
38
|
+
NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
|
|
41
39
|
logger,
|
|
42
40
|
routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
|
|
43
41
|
});
|
|
@@ -159,10 +157,7 @@ const makeSocket = (config) => {
|
|
|
159
157
|
logger.trace({ handshake }, 'handshake recv from WA');
|
|
160
158
|
const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
|
|
161
159
|
let node;
|
|
162
|
-
if (
|
|
163
|
-
node = (0, Utils_1.generateMobileNode)(config);
|
|
164
|
-
}
|
|
165
|
-
else if (!creds.me) {
|
|
160
|
+
if (!creds.me) {
|
|
166
161
|
node = (0, Utils_1.generateRegistrationNode)(creds, config);
|
|
167
162
|
logger.info({ node }, 'not logged in, attempting registration...');
|
|
168
163
|
}
|
|
@@ -232,11 +227,11 @@ const makeSocket = (config) => {
|
|
|
232
227
|
const l0 = frame.tag;
|
|
233
228
|
const l1 = frame.attrs || {};
|
|
234
229
|
const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
|
|
235
|
-
Object.keys(l1)
|
|
230
|
+
for (const key of Object.keys(l1)) {
|
|
236
231
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
|
|
237
232
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
|
|
238
233
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
|
|
239
|
-
}
|
|
234
|
+
}
|
|
240
235
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
|
|
241
236
|
anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
|
|
242
237
|
if (!anyTriggered && logger.level === 'debug') {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Store } from 'cache-manager';
|
|
1
2
|
import { AuthenticationCreds } from '../Types';
|
|
2
|
-
declare const makeCacheManagerAuthState: (store:
|
|
3
|
+
declare const makeCacheManagerAuthState: (store: Store, sessionKey: string) => Promise<{
|
|
3
4
|
clearState: () => Promise<void>;
|
|
4
5
|
saveCreds: () => Promise<void>;
|
|
5
6
|
state: {
|
|
@@ -182,16 +182,14 @@ exports.default = (config) => {
|
|
|
182
182
|
const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
|
|
183
183
|
const list = assertMessageList(jid);
|
|
184
184
|
list.upsert(msg, 'append');
|
|
185
|
-
if (type === 'notify') {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
]);
|
|
194
|
-
}
|
|
185
|
+
if (type === 'notify' && !chats.get(jid)) {
|
|
186
|
+
ev.emit('chats.upsert', [
|
|
187
|
+
{
|
|
188
|
+
id: jid,
|
|
189
|
+
conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
|
|
190
|
+
unreadCount: 1
|
|
191
|
+
}
|
|
192
|
+
]);
|
|
195
193
|
}
|
|
196
194
|
}
|
|
197
195
|
break;
|
|
@@ -56,9 +56,9 @@ function makeOrderedDictionary(idGetter) {
|
|
|
56
56
|
},
|
|
57
57
|
clear: () => {
|
|
58
58
|
array.splice(0, array.length);
|
|
59
|
-
Object.keys(dict)
|
|
59
|
+
for (const key of Object.keys(dict)) {
|
|
60
60
|
delete dict[key];
|
|
61
|
-
}
|
|
61
|
+
}
|
|
62
62
|
},
|
|
63
63
|
filter: (contain) => {
|
|
64
64
|
let i = 0;
|
package/lib/Types/Auth.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import type { proto } from '../../WAProto';
|
|
3
|
-
import { RegistrationOptions } from '../Socket/registration';
|
|
4
4
|
import type { Contact } from './Contact';
|
|
5
5
|
import type { MinimalMessage } from './Message';
|
|
6
6
|
export type KeyPair = {
|
|
@@ -57,12 +57,7 @@ export type AuthenticationCreds = SignalCreds & {
|
|
|
57
57
|
/** number of times history & app state has been synced */
|
|
58
58
|
accountSyncCounter: number;
|
|
59
59
|
accountSettings: AccountSettings;
|
|
60
|
-
deviceId: string;
|
|
61
|
-
phoneId: string;
|
|
62
|
-
identityId: Buffer;
|
|
63
60
|
registered: boolean;
|
|
64
|
-
backupToken: Buffer;
|
|
65
|
-
registration: RegistrationOptions;
|
|
66
61
|
pairingCode: string | undefined;
|
|
67
62
|
lastPropHash: string | undefined;
|
|
68
63
|
routingInfo: Buffer | undefined;
|