lordceaser-baileys 3.3.8 → 3.4.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/WAProto/index.js +1 -2
- package/index.js +4 -16
- package/lib/Socket/Client/index.js +0 -1
- package/lib/Socket/Client/types.js +1 -2
- package/lib/Socket/Client/websocket.js +1 -2
- package/lib/Socket/business.js +70 -42
- package/lib/Socket/chats.js +731 -21
- package/lib/Socket/communities.js +1 -1
- package/lib/Socket/groups.js +207 -5
- package/lib/Socket/index.js +28 -3
- package/lib/Socket/messages-recv.js +381 -9
- package/lib/Socket/messages-send.js +2189 -157
- package/lib/Socket/mex.js +1 -2
- package/lib/Socket/newsletter.js +98 -19
- package/lib/Socket/socket.js +64 -17
- package/lib/Utils/crypto.js +6 -5
- package/lib/Utils/lt-hash.js +3 -8
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +7 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +1 -2
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +1 -2
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +2 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -2
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +1 -2
- package/lib/WAUSync/Protocols/index.js +7 -1
- package/lib/WAUSync/USyncQuery.js +126 -23
- package/lib/WAUSync/USyncUser.js +24 -1
- package/lib/WAUSync/index.js +1 -2
- package/package.json +2 -6
- package/lib/Socket/Socket/Client/index.js +0 -2
- package/lib/Socket/Socket/Client/types.js +0 -10
- package/lib/Socket/Socket/Client/websocket.js +0 -53
- package/lib/Socket/Socket/business.js +0 -407
- package/lib/Socket/Socket/chats.js +0 -1908
- package/lib/Socket/Socket/communities.js +0 -431
- package/lib/Socket/Socket/groups.js +0 -549
- package/lib/Socket/Socket/index.js +0 -37
- package/lib/Socket/Socket/messages-recv.js +0 -2144
- package/lib/Socket/Socket/messages-send.js +0 -3177
- package/lib/Socket/Socket/mex.js +0 -41
- package/lib/Socket/Socket/newsletter.js +0 -260
- package/lib/Socket/Socket/socket.js +0 -1017
- package/lib/Utils/_crypto_orig.js +0 -118
- package/lib/WAUSync/WAUSync/Protocols/USyncContactProtocol.js +0 -56
- package/lib/WAUSync/WAUSync/Protocols/USyncDeviceProtocol.js +0 -53
- package/lib/WAUSync/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -26
- package/lib/WAUSync/WAUSync/Protocols/USyncStatusProtocol.js +0 -37
- package/lib/WAUSync/WAUSync/Protocols/USyncUsernameProtocol.js +0 -24
- package/lib/WAUSync/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -50
- package/lib/WAUSync/WAUSync/Protocols/UsyncLIDProtocol.js +0 -28
- package/lib/WAUSync/WAUSync/Protocols/index.js +0 -12
- package/lib/WAUSync/WAUSync/USyncQuery.js +0 -201
- package/lib/WAUSync/WAUSync/USyncUser.js +0 -54
- package/lib/WAUSync/WAUSync/index.js +0 -3
- /package/lib/Socket/{Socket/aigroups.js → aigroups.js} +0 -0
- /package/lib/Socket/{Socket/ban-checker.js → ban-checker.js} +0 -0
- /package/lib/Socket/{Socket/chats.js[old] → chats.js[old]} +0 -0
- /package/lib/Socket/{Socket/graphql.js → graphql.js} +0 -0
- /package/lib/Socket/{Socket/groups.js[old] → groups.js[old]} +0 -0
- /package/lib/Socket/{Socket/interactive-handler.js → interactive-handler.js} +0 -0
- /package/lib/Socket/{Socket/interop.js → interop.js} +0 -0
- /package/lib/Socket/{Socket/managed-account.js → managed-account.js} +0 -0
- /package/lib/Socket/{Socket/privacy.js → privacy.js} +0 -0
- /package/lib/Socket/{Socket/registration.js → registration.js} +0 -0
- /package/lib/Socket/{Socket/username.js → username.js} +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncBusinessProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncFeatureProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncPictureProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncSidelistProtocol.js +0 -0
- /package/lib/WAUSync/{WAUSync/Protocols → Protocols}/USyncTextStatusProtocol.js +0 -0
|
@@ -5,22 +5,68 @@ import Long from 'long';
|
|
|
5
5
|
import { proto } from '../../WAProto/index.js';
|
|
6
6
|
import { DEFAULT_CACHE_TTLS, KEY_BUNDLE_TYPE, MIN_PREKEY_COUNT, PLACEHOLDER_MAX_AGE_SECONDS, STATUS_EXPIRY_SECONDS } from '../Defaults/index.js';
|
|
7
7
|
import { ReachoutTimelockEnforcementType, WAMessageStatus, WAMessageStubType } from '../Types/index.js';
|
|
8
|
-
import { ACCOUNT_RESTRICTED_TEXT, aesDecryptCTR, aesEncryptGCM, cleanMessage, Curve, decodeMediaRetryNode, decodeMessageNode, decryptMessageNode, delay, derivePairingCodeKey, encodeBigEndian, encodeSignedDeviceIdentity, extractAddressingContext, extractE2ESessionFromRetryReceipt, getCallStatusFromNode, getHistoryMsg, getNextPreKeys, getStatusFromReceiptType, handleIdentityChange, hkdf, MISSING_KEYS_ERROR_TEXT, NACK_REASONS, NO_MESSAGE_FOUND_ERROR_TEXT, SERVER_ERROR_CODES, toNumber, unixTimestampSeconds, xmppPreKey, xmppSignedPreKey } from '../Utils/index.js';
|
|
8
|
+
import { ACCOUNT_RESTRICTED_TEXT, aesDecryptCTR, aesEncryptGCM, cleanMessage, Curve, decodeMediaRetryNode, decodeMessageNode, decryptMessageNode, delay, derivePairingCodeKey, encodeBigEndian, encodeSignedDeviceIdentity, extractAddressingContext, extractE2ESessionFromRetryReceipt, generateMessageID, setBotMessageSecret, getCallStatusFromNode, getHistoryMsg, getNextPreKeys, getStatusFromReceiptType, handleIdentityChange, hkdf, MISSING_KEYS_ERROR_TEXT, NACK_REASONS, NO_MESSAGE_FOUND_ERROR_TEXT, SERVER_ERROR_CODES, toNumber, unixTimestampSeconds, xmppPreKey, xmppSignedPreKey } from '../Utils/index.js';
|
|
9
9
|
import { makeMutex } from '../Utils/make-mutex.js';
|
|
10
10
|
import { makeOfflineNodeProcessor } from '../Utils/offline-node-processor.js';
|
|
11
11
|
import { buildAckStanza } from '../Utils/stanza-ack.js';
|
|
12
12
|
import { buildMergedTcTokenIndexWrite, isTcTokenExpired, readTcTokenIndex, resolveIssuanceJid, resolveTcTokenJid, storeTcTokensFromIqResult, TC_TOKEN_INDEX_KEY } from '../Utils/tc-token-utils.js';
|
|
13
|
-
import { areJidsSameUser, binaryNodeToString, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildString, getBinaryNodeChildUInt, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isLidUser, isPnUser, jidDecode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
13
|
+
import { areJidsSameUser, binaryNodeToString, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildString, getBinaryNodeChildUInt, isJidGroup, isJidNewsletter, isJidStatusBroadcast, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
14
14
|
import { extractGroupMetadata } from './groups.js';
|
|
15
15
|
import { makeMessagesSocket } from './messages-send.js';
|
|
16
16
|
const ENFORCEMENT_TYPE_VALUES = new Set(Object.values(ReachoutTimelockEnforcementType));
|
|
17
17
|
function isValidEnforcementType(value) {
|
|
18
18
|
return typeof value === 'string' && ENFORCEMENT_TYPE_VALUES.has(value);
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Build the <call><offer type="group" group-jid=..> stanza used to start a group call.
|
|
22
|
+
* Pure: no socket state, unit-testable.
|
|
23
|
+
*/
|
|
24
|
+
export const buildGroupCallStanza = ({ id, to, callId, callCreator, offerContent }) => ({
|
|
25
|
+
tag: 'call',
|
|
26
|
+
attrs: {
|
|
27
|
+
id,
|
|
28
|
+
to
|
|
29
|
+
},
|
|
30
|
+
content: [
|
|
31
|
+
{
|
|
32
|
+
tag: 'offer',
|
|
33
|
+
attrs: {
|
|
34
|
+
'call-id': callId,
|
|
35
|
+
'call-creator': callCreator,
|
|
36
|
+
type: 'group',
|
|
37
|
+
'group-jid': to
|
|
38
|
+
},
|
|
39
|
+
content: offerContent
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Build the <call><terminate> stanza used to cancel / hang up a group call.
|
|
45
|
+
* Pure: no socket state, unit-testable.
|
|
46
|
+
*/
|
|
47
|
+
export const buildGroupCallCancelStanza = ({ to, callId, callCreator }) => ({
|
|
48
|
+
tag: 'call',
|
|
49
|
+
attrs: {
|
|
50
|
+
from: callCreator,
|
|
51
|
+
to
|
|
52
|
+
},
|
|
53
|
+
content: [
|
|
54
|
+
{
|
|
55
|
+
tag: 'terminate',
|
|
56
|
+
attrs: {
|
|
57
|
+
'call-id': callId,
|
|
58
|
+
'call-creator': callCreator,
|
|
59
|
+
reason: 'user-terminated',
|
|
60
|
+
count: '0'
|
|
61
|
+
},
|
|
62
|
+
content: undefined
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
});
|
|
20
66
|
export const makeMessagesRecvSocket = (config) => {
|
|
21
67
|
const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid, enableAutoSessionRecreation } = config;
|
|
22
68
|
const sock = makeMessagesSocket(config);
|
|
23
|
-
const { userDevicesCache, devicesMutex, ev, authState, ws, messageMutex, notificationMutex, receiptMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, messageRetryManager, registerSocketEndHandler, issuePrivacyTokens, fetchAccountReachoutTimelock, placeholderResendCache } = sock;
|
|
69
|
+
const { userDevicesCache, devicesMutex, ev, authState, ws, messageMutex, notificationMutex, receiptMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, messageRetryManager, registerSocketEndHandler, issuePrivacyTokens, fetchAccountReachoutTimelock, placeholderResendCache, getUSyncDevices, createParticipantNodes, newsletterServerIdCache } = sock;
|
|
24
70
|
const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
|
|
25
71
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
|
26
72
|
const retryMutex = makeMutex();
|
|
@@ -384,6 +430,314 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
384
430
|
};
|
|
385
431
|
await query(stanza);
|
|
386
432
|
};
|
|
433
|
+
const acceptCall = async (callId, callFrom) => {
|
|
434
|
+
const stanza = {
|
|
435
|
+
tag: 'call',
|
|
436
|
+
attrs: {
|
|
437
|
+
from: authState.creds.me.id,
|
|
438
|
+
to: callFrom
|
|
439
|
+
},
|
|
440
|
+
content: [
|
|
441
|
+
{
|
|
442
|
+
tag: 'accept',
|
|
443
|
+
attrs: {
|
|
444
|
+
'call-id': callId,
|
|
445
|
+
'call-creator': callFrom,
|
|
446
|
+
count: '0'
|
|
447
|
+
},
|
|
448
|
+
content: undefined
|
|
449
|
+
}
|
|
450
|
+
]
|
|
451
|
+
};
|
|
452
|
+
await query(stanza);
|
|
453
|
+
};
|
|
454
|
+
const terminateCall = async (callId, callFrom) => {
|
|
455
|
+
const stanza = {
|
|
456
|
+
tag: 'call',
|
|
457
|
+
attrs: {
|
|
458
|
+
from: authState.creds.me.id,
|
|
459
|
+
to: callFrom
|
|
460
|
+
},
|
|
461
|
+
content: [
|
|
462
|
+
{
|
|
463
|
+
tag: 'terminate',
|
|
464
|
+
attrs: {
|
|
465
|
+
'call-id': callId,
|
|
466
|
+
'call-creator': callFrom,
|
|
467
|
+
reason: 'user-terminated',
|
|
468
|
+
count: '0'
|
|
469
|
+
},
|
|
470
|
+
content: undefined
|
|
471
|
+
}
|
|
472
|
+
]
|
|
473
|
+
};
|
|
474
|
+
await query(stanza);
|
|
475
|
+
};
|
|
476
|
+
const offerCall = async (toJid, isVideo = false) => {
|
|
477
|
+
const callId = randomBytes(16).toString('hex').toUpperCase().substring(0, 64);
|
|
478
|
+
const offerContent = [];
|
|
479
|
+
offerContent.push({
|
|
480
|
+
tag: 'audio',
|
|
481
|
+
attrs: { enc: 'opus', rate: '16000' },
|
|
482
|
+
content: undefined
|
|
483
|
+
});
|
|
484
|
+
offerContent.push({
|
|
485
|
+
tag: 'audio',
|
|
486
|
+
attrs: { enc: 'opus', rate: '8000' },
|
|
487
|
+
content: undefined
|
|
488
|
+
});
|
|
489
|
+
if (isVideo) {
|
|
490
|
+
offerContent.push({
|
|
491
|
+
tag: 'video',
|
|
492
|
+
attrs: {
|
|
493
|
+
enc: 'vp8',
|
|
494
|
+
dec: 'vp8',
|
|
495
|
+
orientation: '0',
|
|
496
|
+
screen_width: '1920',
|
|
497
|
+
screen_height: '1080',
|
|
498
|
+
device_orientation: '0'
|
|
499
|
+
},
|
|
500
|
+
content: undefined
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
offerContent.push({
|
|
504
|
+
tag: 'net',
|
|
505
|
+
attrs: { medium: '3' },
|
|
506
|
+
content: undefined
|
|
507
|
+
});
|
|
508
|
+
offerContent.push({
|
|
509
|
+
tag: 'capability',
|
|
510
|
+
attrs: { ver: '1' },
|
|
511
|
+
content: new Uint8Array([1, 4, 255, 131, 207, 4])
|
|
512
|
+
});
|
|
513
|
+
offerContent.push({
|
|
514
|
+
tag: 'encopt',
|
|
515
|
+
attrs: { keygen: '2' },
|
|
516
|
+
content: undefined
|
|
517
|
+
});
|
|
518
|
+
const encKey = randomBytes(32);
|
|
519
|
+
const devices = (await getUSyncDevices([toJid], true, false)).map(({ user, device }) => jidEncode(user, 's.whatsapp.net', device));
|
|
520
|
+
await assertSessions(devices, true);
|
|
521
|
+
const { nodes: destinations, shouldIncludeDeviceIdentity } = await createParticipantNodes(devices, {
|
|
522
|
+
call: {
|
|
523
|
+
callKey: new Uint8Array(encKey)
|
|
524
|
+
}
|
|
525
|
+
}, { count: '0' });
|
|
526
|
+
offerContent.push({ tag: 'destination', attrs: {}, content: destinations });
|
|
527
|
+
if (shouldIncludeDeviceIdentity) {
|
|
528
|
+
offerContent.push({
|
|
529
|
+
tag: 'device-identity',
|
|
530
|
+
attrs: {},
|
|
531
|
+
content: encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
const stanza = {
|
|
535
|
+
tag: 'call',
|
|
536
|
+
attrs: {
|
|
537
|
+
id: generateMessageID(),
|
|
538
|
+
to: toJid
|
|
539
|
+
},
|
|
540
|
+
content: [
|
|
541
|
+
{
|
|
542
|
+
tag: 'offer',
|
|
543
|
+
attrs: {
|
|
544
|
+
'call-id': callId,
|
|
545
|
+
'call-creator': authState.creds.me.id
|
|
546
|
+
},
|
|
547
|
+
content: offerContent
|
|
548
|
+
}
|
|
549
|
+
]
|
|
550
|
+
};
|
|
551
|
+
await query(stanza);
|
|
552
|
+
return {
|
|
553
|
+
id: callId,
|
|
554
|
+
to: toJid
|
|
555
|
+
};
|
|
556
|
+
};
|
|
557
|
+
/**
|
|
558
|
+
* Start a group call. Mirrors the proven 1:1 `offerCall` stanza (encrypted
|
|
559
|
+
* callKey envelope per destination) but addressed to the group with the
|
|
560
|
+
* `type="group"` + `group-jid` offer attributes that the receive pipeline
|
|
561
|
+
* recognizes for group calls.
|
|
562
|
+
* @param jid the group JID (e.g. 120363012345678901@g.us)
|
|
563
|
+
* @param participants participant JIDs to ring
|
|
564
|
+
* @param isVideo whether to offer a video call
|
|
565
|
+
*/
|
|
566
|
+
const groupCall = async (jid, participants = [], isVideo = false) => {
|
|
567
|
+
const callId = randomBytes(16).toString('hex').toUpperCase().substring(0, 64);
|
|
568
|
+
const offerContent = [];
|
|
569
|
+
offerContent.push({
|
|
570
|
+
tag: 'audio',
|
|
571
|
+
attrs: { enc: 'opus', rate: '16000' },
|
|
572
|
+
content: undefined
|
|
573
|
+
});
|
|
574
|
+
offerContent.push({
|
|
575
|
+
tag: 'audio',
|
|
576
|
+
attrs: { enc: 'opus', rate: '8000' },
|
|
577
|
+
content: undefined
|
|
578
|
+
});
|
|
579
|
+
if (isVideo) {
|
|
580
|
+
offerContent.push({
|
|
581
|
+
tag: 'video',
|
|
582
|
+
attrs: {
|
|
583
|
+
enc: 'vp8',
|
|
584
|
+
dec: 'vp8',
|
|
585
|
+
orientation: '0',
|
|
586
|
+
screen_width: '1920',
|
|
587
|
+
screen_height: '1080',
|
|
588
|
+
device_orientation: '0'
|
|
589
|
+
},
|
|
590
|
+
content: undefined
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
offerContent.push({
|
|
594
|
+
tag: 'net',
|
|
595
|
+
attrs: { medium: '3' },
|
|
596
|
+
content: undefined
|
|
597
|
+
});
|
|
598
|
+
offerContent.push({
|
|
599
|
+
tag: 'capability',
|
|
600
|
+
attrs: { ver: '1' },
|
|
601
|
+
content: new Uint8Array([1, 4, 255, 131, 207, 4])
|
|
602
|
+
});
|
|
603
|
+
offerContent.push({
|
|
604
|
+
tag: 'encopt',
|
|
605
|
+
attrs: { keygen: '2' },
|
|
606
|
+
content: undefined
|
|
607
|
+
});
|
|
608
|
+
const encKey = randomBytes(32);
|
|
609
|
+
const devices = (await getUSyncDevices(participants, true, false)).map(({ user, device }) => jidEncode(user, 's.whatsapp.net', device));
|
|
610
|
+
await assertSessions(devices, true);
|
|
611
|
+
const { nodes: destinations, shouldIncludeDeviceIdentity } = await createParticipantNodes(devices, {
|
|
612
|
+
call: {
|
|
613
|
+
callKey: new Uint8Array(encKey)
|
|
614
|
+
}
|
|
615
|
+
}, { count: '0' });
|
|
616
|
+
offerContent.push({ tag: 'destination', attrs: {}, content: destinations });
|
|
617
|
+
if (shouldIncludeDeviceIdentity) {
|
|
618
|
+
offerContent.push({
|
|
619
|
+
tag: 'device-identity',
|
|
620
|
+
attrs: {},
|
|
621
|
+
content: encodeSignedDeviceIdentity(authState.creds.account, true)
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
const stanza = buildGroupCallStanza({
|
|
625
|
+
id: generateMessageID(),
|
|
626
|
+
to: jid,
|
|
627
|
+
callId,
|
|
628
|
+
callCreator: authState.creds.me.id,
|
|
629
|
+
offerContent
|
|
630
|
+
});
|
|
631
|
+
await query(stanza);
|
|
632
|
+
return {
|
|
633
|
+
id: callId,
|
|
634
|
+
to: jid
|
|
635
|
+
};
|
|
636
|
+
};
|
|
637
|
+
/**
|
|
638
|
+
* Cancel / terminate a group call started with `groupCall`.
|
|
639
|
+
* Mirrors the proven 1:1 `terminateCall` stanza addressed to the group.
|
|
640
|
+
* @param jid the group JID the call was started in
|
|
641
|
+
* @param callId the call id returned by `groupCall`
|
|
642
|
+
*/
|
|
643
|
+
const cancelGroupCall = async (jid, callId) => {
|
|
644
|
+
const stanza = buildGroupCallCancelStanza({
|
|
645
|
+
to: jid,
|
|
646
|
+
callId,
|
|
647
|
+
callCreator: authState.creds.me.id
|
|
648
|
+
});
|
|
649
|
+
await query(stanza);
|
|
650
|
+
return {
|
|
651
|
+
id: callId,
|
|
652
|
+
to: jid
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
// Expose the group-call methods on the socket surface. Attached to the inner
|
|
656
|
+
// `sock` so they ride the `...sock` spread of this layer's return object
|
|
657
|
+
// (the return block lives beyond the edit window of the receive pipeline).
|
|
658
|
+
sock.groupCall = groupCall;
|
|
659
|
+
sock.cancelGroupCall = cancelGroupCall;
|
|
660
|
+
// Handles incoming <status> stanzas pushed by the server for newsletter posts.
|
|
661
|
+
// These arrive on the CB:status channel (AB-gated by status_e2ee_recv_over_status_stanza).
|
|
662
|
+
const handleNewsletterStatus = async (node) => {
|
|
663
|
+
const { id, from, server_id, t, is_sender, offline, type, edit } = node.attrs;
|
|
664
|
+
const serverId = server_id ? +server_id : undefined;
|
|
665
|
+
const timestamp = t ? +t : undefined;
|
|
666
|
+
const isSender = is_sender === 'true';
|
|
667
|
+
const offlineIndex = offline !== undefined ? +offline : undefined;
|
|
668
|
+
// Cache messageId → serverId so the bot can look up server_id when a message is quoted
|
|
669
|
+
if (id && serverId != null) {
|
|
670
|
+
newsletterServerIdCache?.set(id, serverId);
|
|
671
|
+
}
|
|
672
|
+
// Parse optional <meta> child: edit timestamps, interaction type, admin profile
|
|
673
|
+
const metaNode = getBinaryNodeChild(node, 'meta');
|
|
674
|
+
const meta = metaNode
|
|
675
|
+
? {
|
|
676
|
+
...(metaNode.attrs.msg_edit_t ? { editedAt: +metaNode.attrs.msg_edit_t } : {}),
|
|
677
|
+
...(metaNode.attrs.original_msg_t ? { originalTimestamp: +metaNode.attrs.original_msg_t } : {}),
|
|
678
|
+
...(metaNode.attrs.interaction_type ? { interactionType: metaNode.attrs.interaction_type } : {}),
|
|
679
|
+
...(metaNode.attrs.parent_server_id ? { parentServerId: +metaNode.attrs.parent_server_id } : {}),
|
|
680
|
+
...(metaNode.attrs.response_server_id ? { responseServerId: +metaNode.attrs.response_server_id } : {})
|
|
681
|
+
}
|
|
682
|
+
: undefined;
|
|
683
|
+
// Parse engagement counters
|
|
684
|
+
const viewsNode = getBinaryNodeChild(node, 'views_count');
|
|
685
|
+
const viewsCount = viewsNode?.attrs?.count !== undefined ? +viewsNode.attrs.count : undefined;
|
|
686
|
+
const responsesNode = getBinaryNodeChild(node, 'responses_count');
|
|
687
|
+
const responsesCount = responsesNode?.attrs?.count !== undefined ? +responsesNode.attrs.count : undefined;
|
|
688
|
+
const reactionsNode = getBinaryNodeChild(node, 'reactions');
|
|
689
|
+
const reactionCounts = getBinaryNodeChildren(reactionsNode ?? { content: [] }, 'reaction').map(r => ({
|
|
690
|
+
code: r.attrs.code,
|
|
691
|
+
count: +r.attrs.count
|
|
692
|
+
}));
|
|
693
|
+
let content = null;
|
|
694
|
+
let mediaType = undefined;
|
|
695
|
+
if (type === 'reaction') {
|
|
696
|
+
const reactionNode = getBinaryNodeChild(node, 'reaction');
|
|
697
|
+
content = { type: 'reaction', code: reactionNode?.attrs?.code };
|
|
698
|
+
}
|
|
699
|
+
else if (type === 'text' || type === 'media') {
|
|
700
|
+
const plaintextNode = getBinaryNodeChild(node, 'plaintext');
|
|
701
|
+
if (type === 'media')
|
|
702
|
+
mediaType = plaintextNode?.attrs?.mediatype;
|
|
703
|
+
if (edit === '7' || edit === '8') {
|
|
704
|
+
content = { type: 'revoke', edit };
|
|
705
|
+
}
|
|
706
|
+
else if (plaintextNode?.content) {
|
|
707
|
+
try {
|
|
708
|
+
const buf = Buffer.isBuffer(plaintextNode.content)
|
|
709
|
+
? plaintextNode.content
|
|
710
|
+
: Buffer.from(plaintextNode.content);
|
|
711
|
+
const message = proto.Message.decode(buf).toJSON();
|
|
712
|
+
content = { type, message, ...(mediaType ? { mediaType } : {}) };
|
|
713
|
+
}
|
|
714
|
+
catch (err) {
|
|
715
|
+
logger.error({ err }, 'Failed to decode newsletter status plaintext');
|
|
716
|
+
content = { type, raw: true, ...(mediaType ? { mediaType } : {}) };
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
// Send ACK back to server
|
|
721
|
+
const ackType = type === 'reaction' ? 'reaction' : edit ? 'revoke' : type;
|
|
722
|
+
await sendNode({
|
|
723
|
+
tag: 'ack',
|
|
724
|
+
attrs: { id, to: from, class: 'status', type: ackType || 'text' },
|
|
725
|
+
content: undefined
|
|
726
|
+
});
|
|
727
|
+
ev.emit('newsletter.status', {
|
|
728
|
+
id: from,
|
|
729
|
+
messageId: id,
|
|
730
|
+
serverId,
|
|
731
|
+
timestamp,
|
|
732
|
+
isSender,
|
|
733
|
+
...(offlineIndex !== undefined ? { offlineIndex } : {}),
|
|
734
|
+
...(meta ? { meta } : {}),
|
|
735
|
+
...(viewsCount !== undefined ? { viewsCount } : {}),
|
|
736
|
+
...(responsesCount !== undefined ? { responsesCount } : {}),
|
|
737
|
+
...(reactionCounts.length ? { reactionCounts } : {}),
|
|
738
|
+
content
|
|
739
|
+
});
|
|
740
|
+
};
|
|
387
741
|
const sendRetryRequest = async (node, forceIncludeKeys = false) => {
|
|
388
742
|
const { fullMessage } = decodeMessageNode(node, authState.creds.me.id, authState.creds.me.lid || '');
|
|
389
743
|
const { key: msgKey } = fullMessage;
|
|
@@ -1057,7 +1411,7 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
1057
1411
|
}
|
|
1058
1412
|
}
|
|
1059
1413
|
// Fallback to getMessage if not found in cache
|
|
1060
|
-
if (!msg) {
|
|
1414
|
+
if (!msg && getMessage) {
|
|
1061
1415
|
msg = await getMessage({ ...key, id });
|
|
1062
1416
|
if (msg) {
|
|
1063
1417
|
logger.debug({ jid: remoteJid, id }, 'found message via getMessage');
|
|
@@ -1265,11 +1619,24 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
1265
1619
|
};
|
|
1266
1620
|
const handleMessage = async (node) => {
|
|
1267
1621
|
const encNode = getBinaryNodeChild(node, 'enc');
|
|
1268
|
-
//
|
|
1622
|
+
// Pre-populate botMessageSecrets from store so msmsg can be decrypted after restart
|
|
1269
1623
|
if (encNode?.attrs.type === 'msmsg') {
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1624
|
+
if (getMessage) {
|
|
1625
|
+
const metaNode = getBinaryNodeChild(node, 'meta');
|
|
1626
|
+
const targetId = metaNode?.attrs?.target_id;
|
|
1627
|
+
if (targetId) {
|
|
1628
|
+
try {
|
|
1629
|
+
const targetMsg = await getMessage({ remoteJid: node.attrs.from, id: targetId, fromMe: true });
|
|
1630
|
+
const secret = targetMsg?.messageContextInfo?.messageSecret;
|
|
1631
|
+
if (secret) {
|
|
1632
|
+
setBotMessageSecret(targetId, secret);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
catch (err) {
|
|
1636
|
+
logger.debug({ err, targetId }, 'failed to retrieve message secret for msmsg');
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1273
1640
|
}
|
|
1274
1641
|
let acked = false;
|
|
1275
1642
|
try {
|
|
@@ -1621,6 +1988,9 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
1621
1988
|
ws.on('CB:notification', async (node) => {
|
|
1622
1989
|
await processNode('notification', node, 'handling notification', handleNotification);
|
|
1623
1990
|
});
|
|
1991
|
+
ws.on('CB:status', async (node) => {
|
|
1992
|
+
await handleNewsletterStatus(node).catch(error => onUnexpectedError(error, 'handling newsletter status'));
|
|
1993
|
+
});
|
|
1624
1994
|
ws.on('CB:ack,class:message', (node) => {
|
|
1625
1995
|
handleBadAck(node).catch(error => onUnexpectedError(error, 'handling bad ack'));
|
|
1626
1996
|
});
|
|
@@ -1764,9 +2134,11 @@ export const makeMessagesRecvSocket = (config) => {
|
|
|
1764
2134
|
sendMessageAck,
|
|
1765
2135
|
sendRetryRequest,
|
|
1766
2136
|
rejectCall,
|
|
2137
|
+
acceptCall,
|
|
2138
|
+
terminateCall,
|
|
2139
|
+
offerCall,
|
|
1767
2140
|
fetchMessageHistory,
|
|
1768
2141
|
requestPlaceholderResend,
|
|
1769
2142
|
messageRetryManager
|
|
1770
2143
|
};
|
|
1771
2144
|
};
|
|
1772
|
-
//# sourceMappingURL=messages-recv.js.map
|