@genuxofficial/baileys 1.0.0 → 2.0.0
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/LICENSE +1 -1
- package/README.md +5 -1
- package/WAProto/index.d.ts +19244 -2787
- package/WAProto/index.js +138202 -74217
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +3 -5
- package/lib/Defaults/index.js +7 -6
- package/lib/Signal/libsignal.js +18 -9
- package/lib/Socket/Client/types.d.ts +0 -2
- package/lib/Socket/Client/websocket.js +1 -1
- package/lib/Socket/business.d.ts +65 -37
- package/lib/Socket/chats.d.ts +22 -18
- package/lib/Socket/chats.js +110 -6
- package/lib/Socket/groups.d.ts +30 -26
- package/lib/Socket/groups.js +20 -6
- package/lib/Socket/index.d.ts +66 -38
- package/lib/Socket/messages-recv.d.ts +63 -33
- package/lib/Socket/messages-recv.js +174 -27
- package/lib/Socket/messages-send.d.ts +55 -29
- package/lib/Socket/messages-send.js +190 -26
- package/lib/Socket/newsletter.d.ts +140 -0
- package/lib/Socket/newsletter.js +252 -0
- package/lib/Socket/socket.d.ts +8 -10
- package/lib/Socket/socket.js +26 -13
- package/lib/Socket/usync.d.ts +10 -12
- package/lib/Socket/usync.js +10 -15
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.d.ts +1 -1
- package/lib/Store/make-in-memory-store.js +14 -5
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +0 -2
- package/lib/Types/Chat.d.ts +7 -0
- package/lib/Types/Contact.d.ts +5 -0
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/GroupMetadata.d.ts +7 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +129 -16
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Socket.d.ts +8 -5
- package/lib/Types/index.d.ts +1 -0
- package/lib/Types/index.js +2 -1
- package/lib/Utils/auth-utils.d.ts +1 -1
- package/lib/Utils/auth-utils.js +6 -7
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +8 -10
- package/lib/Utils/chat-utils.js +11 -0
- package/lib/Utils/crypto.d.ts +14 -16
- package/lib/Utils/crypto.js +40 -26
- package/lib/Utils/decode-wa-message.d.ts +5 -3
- package/lib/Utils/decode-wa-message.js +171 -29
- package/lib/Utils/event-buffer.js +1 -3
- package/lib/Utils/generics.d.ts +35 -9
- package/lib/Utils/generics.js +93 -27
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/link-preview.d.ts +1 -1
- package/lib/Utils/link-preview.js +17 -7
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +35 -16
- package/lib/Utils/messages-media.js +168 -43
- package/lib/Utils/messages.d.ts +6 -9
- package/lib/Utils/messages.js +297 -37
- package/lib/Utils/noise-handler.d.ts +5 -7
- package/lib/Utils/process-message.js +2 -3
- package/lib/Utils/use-multi-file-auth-state.js +44 -13
- package/lib/Utils/validate-connection.d.ts +2 -2
- package/lib/Utils/validate-connection.js +1 -3
- package/lib/WABinary/decode.d.ts +2 -4
- package/lib/WABinary/decode.js +20 -9
- package/lib/WABinary/encode.d.ts +1 -3
- package/lib/WABinary/encode.js +30 -12
- package/lib/WABinary/generic-utils.d.ts +1 -3
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WABinary/jid-utils.d.ts +9 -4
- package/lib/WABinary/jid-utils.js +25 -4
- package/lib/WAM/BinaryInfo.d.ts +2 -12
- package/lib/WAM/encode.d.ts +1 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/USyncQuery.d.ts +2 -0
- package/lib/WAUSync/USyncQuery.js +27 -13
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/WAUSync/USyncUser.js +4 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/package.json +59 -57
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -3344
@@ -4,9 +4,9 @@ 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");
|
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,25 +16,30 @@ 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 { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
|
19
|
+
const { logger, retryRequestDelayMs, maxMsgRetryCount, ignoreMsgLoading, getMessage, shouldIgnoreJid } = config;
|
20
20
|
const sock = (0, messages_send_1.makeMessagesSocket)(config);
|
21
|
-
const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, } = sock;
|
21
|
+
const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, createParticipantNodes, getUSyncDevices, sendPeerDataOperationMessage, } = sock;
|
22
22
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
23
23
|
const retryMutex = (0, make_mutex_1.makeMutex)();
|
24
24
|
const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
|
25
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
25
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
26
26
|
useClones: false
|
27
27
|
});
|
28
28
|
const callOfferCache = config.callOfferCache || new node_cache_1.default({
|
29
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER,
|
29
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins
|
30
30
|
useClones: false
|
31
31
|
});
|
32
32
|
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
33
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
|
33
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
34
34
|
useClones: false
|
35
35
|
});
|
36
36
|
let sendActiveReceipts = false;
|
37
37
|
const sendMessageAck = async ({ tag, attrs, content }, errorCode) => {
|
38
|
+
// If ws not connected - logs it and return
|
39
|
+
if (!ws.isOpen) {
|
40
|
+
logger.warn({ attrs: attrs }, 'Client not connected, cannot send ack');
|
41
|
+
return;
|
42
|
+
}
|
38
43
|
const stanza = {
|
39
44
|
tag: 'ack',
|
40
45
|
attrs: {
|
@@ -61,6 +66,67 @@ const makeMessagesRecvSocket = (config) => {
|
|
61
66
|
logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
|
62
67
|
await sendNode(stanza);
|
63
68
|
};
|
69
|
+
const offerCall = async (toJid, isVideo = false) => {
|
70
|
+
const ToJidm = `${toJid}`;
|
71
|
+
const callId = (0, crypto_1.randomBytes)(16).toString('hex').toUpperCase().substring(0, 64);
|
72
|
+
const offerContent = [];
|
73
|
+
offerContent.push({ tag: 'audio', attrs: { enc: 'opus', rate: '16000' }, content: undefined });
|
74
|
+
offerContent.push({ tag: 'audio', attrs: { enc: 'opus', rate: '8000' }, content: undefined });
|
75
|
+
if (isVideo) {
|
76
|
+
offerContent.push({
|
77
|
+
tag: 'video',
|
78
|
+
attrs: {
|
79
|
+
orientation: '0',
|
80
|
+
'screen_width': '1920',
|
81
|
+
'screen_height': '1080',
|
82
|
+
'device_orientation': '0',
|
83
|
+
enc: 'vp8',
|
84
|
+
dec: 'vp8',
|
85
|
+
}
|
86
|
+
});
|
87
|
+
}
|
88
|
+
offerContent.push({ tag: 'net', attrs: { medium: '3' }, content: undefined });
|
89
|
+
offerContent.push({ tag: 'capability', attrs: { ver: '1' }, content: new Uint8Array([1, 4, 255, 131, 207, 4]) });
|
90
|
+
offerContent.push({ tag: 'encopt', attrs: { keygen: '2' }, content: undefined });
|
91
|
+
const encKey = (0, crypto_1.randomBytes)(32);
|
92
|
+
const usrr = toJid.split('@')[0];
|
93
|
+
const srvr = toJid.split('@')[1];
|
94
|
+
const devices = (await getUSyncDevices([toJid], true, false)).map(({ user, device }) => toJid);
|
95
|
+
await assertSessions(devices, true);
|
96
|
+
const { nodes: destinations, shouldIncludeDeviceIdentity } = await createParticipantNodes(devices, {
|
97
|
+
call: {
|
98
|
+
callKey: encKey
|
99
|
+
}
|
100
|
+
});
|
101
|
+
offerContent.push({ tag: 'destination', attrs: {}, content: destinations });
|
102
|
+
if (shouldIncludeDeviceIdentity) {
|
103
|
+
offerContent.push({
|
104
|
+
tag: 'device-identity',
|
105
|
+
attrs: {},
|
106
|
+
content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
|
107
|
+
});
|
108
|
+
}
|
109
|
+
const stanza = ({
|
110
|
+
tag: 'call',
|
111
|
+
attrs: {
|
112
|
+
to: toJid,
|
113
|
+
},
|
114
|
+
content: [{
|
115
|
+
tag: 'offer',
|
116
|
+
attrs: {
|
117
|
+
'call-id': callId,
|
118
|
+
'call-creator': authState.creds.me.id,
|
119
|
+
},
|
120
|
+
content: offerContent,
|
121
|
+
}],
|
122
|
+
});
|
123
|
+
await query(stanza);
|
124
|
+
return {
|
125
|
+
callId,
|
126
|
+
toJid,
|
127
|
+
isVideo,
|
128
|
+
};
|
129
|
+
};
|
64
130
|
const rejectCall = async (callId, callFrom) => {
|
65
131
|
const stanza = ({
|
66
132
|
tag: 'call',
|
@@ -126,7 +192,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
126
192
|
]
|
127
193
|
};
|
128
194
|
if (node.attrs.recipient) {
|
129
|
-
receipt.attrs.recipient = node.attrs.recipient;
|
195
|
+
receipt.attrs.recipient = (0, WABinary_1.getBotJid)(node.attrs.recipient);
|
130
196
|
}
|
131
197
|
if (node.attrs.participant) {
|
132
198
|
receipt.attrs.participant = node.attrs.participant;
|
@@ -272,10 +338,57 @@ const makeMessagesRecvSocket = (config) => {
|
|
272
338
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
|
273
339
|
msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
|
274
340
|
break;
|
341
|
+
break;
|
342
|
+
default:
|
343
|
+
// console.log("BAILEYS-DEBUG:", JSON.stringify({ ...child, content: Buffer.isBuffer(child.content) ? child.content.toString() : child.content, participant }, null, 2))
|
344
|
+
}
|
345
|
+
};
|
346
|
+
const handleNewsletterNotification = (id, node) => {
|
347
|
+
const messages = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
348
|
+
const message = (0, WABinary_1.getBinaryNodeChild)(messages, 'message');
|
349
|
+
const serverId = message.attrs.server_id;
|
350
|
+
const reactionsList = (0, WABinary_1.getBinaryNodeChild)(message, 'reactions');
|
351
|
+
const viewsList = (0, WABinary_1.getBinaryNodeChildren)(message, 'views_count');
|
352
|
+
if (reactionsList) {
|
353
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionsList, 'reaction');
|
354
|
+
if (reactions.length === 0) {
|
355
|
+
ev.emit('newsletter.reaction', { id, 'server_id': serverId, reaction: { removed: true } });
|
356
|
+
}
|
357
|
+
reactions.forEach(item => {
|
358
|
+
var _a, _b;
|
359
|
+
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) } });
|
360
|
+
});
|
361
|
+
}
|
362
|
+
if (viewsList.length) {
|
363
|
+
viewsList.forEach(item => {
|
364
|
+
ev.emit('newsletter.view', { id, 'server_id': serverId, count: +item.attrs.count });
|
365
|
+
});
|
366
|
+
}
|
367
|
+
};
|
368
|
+
const handleMexNewsletterNotification = (id, node) => {
|
369
|
+
var _a;
|
370
|
+
const operation = node === null || node === void 0 ? void 0 : node.attrs.op_name;
|
371
|
+
const content = JSON.parse((_a = node === null || node === void 0 ? void 0 : node.content) === null || _a === void 0 ? void 0 : _a.toString());
|
372
|
+
let contentPath;
|
373
|
+
if (operation === Types_1.MexOperations.PROMOTE || operation === Types_1.MexOperations.DEMOTE) {
|
374
|
+
let action;
|
375
|
+
if (operation === Types_1.MexOperations.PROMOTE) {
|
376
|
+
action = 'promote';
|
377
|
+
contentPath = content.data[Types_1.XWAPaths.PROMOTE];
|
378
|
+
}
|
379
|
+
if (operation === Types_1.MexOperations.DEMOTE) {
|
380
|
+
action = 'demote';
|
381
|
+
contentPath = content.data[Types_1.XWAPaths.DEMOTE];
|
382
|
+
}
|
383
|
+
ev.emit('newsletter-participants.update', { id, author: contentPath.actor.pn, user: contentPath.user.pn, new_role: contentPath.user_new_role, action });
|
384
|
+
}
|
385
|
+
if (operation === Types_1.MexOperations.UPDATE) {
|
386
|
+
contentPath = content.data[Types_1.XWAPaths.METADATA_UPDATE];
|
387
|
+
ev.emit('newsletter-settings.update', { id, update: contentPath.thread_metadata.settings });
|
275
388
|
}
|
276
389
|
};
|
277
390
|
const processNotification = async (node) => {
|
278
|
-
var _a, _b
|
391
|
+
var _a, _b;
|
279
392
|
const result = {};
|
280
393
|
const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
|
281
394
|
const nodeType = node.attrs.type;
|
@@ -294,6 +407,12 @@ const makeMessagesRecvSocket = (config) => {
|
|
294
407
|
logger.debug({ jid }, 'got privacy token update');
|
295
408
|
}
|
296
409
|
break;
|
410
|
+
case 'newsletter':
|
411
|
+
handleNewsletterNotification(node.attrs.from, child);
|
412
|
+
break;
|
413
|
+
case 'mex':
|
414
|
+
handleMexNewsletterNotification(node.attrs.from, child);
|
415
|
+
break;
|
297
416
|
case 'w:gp2':
|
298
417
|
handleGroupNotification(node.attrs.participant, child, result);
|
299
418
|
break;
|
@@ -304,6 +423,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
304
423
|
case 'encrypt':
|
305
424
|
await handleEncryptNotification(node);
|
306
425
|
break;
|
426
|
+
case 'newsletter':
|
427
|
+
// TO DO
|
428
|
+
break;
|
307
429
|
case 'devices':
|
308
430
|
const devices = (0, WABinary_1.getBinaryNodeChildren)(child, 'device');
|
309
431
|
if ((0, WABinary_1.areJidsSameUser)(child.attrs.jid, authState.creds.me.id)) {
|
@@ -322,7 +444,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
322
444
|
const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
|
323
445
|
const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
|
324
446
|
ev.emit('contacts.update', [{
|
325
|
-
id:
|
447
|
+
id: from || ((_b = (_a = (setPicture || delPicture)) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.hash) || '',
|
326
448
|
imgUrl: setPicture ? 'changed' : 'removed'
|
327
449
|
}]);
|
328
450
|
if ((0, WABinary_1.isJidGroup)(from)) {
|
@@ -450,6 +572,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
450
572
|
};
|
451
573
|
const sendMessagesAgain = async (key, ids, retryNode) => {
|
452
574
|
var _a;
|
575
|
+
// todo: implement a cache to store the last 256 sent messages (copy whatsmeow)
|
453
576
|
const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
|
454
577
|
const remoteJid = key.remoteJid;
|
455
578
|
const participant = key.participant || remoteJid;
|
@@ -488,7 +611,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
488
611
|
const isLid = attrs.from.includes('lid');
|
489
612
|
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);
|
490
613
|
const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
|
491
|
-
const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe);
|
614
|
+
const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
|
492
615
|
const key = {
|
493
616
|
remoteJid,
|
494
617
|
id: '',
|
@@ -598,13 +721,25 @@ const makeMessagesRecvSocket = (config) => {
|
|
598
721
|
};
|
599
722
|
const handleMessage = async (node) => {
|
600
723
|
var _a, _b, _c;
|
724
|
+
if (ignoreMsgLoading && node.attrs.offline) {
|
725
|
+
logger.debug({ key: node.attrs.key }, 'ignored offline message');
|
726
|
+
await sendMessageAck(node);
|
727
|
+
return;
|
728
|
+
}
|
601
729
|
if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
|
602
730
|
logger.debug({ key: node.attrs.key }, 'ignored message');
|
603
731
|
await sendMessageAck(node);
|
604
732
|
return;
|
605
733
|
}
|
734
|
+
const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
|
735
|
+
// TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
|
736
|
+
if (encNode && encNode.attrs.type === 'msmsg') {
|
737
|
+
logger.debug({ key: node.attrs.key }, 'ignored msmsg');
|
738
|
+
await sendMessageAck(node);
|
739
|
+
return;
|
740
|
+
}
|
606
741
|
let response;
|
607
|
-
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !
|
742
|
+
if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !encNode) {
|
608
743
|
await sendMessageAck(node);
|
609
744
|
const { key } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
|
610
745
|
response = await requestPlaceholderResend(key);
|
@@ -618,7 +753,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
618
753
|
placeholderResendCache.del(node.attrs.id);
|
619
754
|
}
|
620
755
|
}
|
621
|
-
const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
|
756
|
+
const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger, getMessage);
|
622
757
|
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) {
|
623
758
|
msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
|
624
759
|
}
|
@@ -628,7 +763,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
628
763
|
try {
|
629
764
|
await Promise.all([
|
630
765
|
processingMutex.mutex(async () => {
|
631
|
-
var _a;
|
766
|
+
var _a, _b, _c;
|
632
767
|
await decrypt();
|
633
768
|
// message failed to decrypt
|
634
769
|
if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
|
@@ -676,6 +811,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
676
811
|
await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
|
677
812
|
}
|
678
813
|
}
|
814
|
+
if (((_b = node.attrs) === null || _b === void 0 ? void 0 : _b.addressing_mode) === 'lid' && ((_c = node.attrs) === null || _c === void 0 ? void 0 : _c.participant_pn)) {
|
815
|
+
msg.key.participant = (0, WABinary_1.jidNormalizedUser)(node.attrs.participant_pn);
|
816
|
+
}
|
679
817
|
(0, Utils_1.cleanMessage)(msg, authState.creds.me.id);
|
680
818
|
await sendMessageAck(node);
|
681
819
|
await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
|
@@ -768,20 +906,28 @@ const makeMessagesRecvSocket = (config) => {
|
|
768
906
|
await sendMessageAck(node);
|
769
907
|
};
|
770
908
|
const handleBadAck = async ({ attrs }) => {
|
771
|
-
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
|
772
|
-
//
|
773
|
-
//
|
774
|
-
//
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
909
|
+
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id, 'server_id': attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
|
910
|
+
// current hypothesis is that if pash is sent in the ack
|
911
|
+
// it means -- the message hasn't reached all devices yet
|
912
|
+
// we'll retry sending the message here
|
913
|
+
if (attrs.phash) {
|
914
|
+
logger.info({ attrs }, 'received phash in ack, resending message...');
|
915
|
+
const cacheKey = `${key.remoteJid}:${key.id}`;
|
916
|
+
if ((msgRetryCache.get(cacheKey) || 0) >= maxMsgRetryCount) {
|
917
|
+
logger.warn({ attrs }, 'reached max retry count, not sending message again');
|
918
|
+
msgRetryCache.del(cacheKey);
|
919
|
+
return;
|
920
|
+
}
|
921
|
+
const retryCount = msgRetryCache.get(cacheKey) || 0;
|
922
|
+
const msg = await getMessage(key);
|
923
|
+
if (msg) {
|
924
|
+
await relayMessage(key.remoteJid, msg, { messageId: key.id, useUserDevicesCache: false });
|
925
|
+
msgRetryCache.set(cacheKey, retryCount + 1);
|
926
|
+
}
|
927
|
+
else {
|
928
|
+
logger.warn({ attrs }, 'could not send message again, as it was not found');
|
929
|
+
}
|
930
|
+
}
|
785
931
|
// error in acknowledgement,
|
786
932
|
// device could not display the message
|
787
933
|
if (attrs.error) {
|
@@ -905,6 +1051,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
905
1051
|
sendMessageAck,
|
906
1052
|
sendRetryRequest,
|
907
1053
|
rejectCall,
|
1054
|
+
offerCall,
|
908
1055
|
fetchMessageHistory,
|
909
1056
|
requestPlaceholderResend,
|
910
1057
|
};
|
@@ -1,30 +1,50 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
1
|
import { Boom } from '@hapi/boom';
|
4
2
|
import { proto } from '../../WAProto';
|
5
3
|
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
|
6
4
|
import { BinaryNode, JidWithDevice } from '../WABinary';
|
7
5
|
import { USyncQuery } from '../WAUSync';
|
8
6
|
export declare const makeMessagesSocket: (config: SocketConfig) => {
|
9
|
-
getPrivacyTokens: (jids: string[]) => Promise<
|
7
|
+
getPrivacyTokens: (jids: string[]) => Promise<any>;
|
10
8
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
11
9
|
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
12
10
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
13
11
|
sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
|
12
|
+
getButtonArgs: (message: proto.IMessage) => BinaryNode["attrs"];
|
14
13
|
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
15
14
|
refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
|
16
15
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
17
16
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
18
17
|
[_: string]: string;
|
19
18
|
}>;
|
20
|
-
|
21
|
-
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode[
|
19
|
+
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
|
20
|
+
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode["attrs"]) => Promise<{
|
22
21
|
nodes: BinaryNode[];
|
23
22
|
shouldIncludeDeviceIdentity: boolean;
|
24
23
|
}>;
|
25
|
-
|
24
|
+
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
26
25
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
27
26
|
sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
27
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
28
|
+
duration: string;
|
29
|
+
}>;
|
30
|
+
newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
|
31
|
+
newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
32
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<void>;
|
33
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
34
|
+
newsletterRemovePicture: (jid: string) => Promise<void>;
|
35
|
+
newsletterUnfollow: (jid: string) => Promise<void>;
|
36
|
+
newsletterFollow: (jid: string) => Promise<void>;
|
37
|
+
newsletterUnmute: (jid: string) => Promise<void>;
|
38
|
+
newsletterMute: (jid: string) => Promise<void>;
|
39
|
+
newsletterCreate: (name: string, description?: string, picture?: import("../Types").WAMediaUpload) => Promise<import("../Types").NewsletterMetadata>;
|
40
|
+
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole) => Promise<import("../Types").NewsletterMetadata>;
|
41
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
42
|
+
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
43
|
+
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
44
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
45
|
+
newsletterReactMessage: (jid: string, server_id: string, code?: string) => Promise<void>;
|
46
|
+
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
47
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
28
48
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
29
49
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
30
50
|
groupLeave: (id: string) => Promise<void>;
|
@@ -32,7 +52,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
32
52
|
groupRequestParticipantsList: (jid: string) => Promise<{
|
33
53
|
[key: string]: string;
|
34
54
|
}[]>;
|
35
|
-
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "
|
55
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
|
36
56
|
status: string;
|
37
57
|
jid: string;
|
38
58
|
}[]>;
|
@@ -41,36 +61,40 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
41
61
|
jid: string;
|
42
62
|
content: BinaryNode;
|
43
63
|
}[]>;
|
44
|
-
groupUpdateDescription: (jid: string, description?: string
|
64
|
+
groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
45
65
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
46
66
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
47
67
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
48
68
|
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
49
|
-
groupAcceptInviteV4: (key: string |
|
69
|
+
groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
|
50
70
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
51
71
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
52
|
-
groupSettingUpdate: (jid: string, setting: "announcement" | "
|
53
|
-
groupMemberAddMode: (jid: string, mode: "
|
72
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
73
|
+
groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
|
54
74
|
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
55
75
|
groupFetchAllParticipating: () => Promise<{
|
56
76
|
[_: string]: import("../Types").GroupMetadata;
|
57
77
|
}>;
|
78
|
+
getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
|
58
79
|
processingMutex: {
|
59
|
-
mutex<T>(code: () => T |
|
80
|
+
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
60
81
|
};
|
61
82
|
upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
62
83
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
63
|
-
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string
|
64
|
-
presenceSubscribe: (toJid: string, tcToken?: Buffer
|
65
|
-
profilePictureUrl: (jid: string, type?: "
|
84
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
85
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
86
|
+
profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
|
66
87
|
onWhatsApp: (...jids: string[]) => Promise<{
|
67
88
|
jid: string;
|
68
89
|
exists: unknown;
|
90
|
+
lid: unknown;
|
69
91
|
}[] | undefined>;
|
70
92
|
fetchBlocklist: () => Promise<string[]>;
|
71
|
-
fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
72
93
|
fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
94
|
+
fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
73
95
|
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
96
|
+
updateProfilePictureFull: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
97
|
+
updateProfilePictureFull2: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
74
98
|
removeProfilePicture: (jid: string) => Promise<void>;
|
75
99
|
updateProfileStatus: (status: string) => Promise<void>;
|
76
100
|
updateProfileName: (name: string) => Promise<void>;
|
@@ -84,10 +108,12 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
84
108
|
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
85
109
|
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
|
86
110
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
87
|
-
getBusinessProfile: (jid: string) => Promise<
|
111
|
+
getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
|
88
112
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
89
113
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
90
|
-
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?:
|
114
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
115
|
+
addOrEditContact: (jid: string, contact: import("../Types").ContactAction) => Promise<void>;
|
116
|
+
removeContact: (jid: string) => Promise<void>;
|
91
117
|
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
92
118
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
93
119
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
@@ -95,16 +121,16 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
95
121
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
96
122
|
star: (jid: string, messages: {
|
97
123
|
id: string;
|
98
|
-
fromMe?: boolean
|
124
|
+
fromMe?: boolean;
|
99
125
|
}[], star: boolean) => Promise<void>;
|
100
126
|
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
101
127
|
type: "md";
|
102
128
|
ws: import("./Client").WebSocketClient;
|
103
129
|
ev: import("../Types").BaileysEventEmitter & {
|
104
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
130
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
105
131
|
buffer(): void;
|
106
|
-
createBufferedFunction<A extends any[],
|
107
|
-
flush(force?: boolean
|
132
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
133
|
+
flush(force?: boolean): boolean;
|
108
134
|
isBuffering(): boolean;
|
109
135
|
};
|
110
136
|
authState: {
|
@@ -114,17 +140,17 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
114
140
|
signalRepository: import("../Types").SignalRepository;
|
115
141
|
user: import("../Types").Contact | undefined;
|
116
142
|
generateMessageTag: () => string;
|
117
|
-
query: (node: BinaryNode, timeoutMs?: number
|
118
|
-
waitForMessage: <
|
143
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
144
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
119
145
|
waitForSocketOpen: () => Promise<void>;
|
120
146
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
121
147
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
122
|
-
logout: (msg?: string
|
148
|
+
logout: (msg?: string) => Promise<void>;
|
123
149
|
end: (error: Error | undefined) => void;
|
124
|
-
onUnexpectedError: (err: Error | Boom
|
150
|
+
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
125
151
|
uploadPreKeys: (count?: number) => Promise<void>;
|
126
152
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
127
|
-
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
128
|
-
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number
|
129
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
153
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
154
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
155
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
130
156
|
};
|