@heavstaltech/baileys 2.3.4 → 3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +226 -53
- package/WAProto/index.js +14270 -302
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +118 -79
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
- package/lib/Signal/libsignal.js +51 -29
- package/lib/Socket/business.d.ts +43 -42
- package/lib/Socket/chats.d.ts +222 -36
- package/lib/Socket/chats.js +186 -153
- package/lib/Socket/dugong.d.ts +254 -0
- package/lib/Socket/dugong.js +484 -0
- package/lib/Socket/groups.d.ts +7 -7
- package/lib/Socket/groups.js +37 -35
- package/lib/Socket/index.d.ts +52 -51
- package/lib/Socket/index.js +1 -0
- package/lib/Socket/messages-recv.d.ts +37 -34
- package/lib/Socket/messages-recv.js +175 -37
- package/lib/Socket/messages-send.d.ts +12 -18
- package/lib/Socket/messages-send.js +396 -574
- package/lib/Socket/newsletter.d.ts +28 -26
- package/lib/Socket/newsletter.js +140 -25
- 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 +47 -198
- package/lib/Socket/usync.d.ts +10 -11
- package/lib/Store/make-cache-manager-store.d.ts +1 -2
- package/lib/Store/make-in-memory-store.d.ts +2 -2
- package/lib/Store/make-in-memory-store.js +1 -5
- package/lib/Store/make-ordered-dictionary.js +2 -2
- 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.d.ts +97 -86
- package/lib/Types/Newsletter.js +38 -32
- package/lib/Types/Socket.d.ts +2 -7
- package/lib/Types/index.d.ts +0 -9
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +14 -35
- 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 +36 -52
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +26 -74
- package/lib/Utils/decode-wa-message.d.ts +0 -17
- package/lib/Utils/decode-wa-message.js +17 -53
- package/lib/Utils/event-buffer.js +7 -10
- package/lib/Utils/generics.d.ts +17 -13
- package/lib/Utils/generics.js +79 -58
- 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/lt-hash.js +12 -12
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +28 -25
- package/lib/Utils/messages-media.js +201 -103
- package/lib/Utils/messages.js +36 -473
- package/lib/Utils/noise-handler.d.ts +5 -4
- package/lib/Utils/noise-handler.js +14 -19
- package/lib/Utils/process-message.d.ts +5 -5
- package/lib/Utils/process-message.js +23 -75
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +26 -32
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +66 -242
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.js +88 -64
- package/lib/WABinary/constants.d.ts +27 -24
- package/lib/WABinary/decode.d.ts +2 -1
- package/lib/WABinary/decode.js +11 -23
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +147 -134
- package/lib/WABinary/generic-utils.d.ts +5 -2
- package/lib/WABinary/generic-utils.js +125 -37
- 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/USyncUser.d.ts +2 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +12 -0
- package/package.json +102 -98
- package/WAProto/index.d.ts +0 -50383
- package/WASignalGroup/GroupProtocol.js +0 -1697
- package/WASignalGroup/ciphertext_message.js +0 -16
- package/WASignalGroup/group_cipher.js +0 -120
- package/WASignalGroup/group_session_builder.js +0 -46
- package/WASignalGroup/index.js +0 -5
- package/WASignalGroup/keyhelper.js +0 -21
- package/WASignalGroup/protobufs.js +0 -3
- package/WASignalGroup/queue_job.js +0 -69
- package/WASignalGroup/sender_chain_key.js +0 -50
- package/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/WASignalGroup/sender_key_message.js +0 -92
- package/WASignalGroup/sender_key_name.js +0 -70
- package/WASignalGroup/sender_key_record.js +0 -56
- package/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-state.js +0 -75
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.makeMessagesRecvSocket = void 0;
|
|
7
7
|
const boom_1 = require("@hapi/boom");
|
|
8
8
|
const crypto_1 = require("crypto");
|
|
9
|
-
const node_cache_1 = __importDefault(require("node-cache"));
|
|
9
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
10
10
|
const WAProto_1 = require("../../WAProto");
|
|
11
11
|
const Defaults_1 = require("../Defaults");
|
|
12
12
|
const Types_1 = require("../Types");
|
|
@@ -16,9 +16,34 @@ const WABinary_1 = require("../WABinary");
|
|
|
16
16
|
const groups_1 = require("./groups");
|
|
17
17
|
const messages_send_1 = require("./messages-send");
|
|
18
18
|
const makeMessagesRecvSocket = (config) => {
|
|
19
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
logger,
|
|
21
|
+
retryRequestDelayMs,
|
|
22
|
+
maxMsgRetryCount,
|
|
23
|
+
getMessage,
|
|
24
|
+
shouldIgnoreJid
|
|
25
|
+
} = config;
|
|
20
26
|
const sock = (0, messages_send_1.makeMessagesSocket)(config);
|
|
21
|
-
const {
|
|
27
|
+
const {
|
|
28
|
+
ev,
|
|
29
|
+
authState,
|
|
30
|
+
ws,
|
|
31
|
+
processingMutex,
|
|
32
|
+
signalRepository,
|
|
33
|
+
query,
|
|
34
|
+
upsertMessage,
|
|
35
|
+
resyncAppState,
|
|
36
|
+
groupMetadata,
|
|
37
|
+
onUnexpectedError,
|
|
38
|
+
assertSessions,
|
|
39
|
+
sendNode,
|
|
40
|
+
relayMessage,
|
|
41
|
+
sendReceipt,
|
|
42
|
+
uploadPreKeys,
|
|
43
|
+
createParticipantNodes,
|
|
44
|
+
getUSyncDevices,
|
|
45
|
+
sendPeerDataOperationMessage
|
|
46
|
+
} = sock;
|
|
22
47
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
|
23
48
|
const retryMutex = (0, make_mutex_1.makeMutex)();
|
|
24
49
|
const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
|
|
@@ -42,7 +67,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
42
67
|
to: attrs.from,
|
|
43
68
|
class: tag
|
|
44
69
|
}
|
|
45
|
-
}
|
|
70
|
+
}
|
|
46
71
|
if (!!errorCode) {
|
|
47
72
|
stanza.attrs.error = errorCode.toString();
|
|
48
73
|
}
|
|
@@ -58,32 +83,69 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
58
83
|
if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
|
|
59
84
|
stanza.attrs.from = authState.creds.me.id;
|
|
60
85
|
}
|
|
61
|
-
logger.debug({
|
|
86
|
+
logger.debug({
|
|
87
|
+
recv: {
|
|
88
|
+
tag,
|
|
89
|
+
attrs
|
|
90
|
+
},
|
|
91
|
+
sent: stanza.attrs }, 'sent ack');
|
|
62
92
|
await sendNode(stanza);
|
|
63
93
|
};
|
|
64
94
|
const offerCall = async (toJid, isVideo = false) => {
|
|
65
95
|
const callId = (0, crypto_1.randomBytes)(16).toString('hex').toUpperCase().substring(0, 64);
|
|
66
96
|
const offerContent = [];
|
|
67
|
-
offerContent.push({
|
|
68
|
-
|
|
97
|
+
offerContent.push({
|
|
98
|
+
tag: 'audio',
|
|
99
|
+
attrs: {
|
|
100
|
+
enc: 'opus',
|
|
101
|
+
rate: '16000'
|
|
102
|
+
}, content: undefined
|
|
103
|
+
});
|
|
104
|
+
offerContent.push({
|
|
105
|
+
tag: 'audio',
|
|
106
|
+
attrs: {
|
|
107
|
+
enc: 'opus',
|
|
108
|
+
rate: '8000'
|
|
109
|
+
}, content: undefined
|
|
110
|
+
});
|
|
69
111
|
if (isVideo) {
|
|
70
112
|
offerContent.push({
|
|
71
113
|
tag: 'video',
|
|
72
|
-
attrs: {
|
|
73
|
-
|
|
114
|
+
attrs: {
|
|
115
|
+
orientation: '0',
|
|
116
|
+
'screen_width': '1920',
|
|
117
|
+
'screen_height': '1080',
|
|
118
|
+
'device_orientation': '0',
|
|
119
|
+
enc: 'vp8',
|
|
120
|
+
dec: 'vp8',
|
|
121
|
+
}
|
|
74
122
|
});
|
|
75
123
|
}
|
|
76
|
-
offerContent.push({
|
|
77
|
-
|
|
78
|
-
|
|
124
|
+
offerContent.push({
|
|
125
|
+
tag: 'net',
|
|
126
|
+
attrs: {
|
|
127
|
+
medium: '3'
|
|
128
|
+
}, content: undefined
|
|
129
|
+
});
|
|
130
|
+
offerContent.push({
|
|
131
|
+
tag: 'capability',
|
|
132
|
+
attrs: {
|
|
133
|
+
ver: '1'
|
|
134
|
+
}, content: new Uint8Array([1, 4, 255, 131, 207, 4]) });
|
|
135
|
+
offerContent.push({
|
|
136
|
+
tag: 'encopt',
|
|
137
|
+
attrs: {
|
|
138
|
+
keygen: '2'
|
|
139
|
+
}, content: undefined
|
|
140
|
+
})
|
|
79
141
|
const encKey = (0, crypto_1.randomBytes)(32);
|
|
80
142
|
const devices = (await getUSyncDevices([toJid], true, false)).map(({ user, device }) => (0, WABinary_1.jidEncode)(user, 's.whatsapp.net', device));
|
|
81
143
|
await assertSessions(devices, true);
|
|
82
144
|
const { nodes: destinations, shouldIncludeDeviceIdentity } = await createParticipantNodes(devices, {
|
|
83
145
|
call: {
|
|
84
|
-
callKey:
|
|
146
|
+
callKey: encKey
|
|
85
147
|
}
|
|
86
|
-
}
|
|
148
|
+
});
|
|
87
149
|
offerContent.push({ tag: 'destination', attrs: {}, content: destinations });
|
|
88
150
|
if (shouldIncludeDeviceIdentity) {
|
|
89
151
|
offerContent.push({
|
|
@@ -95,7 +157,6 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
95
157
|
const stanza = ({
|
|
96
158
|
tag: 'call',
|
|
97
159
|
attrs: {
|
|
98
|
-
id: await config.generateMessageIDV2() ?? (0, Utils_1.generateMessageIDV2)(),
|
|
99
160
|
to: toJid,
|
|
100
161
|
},
|
|
101
162
|
content: [{
|
|
@@ -109,8 +170,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
109
170
|
});
|
|
110
171
|
await query(stanza);
|
|
111
172
|
return {
|
|
112
|
-
|
|
113
|
-
|
|
173
|
+
callId,
|
|
174
|
+
toJid,
|
|
175
|
+
isVideo,
|
|
114
176
|
};
|
|
115
177
|
};
|
|
116
178
|
const rejectCall = async (callId, callFrom) => {
|
|
@@ -324,10 +386,57 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
324
386
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
|
325
387
|
msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
|
|
326
388
|
break;
|
|
389
|
+
break;
|
|
390
|
+
default:
|
|
391
|
+
// console.log("BAILEYS-DEBUG:", JSON.stringify({ ...child, content: Buffer.isBuffer(child.content) ? child.content.toString() : child.content, participant }, null, 2))
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
const handleNewsletterNotification = (id, node) => {
|
|
395
|
+
const messages = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
396
|
+
const message = (0, WABinary_1.getBinaryNodeChild)(messages, 'message');
|
|
397
|
+
const serverId = message.attrs.server_id;
|
|
398
|
+
const reactionsList = (0, WABinary_1.getBinaryNodeChild)(message, 'reactions');
|
|
399
|
+
const viewsList = (0, WABinary_1.getBinaryNodeChildren)(message, 'views_count');
|
|
400
|
+
if (reactionsList) {
|
|
401
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionsList, 'reaction');
|
|
402
|
+
if (reactions.length === 0) {
|
|
403
|
+
ev.emit('newsletter.reaction', { id, 'server_id': serverId, reaction: { removed: true } });
|
|
404
|
+
}
|
|
405
|
+
reactions.forEach(item => {
|
|
406
|
+
var _a, _b;
|
|
407
|
+
ev.emit('newsletter.reaction', { id, 'server_id': serverId, reaction: { code: (_a = item.attrs) === null || _a === void 0 ? void 0 : _a.code, count: +((_b = item.attrs) === null || _b === void 0 ? void 0 : _b.count) } });
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
if (viewsList.length) {
|
|
411
|
+
viewsList.forEach(item => {
|
|
412
|
+
ev.emit('newsletter.view', { id, 'server_id': serverId, count: +item.attrs.count });
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
const handleMexNewsletterNotification = (id, node) => {
|
|
417
|
+
var _a;
|
|
418
|
+
const operation = node === null || node === void 0 ? void 0 : node.attrs.op_name;
|
|
419
|
+
const content = JSON.parse((_a = node === null || node === void 0 ? void 0 : node.content) === null || _a === void 0 ? void 0 : _a.toString());
|
|
420
|
+
let contentPath;
|
|
421
|
+
if (operation === Types_1.MexOperations.PROMOTE || operation === Types_1.MexOperations.DEMOTE) {
|
|
422
|
+
let action;
|
|
423
|
+
if (operation === Types_1.MexOperations.PROMOTE) {
|
|
424
|
+
action = 'promote';
|
|
425
|
+
contentPath = content.data[Types_1.XWAPaths.PROMOTE];
|
|
426
|
+
}
|
|
427
|
+
if (operation === Types_1.MexOperations.DEMOTE) {
|
|
428
|
+
action = 'demote';
|
|
429
|
+
contentPath = content.data[Types_1.XWAPaths.DEMOTE];
|
|
430
|
+
}
|
|
431
|
+
ev.emit('newsletter-participants.update', { id, author: contentPath.actor.pn, user: contentPath.user.pn, new_role: contentPath.user_new_role, action });
|
|
432
|
+
}
|
|
433
|
+
if (operation === Types_1.MexOperations.UPDATE) {
|
|
434
|
+
contentPath = content.data[Types_1.XWAPaths.METADATA_UPDATE];
|
|
435
|
+
ev.emit('newsletter-settings.update', { id, update: contentPath.thread_metadata.settings });
|
|
327
436
|
}
|
|
328
437
|
};
|
|
329
438
|
const processNotification = async (node) => {
|
|
330
|
-
var _a, _b
|
|
439
|
+
var _a, _b;
|
|
331
440
|
const result = {};
|
|
332
441
|
const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
|
333
442
|
const nodeType = node.attrs.type;
|
|
@@ -346,6 +455,12 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
346
455
|
logger.debug({ jid }, 'got privacy token update');
|
|
347
456
|
}
|
|
348
457
|
break;
|
|
458
|
+
case 'newsletter':
|
|
459
|
+
handleNewsletterNotification(node.attrs.from, child);
|
|
460
|
+
break;
|
|
461
|
+
case 'mex':
|
|
462
|
+
handleMexNewsletterNotification(node.attrs.from, child);
|
|
463
|
+
break;
|
|
349
464
|
case 'w:gp2':
|
|
350
465
|
handleGroupNotification(node.attrs.participant, child, result);
|
|
351
466
|
break;
|
|
@@ -374,7 +489,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
374
489
|
const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
|
|
375
490
|
const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
|
|
376
491
|
ev.emit('contacts.update', [{
|
|
377
|
-
id:
|
|
492
|
+
id: from || ((_b = (_a = (setPicture || delPicture)) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.hash) || '',
|
|
378
493
|
imgUrl: setPicture ? 'changed' : 'removed'
|
|
379
494
|
}]);
|
|
380
495
|
if ((0, WABinary_1.isJidGroup)(from)) {
|
|
@@ -502,6 +617,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
502
617
|
};
|
|
503
618
|
const sendMessagesAgain = async (key, ids, retryNode) => {
|
|
504
619
|
var _a;
|
|
620
|
+
// todo: implement a cache to store the last 256 sent messages (copy whatsmeow)
|
|
505
621
|
const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
|
|
506
622
|
const remoteJid = key.remoteJid;
|
|
507
623
|
const participant = key.participant || remoteJid;
|
|
@@ -540,7 +656,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
540
656
|
const isLid = attrs.from.includes('lid');
|
|
541
657
|
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);
|
|
542
658
|
const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
|
|
543
|
-
const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe);
|
|
659
|
+
const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
|
|
544
660
|
const key = {
|
|
545
661
|
remoteJid,
|
|
546
662
|
id: '',
|
|
@@ -565,7 +681,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
565
681
|
(
|
|
566
682
|
// basically, we only want to know when a message from us has been delivered to/read by the other person
|
|
567
683
|
// or another device of ours has read some messages
|
|
568
|
-
status >= WAProto_1.proto.WebMessageInfo.Status.
|
|
684
|
+
status >= WAProto_1.proto.WebMessageInfo.Status.SERVER_ACK ||
|
|
569
685
|
!isNodeFromMe)) {
|
|
570
686
|
if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
|
|
571
687
|
if (attrs.participant) {
|
|
@@ -687,7 +803,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
687
803
|
try {
|
|
688
804
|
await Promise.all([
|
|
689
805
|
processingMutex.mutex(async () => {
|
|
690
|
-
var _a;
|
|
806
|
+
var _a, _b, _c, _d, _e, _f;
|
|
691
807
|
await decrypt();
|
|
692
808
|
// message failed to decrypt
|
|
693
809
|
if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
|
@@ -713,6 +829,20 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
713
829
|
else {
|
|
714
830
|
// no type in the receipt => message delivered
|
|
715
831
|
let type = undefined;
|
|
832
|
+
if ((_b = msg.key.participant) === null || _b === void 0 ? void 0 : _b.endsWith('@lid')) {
|
|
833
|
+
msg.key.participant = node.attrs.participant_pn || authState.creds.me.id;
|
|
834
|
+
}
|
|
835
|
+
if ((0, WABinary_1.isJidGroup)(msg.key.remoteJid) && ((_f = (_e = (_d = (_c = msg.message) === null || _c === void 0 ? void 0 : _c.extendedTextMessage) === null || _d === void 0 ? void 0 : _d.contextInfo) === null || _e === void 0 ? void 0 : _e.participant) === null || _f === void 0 ? void 0 : _f.endsWith('@lid'))) {
|
|
836
|
+
if (msg.message.extendedTextMessage.contextInfo) {
|
|
837
|
+
const metadata = await groupMetadata(msg.key.remoteJid);
|
|
838
|
+
const sender = msg.message.extendedTextMessage.contextInfo.participant;
|
|
839
|
+
const found = metadata.participants.find(p => p.id === sender);
|
|
840
|
+
msg.message.extendedTextMessage.contextInfo.participant = (found === null || found === void 0 ? void 0 : found.jid) || sender;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (!(0, WABinary_1.isJidGroup)(msg.key.remoteJid) && (0, WABinary_1.isLidUser)(msg.key.remoteJid)) {
|
|
844
|
+
msg.key.remoteJid = node.attrs.sender_pn || node.attrs.peer_recipient_pn;
|
|
845
|
+
}
|
|
716
846
|
let participant = msg.key.participant;
|
|
717
847
|
if (category === 'peer') { // special peer message
|
|
718
848
|
type = 'peer_msg';
|
|
@@ -827,20 +957,28 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
827
957
|
await sendMessageAck(node);
|
|
828
958
|
};
|
|
829
959
|
const handleBadAck = async ({ attrs }) => {
|
|
830
|
-
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
|
|
831
|
-
//
|
|
832
|
-
//
|
|
833
|
-
//
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
960
|
+
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id, 'server_id': attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
|
|
961
|
+
// current hypothesis is that if pash is sent in the ack
|
|
962
|
+
// it means -- the message hasn't reached all devices yet
|
|
963
|
+
// we'll retry sending the message here
|
|
964
|
+
if (attrs.phash) {
|
|
965
|
+
logger.info({ attrs }, 'received phash in ack, resending message...');
|
|
966
|
+
const cacheKey = `${key.remoteJid}:${key.id}`;
|
|
967
|
+
if ((msgRetryCache.get(cacheKey) || 0) >= maxMsgRetryCount) {
|
|
968
|
+
logger.warn({ attrs }, 'reached max retry count, not sending message again');
|
|
969
|
+
msgRetryCache.del(cacheKey);
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
const retryCount = msgRetryCache.get(cacheKey) || 0;
|
|
973
|
+
const msg = await getMessage(key);
|
|
974
|
+
if (msg) {
|
|
975
|
+
await relayMessage(key.remoteJid, msg, { messageId: key.id, useUserDevicesCache: false });
|
|
976
|
+
msgRetryCache.set(cacheKey, retryCount + 1);
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
logger.warn({ attrs }, 'could not send message again, as it was not found');
|
|
980
|
+
}
|
|
981
|
+
}
|
|
844
982
|
// error in acknowledgement,
|
|
845
983
|
// device could not display the message
|
|
846
984
|
if (attrs.error) {
|
|
@@ -963,8 +1101,8 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
963
1101
|
...sock,
|
|
964
1102
|
sendMessageAck,
|
|
965
1103
|
sendRetryRequest,
|
|
966
|
-
offerCall,
|
|
967
1104
|
rejectCall,
|
|
1105
|
+
offerCall,
|
|
968
1106
|
fetchMessageHistory,
|
|
969
1107
|
requestPlaceholderResend,
|
|
970
1108
|
};
|
|
@@ -1,35 +1,29 @@
|
|
|
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>;
|
|
10
|
-
relayMessage: (jid: string, message: proto.IMessage, { messageId
|
|
9
|
+
relayMessage: (jid: string, message: proto.IMessage, { messageId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<proto.WebMessageInfo>;
|
|
11
10
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
|
12
11
|
sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
|
|
13
|
-
getButtonArgs: (message: proto.IMessage) => BinaryNode['attrs'];
|
|
14
12
|
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
|
15
13
|
refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
|
|
16
14
|
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
|
|
17
|
-
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
18
15
|
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
|
|
19
16
|
nodes: BinaryNode[];
|
|
20
17
|
shouldIncludeDeviceIdentity: boolean;
|
|
21
18
|
}>;
|
|
22
|
-
profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | null | undefined>;
|
|
23
19
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
|
24
20
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
25
21
|
[_: string]: string;
|
|
26
22
|
}>;
|
|
23
|
+
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
24
|
+
rahmi: any;
|
|
27
25
|
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
26
|
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
27
|
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
34
28
|
duration: string;
|
|
35
29
|
}>;
|
|
@@ -43,7 +37,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
43
37
|
newsletterUnmute: (jid: string) => Promise<void>;
|
|
44
38
|
newsletterMute: (jid: string) => Promise<void>;
|
|
45
39
|
newsletterAction: (jid: string, type: "mute" | "follow" | "unfollow" | "unmute") => Promise<void>;
|
|
46
|
-
newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
40
|
+
newsletterCreate: (name: string, description: string, reaction_codes: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
47
41
|
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
|
48
42
|
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
49
43
|
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
|
@@ -52,7 +46,6 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
52
46
|
newsletterReactMessage: (jid: string, serverId: string, code?: string | undefined) => Promise<void>;
|
|
53
47
|
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
54
48
|
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
49
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
57
50
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
58
51
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -82,22 +75,24 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
82
75
|
groupFetchAllParticipating: () => Promise<{
|
|
83
76
|
[_: string]: import("../Types").GroupMetadata;
|
|
84
77
|
}>;
|
|
85
|
-
interactiveQuery: (userNodes: BinaryNode[], queryNode: BinaryNode) => Promise<BinaryNode[]>;
|
|
86
78
|
processingMutex: {
|
|
87
79
|
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
|
88
80
|
};
|
|
89
81
|
upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
90
82
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
91
|
-
fetchUserLid: (jid: string) => Promise<string | undefined>;
|
|
92
83
|
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
|
|
93
84
|
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
|
|
85
|
+
profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
|
|
94
86
|
onWhatsApp: (...jids: string[]) => Promise<{
|
|
95
87
|
jid: string;
|
|
96
88
|
exists: unknown;
|
|
89
|
+
lid: unknown;
|
|
97
90
|
}[] | undefined>;
|
|
98
91
|
fetchBlocklist: () => Promise<string[]>;
|
|
99
|
-
fetchStatus: (
|
|
100
|
-
|
|
92
|
+
fetchStatus: (jid: string) => Promise<{
|
|
93
|
+
status: string | undefined;
|
|
94
|
+
setAt: Date;
|
|
95
|
+
} | undefined>;
|
|
101
96
|
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
|
102
97
|
removeProfilePicture: (jid: string) => Promise<void>;
|
|
103
98
|
updateProfileStatus: (status: string) => Promise<void>;
|
|
@@ -122,7 +117,6 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
122
117
|
id: string;
|
|
123
118
|
fromMe?: boolean | undefined;
|
|
124
119
|
}[], star: boolean) => Promise<void>;
|
|
125
|
-
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
|
126
120
|
type: "md";
|
|
127
121
|
ws: any;
|
|
128
122
|
ev: import("../Types").BaileysEventEmitter & {
|
|
@@ -149,7 +143,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
149
143
|
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
|
150
144
|
uploadPreKeys: (count?: number) => Promise<void>;
|
|
151
145
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
152
|
-
requestPairingCode: (phoneNumber: string
|
|
146
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
153
147
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
154
148
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
155
149
|
};
|