@kelvdra/baileys 1.0.3 → 1.0.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 +75 -1499
- package/lib/Defaults/index.d.ts +62 -0
- package/lib/Defaults/index.js +2 -2
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/business.d.ts +190 -0
- package/lib/Socket/chats.d.ts +100 -0
- package/lib/Socket/chats.js +14 -13
- package/lib/Socket/communities.d.ts +246 -0
- package/lib/Socket/groups.d.ts +139 -0
- package/lib/Socket/groups.js +2 -3
- package/lib/Socket/hydra.js +1 -2
- package/lib/Socket/index.d.ts +233 -0
- package/lib/Socket/messages-recv.d.ts +175 -0
- package/lib/Socket/messages-recv.js +325 -515
- package/lib/Socket/messages-send.d.ts +171 -0
- package/lib/Socket/messages-send.js +104 -467
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/newsletter.d.ts +149 -0
- package/lib/Socket/socket.d.ts +53 -0
- package/lib/Socket/socket.js +52 -51
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-in-memory-store.d.ts +123 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Types/Auth.d.ts +115 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Call.d.ts +14 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Events.d.ts +202 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/Message.d.ts +382 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +5 -7
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/generics.d.ts +90 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/index.d.ts +19 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/lt-hash.d.ts +13 -0
- package/lib/Utils/make-mutex.d.ts +8 -0
- package/lib/Utils/message-retry-manager.d.ts +82 -0
- package/lib/Utils/messages-media.d.ts +114 -0
- package/lib/Utils/messages-media.js +69 -33
- package/lib/Utils/messages.d.ts +89 -0
- package/lib/Utils/messages.js +42 -12
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +7 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/index.d.ts +13 -0
- package/package.json +3 -34
|
@@ -2,20 +2,17 @@ import NodeCache from '@cacheable/node-cache';
|
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
3
|
import { proto } from '../../WAProto/index.js';
|
|
4
4
|
import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
5
|
-
import * as Utils_1 from "../Utils/index.js"
|
|
6
5
|
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils/index.js';
|
|
7
6
|
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
8
7
|
import { makeKeyedMutex } from '../Utils/make-mutex.js';
|
|
9
|
-
import
|
|
8
|
+
import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
|
|
10
9
|
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidGroup, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
11
10
|
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
12
11
|
import { makeNewsletterSocket } from './newsletter.js';
|
|
13
|
-
import hydra from './hydra.js'
|
|
14
|
-
import { randomBytes } from "crypto"
|
|
15
12
|
export const makeMessagesSocket = (config) => {
|
|
16
13
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
|
|
17
14
|
const sock = makeNewsletterSocket(config);
|
|
18
|
-
const { ev, authState,
|
|
15
|
+
const { ev, authState, messageMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral } = sock;
|
|
19
16
|
const userDevicesCache = config.userDevicesCache ||
|
|
20
17
|
new NodeCache({
|
|
21
18
|
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
@@ -258,6 +255,31 @@ export const makeMessagesSocket = (config) => {
|
|
|
258
255
|
}
|
|
259
256
|
return deviceResults;
|
|
260
257
|
};
|
|
258
|
+
/**
|
|
259
|
+
* Update Member Label
|
|
260
|
+
*/
|
|
261
|
+
const updateMemberLabel = (jid, memberLabel) => {
|
|
262
|
+
return relayMessage(jid, {
|
|
263
|
+
protocolMessage: {
|
|
264
|
+
type: proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE,
|
|
265
|
+
memberLabel: {
|
|
266
|
+
label: memberLabel?.slice(0, 30),
|
|
267
|
+
labelTimestamp: unixTimestampSeconds()
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}, {
|
|
271
|
+
additionalNodes: [
|
|
272
|
+
{
|
|
273
|
+
tag: 'meta',
|
|
274
|
+
attrs: {
|
|
275
|
+
tag_reason: 'user_update',
|
|
276
|
+
appdata: 'member_tag'
|
|
277
|
+
},
|
|
278
|
+
content: undefined
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
});
|
|
282
|
+
};
|
|
261
283
|
const assertSessions = async (jids, force) => {
|
|
262
284
|
let didFetchNewSession = false;
|
|
263
285
|
const uniqueJids = [...new Set(jids)]; // Deduplicate JIDs
|
|
@@ -358,49 +380,51 @@ export const makeMessagesSocket = (config) => {
|
|
|
358
380
|
const meLid = authState.creds.me?.lid;
|
|
359
381
|
const meLidUser = meLid ? jidDecode(meLid)?.user : null;
|
|
360
382
|
const encryptionPromises = patchedMessages.map(async ({ recipientJid: jid, message: patchedMessage }) => {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
383
|
+
try {
|
|
384
|
+
if (!jid)
|
|
385
|
+
return null;
|
|
386
|
+
let msgToEncrypt = patchedMessage;
|
|
387
|
+
if (dsmMessage) {
|
|
388
|
+
const { user: targetUser } = jidDecode(jid);
|
|
389
|
+
const { user: ownPnUser } = jidDecode(meId);
|
|
390
|
+
const ownLidUser = meLidUser;
|
|
391
|
+
const isOwnUser = targetUser === ownPnUser || (ownLidUser && targetUser === ownLidUser);
|
|
392
|
+
const isExactSenderDevice = jid === meId || (meLid && jid === meLid);
|
|
393
|
+
if (isOwnUser && !isExactSenderDevice) {
|
|
394
|
+
msgToEncrypt = dsmMessage;
|
|
395
|
+
logger.debug({ jid, targetUser }, 'Using DSM for own device');
|
|
396
|
+
}
|
|
373
397
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
398
|
+
const bytes = encodeWAMessage(msgToEncrypt);
|
|
399
|
+
const mutexKey = jid;
|
|
400
|
+
const node = await encryptionMutex.mutex(mutexKey, async () => {
|
|
401
|
+
const { type, ciphertext } = await signalRepository.encryptMessage({ jid, data: bytes });
|
|
402
|
+
if (type === 'pkmsg') {
|
|
403
|
+
shouldIncludeDeviceIdentity = true;
|
|
404
|
+
}
|
|
405
|
+
return {
|
|
406
|
+
tag: 'to',
|
|
407
|
+
attrs: { jid },
|
|
408
|
+
content: [
|
|
409
|
+
{
|
|
410
|
+
tag: 'enc',
|
|
411
|
+
attrs: { v: '2', type, ...(extraAttrs || {}) },
|
|
412
|
+
content: ciphertext
|
|
413
|
+
}
|
|
414
|
+
]
|
|
415
|
+
};
|
|
381
416
|
});
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
content: [
|
|
389
|
-
{
|
|
390
|
-
tag: 'enc',
|
|
391
|
-
attrs: {
|
|
392
|
-
v: '2',
|
|
393
|
-
type,
|
|
394
|
-
...(extraAttrs || {})
|
|
395
|
-
},
|
|
396
|
-
content: ciphertext
|
|
397
|
-
}
|
|
398
|
-
]
|
|
399
|
-
};
|
|
400
|
-
});
|
|
401
|
-
return node;
|
|
417
|
+
return node;
|
|
418
|
+
}
|
|
419
|
+
catch (err) {
|
|
420
|
+
logger.error({ jid, err }, 'Failed to encrypt for recipient');
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
402
423
|
});
|
|
403
424
|
const nodes = (await Promise.all(encryptionPromises)).filter(node => node !== null);
|
|
425
|
+
if (recipientJids.length > 0 && nodes.length === 0) {
|
|
426
|
+
throw new Boom('All encryptions failed', { statusCode: 500 });
|
|
427
|
+
}
|
|
404
428
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
405
429
|
};
|
|
406
430
|
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
|
|
@@ -423,8 +447,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
423
447
|
const destinationJid = !isStatus ? finalJid : statusJid;
|
|
424
448
|
const binaryNodeContent = [];
|
|
425
449
|
const devices = [];
|
|
426
|
-
|
|
427
|
-
const buttonType = getButtonType(messages)
|
|
450
|
+
let reportingMessage;
|
|
428
451
|
const meMsg = {
|
|
429
452
|
deviceSentMessage: {
|
|
430
453
|
destinationJid,
|
|
@@ -471,7 +494,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
471
494
|
await sendNode(stanza);
|
|
472
495
|
return;
|
|
473
496
|
}
|
|
474
|
-
if (normalizeMessageContent(message)?.pinInChatMessage) {
|
|
497
|
+
if (normalizeMessageContent(message)?.pinInChatMessage || normalizeMessageContent(message)?.reactionMessage) {
|
|
475
498
|
extraAttrs['decrypt-fail'] = 'hide'; // todo: expand for reactions and other types
|
|
476
499
|
}
|
|
477
500
|
if (isGroupOrStatus && !isRetryResend) {
|
|
@@ -519,6 +542,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
519
542
|
throw new Boom('Per-jid patching is not supported in groups');
|
|
520
543
|
}
|
|
521
544
|
const bytes = encodeWAMessage(patched);
|
|
545
|
+
reportingMessage = patched;
|
|
522
546
|
const groupAddressingMode = additionalAttributes?.['addressing_mode'] || groupData?.addressingMode || 'lid';
|
|
523
547
|
const groupSenderIdentity = groupAddressingMode === 'lid' && meLid ? meLid : meId;
|
|
524
548
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
|
@@ -573,6 +597,12 @@ export const makeMessagesSocket = (config) => {
|
|
|
573
597
|
logger.debug({ to: jid, ownId }, 'Using PN identity for @s.whatsapp.net conversation');
|
|
574
598
|
}
|
|
575
599
|
const { user: ownUser } = jidDecode(ownId);
|
|
600
|
+
if (!participant) {
|
|
601
|
+
const patchedForReporting = await patchMessageBeforeSending(message, [jid]);
|
|
602
|
+
reportingMessage = Array.isArray(patchedForReporting)
|
|
603
|
+
? patchedForReporting.find(item => item.recipientJid === jid) || patchedForReporting[0]
|
|
604
|
+
: patchedForReporting;
|
|
605
|
+
}
|
|
576
606
|
if (!isRetryResend) {
|
|
577
607
|
const targetUserServer = isLid ? 'lid' : 's.whatsapp.net';
|
|
578
608
|
devices.push({
|
|
@@ -708,16 +738,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
708
738
|
else {
|
|
709
739
|
stanza.attrs.to = destinationJid;
|
|
710
740
|
}
|
|
711
|
-
if (!isNewsletter && buttonType) {
|
|
712
|
-
const buttonsNode = getButtonArgs(messages)
|
|
713
|
-
const filteredButtons = WABinary_1.getBinaryFilteredButtons(additionalNodes ? additionalNodes : [])
|
|
714
|
-
if (filteredButtons) {
|
|
715
|
-
stanza.content.push(...additionalNodes)
|
|
716
|
-
additionalAlready = true
|
|
717
|
-
} else {
|
|
718
|
-
stanza.content.push(buttonsNode)
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
741
|
if (shouldIncludeDeviceIdentity) {
|
|
722
742
|
;
|
|
723
743
|
stanza.content.push({
|
|
@@ -727,6 +747,29 @@ export const makeMessagesSocket = (config) => {
|
|
|
727
747
|
});
|
|
728
748
|
logger.debug({ jid }, 'adding device identity');
|
|
729
749
|
}
|
|
750
|
+
if (!isNewsletter &&
|
|
751
|
+
!isRetryResend &&
|
|
752
|
+
reportingMessage?.messageContextInfo?.messageSecret &&
|
|
753
|
+
shouldIncludeReportingToken(reportingMessage)) {
|
|
754
|
+
try {
|
|
755
|
+
const encoded = encodeWAMessage(reportingMessage);
|
|
756
|
+
const reportingKey = {
|
|
757
|
+
id: msgId,
|
|
758
|
+
fromMe: true,
|
|
759
|
+
remoteJid: destinationJid,
|
|
760
|
+
participant: participant?.jid
|
|
761
|
+
};
|
|
762
|
+
const reportingNode = await getMessageReportingToken(encoded, reportingMessage, reportingKey);
|
|
763
|
+
if (reportingNode) {
|
|
764
|
+
;
|
|
765
|
+
stanza.content.push(reportingNode);
|
|
766
|
+
logger.trace({ jid }, 'added reporting token to message');
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
catch (error) {
|
|
770
|
+
logger.warn({ jid, trace: error?.stack }, 'failed to attach reporting token');
|
|
771
|
+
}
|
|
772
|
+
}
|
|
730
773
|
const contactTcTokenData = !isGroup && !isRetryResend && !isStatus ? await authState.keys.get('tctoken', [destinationJid]) : {};
|
|
731
774
|
const tcTokenBuffer = contactTcTokenData[destinationJid]?.token;
|
|
732
775
|
if (tcTokenBuffer) {
|
|
@@ -754,12 +797,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
754
797
|
if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
|
|
755
798
|
return 'poll';
|
|
756
799
|
}
|
|
757
|
-
if (message.eventMessage) {
|
|
758
|
-
return 'event';
|
|
759
|
-
}
|
|
760
|
-
if (getMediaType(message) !== '') {
|
|
761
|
-
return 'media';
|
|
762
|
-
}
|
|
763
800
|
return 'text';
|
|
764
801
|
};
|
|
765
802
|
const getMediaType = (message) => {
|
|
@@ -810,114 +847,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
810
847
|
}
|
|
811
848
|
return '';
|
|
812
849
|
};
|
|
813
|
-
|
|
814
|
-
const getButtonType = (message) => {
|
|
815
|
-
if (message.listMessage) {
|
|
816
|
-
return 'list'
|
|
817
|
-
}
|
|
818
|
-
else if (message.buttonsMessage) {
|
|
819
|
-
return 'buttons'
|
|
820
|
-
}
|
|
821
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_and_pay') {
|
|
822
|
-
return 'review_and_pay'
|
|
823
|
-
}
|
|
824
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_order') {
|
|
825
|
-
return 'review_order'
|
|
826
|
-
}
|
|
827
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_info') {
|
|
828
|
-
return 'payment_info'
|
|
829
|
-
}
|
|
830
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
|
|
831
|
-
return 'payment_status'
|
|
832
|
-
}
|
|
833
|
-
else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
|
|
834
|
-
return 'payment_method'
|
|
835
|
-
}
|
|
836
|
-
else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
|
|
837
|
-
return 'interactive'
|
|
838
|
-
}
|
|
839
|
-
else if (message.interactiveMessage?.nativeFlowMessage) {
|
|
840
|
-
return 'native_flow'
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
const getButtonArgs = (message) => {
|
|
845
|
-
const message_content = message.viewOnceMessage?.message || message;
|
|
846
|
-
const message_flow = message_content.interactiveMessage?.nativeFlowMessage;
|
|
847
|
-
const flow_buttons_first = message_flow?.buttons?.[0]?.name;
|
|
848
|
-
const flow_buttons_special = [ 'mpm', 'cta_catalog', 'send_location', 'call_permission_request', 'wa_payment_transaction_details', 'automated_greeting_message_view_catalog' ];
|
|
849
|
-
const baseArgs = {
|
|
850
|
-
tag: 'biz',
|
|
851
|
-
attrs: {
|
|
852
|
-
actual_actors: '2',
|
|
853
|
-
host_storage: '2',
|
|
854
|
-
privacy_mode_ts: Utils_1.unixTimestampSeconds().toString()
|
|
855
|
-
}
|
|
856
|
-
};
|
|
857
|
-
if (message_flow && (flow_buttons_first === 'review_and_pay' || flow_buttons_first === 'payment_info')) {
|
|
858
|
-
return {
|
|
859
|
-
tag: 'biz',
|
|
860
|
-
attrs: {
|
|
861
|
-
native_flow_name: flow_buttons_first === 'review_and_pay' ? 'order_details' : flow_buttons_first
|
|
862
|
-
}
|
|
863
|
-
};
|
|
864
|
-
}
|
|
865
|
-
if (message_flow && flow_buttons_special.includes(flow_buttons_first)) {
|
|
866
|
-
return {
|
|
867
|
-
...baseArgs,
|
|
868
|
-
content: [
|
|
869
|
-
{
|
|
870
|
-
tag: 'interactive',
|
|
871
|
-
attrs: { type: 'native_flow', v: '1' },
|
|
872
|
-
content: [{
|
|
873
|
-
tag: 'native_flow',
|
|
874
|
-
attrs: { v: '2', name: flow_buttons_first }
|
|
875
|
-
}]
|
|
876
|
-
},
|
|
877
|
-
{
|
|
878
|
-
tag: 'quality_control',
|
|
879
|
-
attrs: { source_type: 'third_party' }
|
|
880
|
-
}
|
|
881
|
-
]
|
|
882
|
-
};
|
|
883
|
-
}
|
|
884
|
-
if (message_flow || message_content.buttonsMessage) {
|
|
885
|
-
return {
|
|
886
|
-
...baseArgs,
|
|
887
|
-
content: [
|
|
888
|
-
{
|
|
889
|
-
tag: 'interactive',
|
|
890
|
-
attrs: { type: 'native_flow', v: '1' },
|
|
891
|
-
content: [{
|
|
892
|
-
tag: 'native_flow',
|
|
893
|
-
attrs: { v: '9', name: 'mixed' }
|
|
894
|
-
}]
|
|
895
|
-
},
|
|
896
|
-
{
|
|
897
|
-
tag: 'quality_control',
|
|
898
|
-
attrs: { source_type: 'third_party' }
|
|
899
|
-
}
|
|
900
|
-
]
|
|
901
|
-
};
|
|
902
|
-
}
|
|
903
|
-
if (message_content.listMessage) {
|
|
904
|
-
return {
|
|
905
|
-
...baseArgs,
|
|
906
|
-
content: [
|
|
907
|
-
{
|
|
908
|
-
tag: 'list',
|
|
909
|
-
attrs: { v: '2', type: 'product_list' }
|
|
910
|
-
},
|
|
911
|
-
{
|
|
912
|
-
tag: 'quality_control',
|
|
913
|
-
attrs: { source_type: 'third_party' }
|
|
914
|
-
}
|
|
915
|
-
]
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
return baseArgs;
|
|
919
|
-
};
|
|
920
|
-
|
|
921
850
|
const getPrivacyTokens = async (jids) => {
|
|
922
851
|
const t = unixTimestampSeconds().toString();
|
|
923
852
|
const result = await query({
|
|
@@ -944,22 +873,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
944
873
|
});
|
|
945
874
|
return result;
|
|
946
875
|
};
|
|
947
|
-
|
|
948
|
-
const getEphemeralGroup = (jid) => {
|
|
949
|
-
if (!WABinary_1.isJidGroup(jid)) throw new TypeError("Jid should originate from a group!")
|
|
950
|
-
|
|
951
|
-
return groupQuery(jid, 'get', [{
|
|
952
|
-
tag: 'query',
|
|
953
|
-
attrs: {
|
|
954
|
-
request: 'interactive'
|
|
955
|
-
}
|
|
956
|
-
}])
|
|
957
|
-
.then((groups) => WABinary_1.getBinaryNodeChild(groups, 'group'))
|
|
958
|
-
.then((metadata) => WABinary_1.getBinaryNodeChild(metadata, 'ephemeral')?.attrs?.expiration || 0)
|
|
959
|
-
}
|
|
960
|
-
|
|
961
876
|
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
962
|
-
const kelvdra = new hydra(Utils_1, waUploadToServer, relayMessage)
|
|
963
877
|
const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
|
|
964
878
|
return {
|
|
965
879
|
...sock,
|
|
@@ -971,17 +885,17 @@ export const makeMessagesSocket = (config) => {
|
|
|
971
885
|
readMessages,
|
|
972
886
|
refreshMediaConn,
|
|
973
887
|
waUploadToServer,
|
|
974
|
-
kelvdra,
|
|
975
888
|
fetchPrivacySettings,
|
|
976
889
|
sendPeerDataOperationMessage,
|
|
977
890
|
createParticipantNodes,
|
|
978
891
|
getUSyncDevices,
|
|
979
892
|
messageRetryManager,
|
|
893
|
+
updateMemberLabel,
|
|
980
894
|
updateMediaMessage: async (message) => {
|
|
981
895
|
const content = assertMediaContent(message.message);
|
|
982
896
|
const mediaKey = content.mediaKey;
|
|
983
897
|
const meId = authState.creds.me.id;
|
|
984
|
-
const node =
|
|
898
|
+
const node = encryptMediaRetryRequest(message.key, mediaKey, meId);
|
|
985
899
|
let error = undefined;
|
|
986
900
|
await Promise.all([
|
|
987
901
|
sendNode(node),
|
|
@@ -993,7 +907,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
993
907
|
}
|
|
994
908
|
else {
|
|
995
909
|
try {
|
|
996
|
-
const media =
|
|
910
|
+
const media = decryptMediaRetryData(result.media, mediaKey, result.key.id);
|
|
997
911
|
if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
|
|
998
912
|
const resultStr = proto.MediaRetryNotification.ResultType[media.result];
|
|
999
913
|
throw new Boom(`Media re-upload failed by device (${resultStr})`, {
|
|
@@ -1019,285 +933,8 @@ export const makeMessagesSocket = (config) => {
|
|
|
1019
933
|
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
|
|
1020
934
|
return message;
|
|
1021
935
|
},
|
|
1022
|
-
sendStatusMentions: async (content, jids = []) => {
|
|
1023
|
-
const userJid = WABinary_1.jidNormalizedUser(authState.creds.me.id)
|
|
1024
|
-
let allUsers = new Set()
|
|
1025
|
-
allUsers.add(userJid)
|
|
1026
|
-
|
|
1027
|
-
for (const id of jids) {
|
|
1028
|
-
const isGroup = WABinary_1.isJidGroup(id)
|
|
1029
|
-
const isPrivate = WABinary_1.isPnUser(id)
|
|
1030
|
-
|
|
1031
|
-
if (isGroup) {
|
|
1032
|
-
try {
|
|
1033
|
-
const metadata = await cachedGroupMetadata(id) || await global.groupMetadataCache(id)
|
|
1034
|
-
const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.id))
|
|
1035
|
-
participants.forEach(jid => allUsers.add(jid))
|
|
1036
|
-
} catch (error) {
|
|
1037
|
-
logger.error(`Error getting metadata for group ${id}: ${error}`)
|
|
1038
|
-
}
|
|
1039
|
-
} else if (isPrivate) {
|
|
1040
|
-
allUsers.add(WABinary_1.jidNormalizedUser(id))
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
const uniqueUsers = Array.from(allUsers)
|
|
1045
|
-
const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0")
|
|
1046
|
-
|
|
1047
|
-
const isMedia = content.image || content.video || content.audio
|
|
1048
|
-
const isAudio = !!content.audio
|
|
1049
|
-
|
|
1050
|
-
const messageContent = {
|
|
1051
|
-
...content
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
if (isMedia && !isAudio) {
|
|
1055
|
-
if (messageContent.text) {
|
|
1056
|
-
messageContent.caption = messageContent.text
|
|
1057
|
-
|
|
1058
|
-
delete messageContent.text
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
delete messageContent.ptt
|
|
1062
|
-
delete messageContent.font
|
|
1063
|
-
delete messageContent.backgroundColor
|
|
1064
|
-
delete messageContent.textColor
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
if (isAudio) {
|
|
1068
|
-
delete messageContent.text
|
|
1069
|
-
delete messageContent.caption
|
|
1070
|
-
delete messageContent.font
|
|
1071
|
-
delete messageContent.textColor
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined
|
|
1075
|
-
const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined
|
|
1076
|
-
const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined
|
|
1077
|
-
const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined
|
|
1078
|
-
|
|
1079
|
-
let msg
|
|
1080
|
-
let mediaHandle
|
|
1081
|
-
try {
|
|
1082
|
-
msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
|
|
1083
|
-
logger,
|
|
1084
|
-
userJid,
|
|
1085
|
-
getUrlInfo: text => link_preview_1.getUrlInfo(text, {
|
|
1086
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1087
|
-
fetchOpts: {
|
|
1088
|
-
timeout: 3000,
|
|
1089
|
-
...axiosOptions || {}
|
|
1090
|
-
},
|
|
1091
|
-
logger,
|
|
1092
|
-
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1093
|
-
}),
|
|
1094
|
-
upload: async (encFilePath, opts) => {
|
|
1095
|
-
const up = await waUploadToServer(encFilePath, {
|
|
1096
|
-
...opts
|
|
1097
|
-
})
|
|
1098
|
-
mediaHandle = up.handle
|
|
1099
|
-
return up
|
|
1100
|
-
},
|
|
1101
|
-
mediaCache: config.mediaCache,
|
|
1102
|
-
options: config.options,
|
|
1103
|
-
font,
|
|
1104
|
-
textColor,
|
|
1105
|
-
backgroundColor,
|
|
1106
|
-
ptt
|
|
1107
|
-
})
|
|
1108
|
-
} catch (error) {
|
|
1109
|
-
logger.error(`Error generating message: ${error}`)
|
|
1110
|
-
throw error
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
await relayMessage(WABinary_1.STORIES_JID, msg.message, {
|
|
1114
|
-
messageId: msg.key.id,
|
|
1115
|
-
statusJidList: uniqueUsers,
|
|
1116
|
-
additionalNodes: [{
|
|
1117
|
-
tag: 'meta',
|
|
1118
|
-
attrs: {},
|
|
1119
|
-
content: [{
|
|
1120
|
-
tag: 'mentioned_users',
|
|
1121
|
-
attrs: {},
|
|
1122
|
-
content: jids.map(jid => ({
|
|
1123
|
-
tag: 'to',
|
|
1124
|
-
attrs: {
|
|
1125
|
-
jid: WABinary_1.jidNormalizedUser(jid)
|
|
1126
|
-
}
|
|
1127
|
-
}))
|
|
1128
|
-
}]
|
|
1129
|
-
}]
|
|
1130
|
-
})
|
|
1131
|
-
|
|
1132
|
-
for (const id of jids) {
|
|
1133
|
-
try {
|
|
1134
|
-
const normalizedId = WABinary_1.jidNormalizedUser(id)
|
|
1135
|
-
const isPrivate = WABinary_1.isJidUser(normalizedId)
|
|
1136
|
-
const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage'
|
|
1137
|
-
|
|
1138
|
-
const protocolMessage = {
|
|
1139
|
-
[type]: {
|
|
1140
|
-
message: {
|
|
1141
|
-
protocolMessage: {
|
|
1142
|
-
key: msg.key,
|
|
1143
|
-
type: 25
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
},
|
|
1147
|
-
messageContextInfo: {
|
|
1148
|
-
messageSecret: randomBytes(32)
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
const statusMsg = await Utils_1.generateWAMessageFromContent(normalizedId,
|
|
1153
|
-
protocolMessage, {}
|
|
1154
|
-
)
|
|
1155
|
-
|
|
1156
|
-
await relayMessage(
|
|
1157
|
-
normalizedId,
|
|
1158
|
-
statusMsg.message, {
|
|
1159
|
-
additionalNodes: [{
|
|
1160
|
-
tag: 'meta',
|
|
1161
|
-
attrs: isPrivate ? {
|
|
1162
|
-
is_status_mention: 'true'
|
|
1163
|
-
} : {
|
|
1164
|
-
is_group_status_mention: 'true'
|
|
1165
|
-
}
|
|
1166
|
-
}]
|
|
1167
|
-
}
|
|
1168
|
-
)
|
|
1169
|
-
|
|
1170
|
-
await Utils_1.delay(2000)
|
|
1171
|
-
} catch (error) {
|
|
1172
|
-
logger.error(`Error sending to ${id}: ${error}`)
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
return msg
|
|
1177
|
-
},
|
|
1178
|
-
sendAlbumMessage: async (jid, medias, options = {}) => {
|
|
1179
|
-
const userJid = authState.creds.me.id
|
|
1180
|
-
for (const media of medias) {
|
|
1181
|
-
if (!media.image && !media.video) throw new TypeError(`medias[i] must have image or video property`)
|
|
1182
|
-
}
|
|
1183
|
-
if (medias.length < 2) throw new RangeError("Minimum 2 media")
|
|
1184
|
-
const time = options.delay || 500
|
|
1185
|
-
delete options.delay
|
|
1186
|
-
const album = await Utils_1.generateWAMessageFromContent(jid, {
|
|
1187
|
-
albumMessage: {
|
|
1188
|
-
expectedImageCount: medias.filter(media => media.image).length,
|
|
1189
|
-
expectedVideoCount: medias.filter(media => media.video).length,
|
|
1190
|
-
...options
|
|
1191
|
-
}
|
|
1192
|
-
}, {
|
|
1193
|
-
userJid,
|
|
1194
|
-
...options
|
|
1195
|
-
})
|
|
1196
|
-
await relayMessage(jid, album.message, {
|
|
1197
|
-
messageId: album.key.id
|
|
1198
|
-
})
|
|
1199
|
-
let mediaHandle
|
|
1200
|
-
let msg
|
|
1201
|
-
for (const i in medias) {
|
|
1202
|
-
const media = medias[i]
|
|
1203
|
-
if (media.image) {
|
|
1204
|
-
msg = await Utils_1.generateWAMessage(jid, {
|
|
1205
|
-
image: media.image,
|
|
1206
|
-
...media,
|
|
1207
|
-
...options
|
|
1208
|
-
}, {
|
|
1209
|
-
userJid,
|
|
1210
|
-
upload: async (readStream, opts) => {
|
|
1211
|
-
const up = await waUploadToServer(readStream, {
|
|
1212
|
-
...opts,
|
|
1213
|
-
newsletter: WABinary_1.isJidNewsletter(jid)
|
|
1214
|
-
})
|
|
1215
|
-
mediaHandle = up.handle
|
|
1216
|
-
return up
|
|
1217
|
-
},
|
|
1218
|
-
...options
|
|
1219
|
-
})
|
|
1220
|
-
} else if (media.video) {
|
|
1221
|
-
msg = await Utils_1.generateWAMessage(jid, {
|
|
1222
|
-
video: media.video,
|
|
1223
|
-
...media,
|
|
1224
|
-
...options
|
|
1225
|
-
}, {
|
|
1226
|
-
userJid,
|
|
1227
|
-
upload: async (readStream, opts) => {
|
|
1228
|
-
const up = await waUploadToServer(readStream, {
|
|
1229
|
-
...opts,
|
|
1230
|
-
newsletter: WABinary_1.isJidNewsletter(jid)
|
|
1231
|
-
})
|
|
1232
|
-
mediaHandle = up.handle
|
|
1233
|
-
return up
|
|
1234
|
-
},
|
|
1235
|
-
...options,
|
|
1236
|
-
})
|
|
1237
|
-
}
|
|
1238
|
-
if (msg) {
|
|
1239
|
-
msg.message.messageContextInfo = {
|
|
1240
|
-
messageSecret: randomBytes(32),
|
|
1241
|
-
messageAssociation: {
|
|
1242
|
-
associationType: 1,
|
|
1243
|
-
parentMessageKey: album.key
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
await relayMessage(jid, msg.message, {
|
|
1248
|
-
messageId: msg.key.id
|
|
1249
|
-
})
|
|
1250
|
-
await Utils_1.delay(time)
|
|
1251
|
-
}
|
|
1252
|
-
return album
|
|
1253
|
-
},
|
|
1254
936
|
sendMessage: async (jid, content, options = {}) => {
|
|
1255
937
|
const userJid = authState.creds.me.id;
|
|
1256
|
-
const additionalAttributes = {}
|
|
1257
|
-
const { filter = false, quoted } = options;
|
|
1258
|
-
const getParticipantAttr = () => filter ? { participant: { jid } } : {};
|
|
1259
|
-
const messageType = kelvdra.detectType(content);
|
|
1260
|
-
if (messageType) {
|
|
1261
|
-
switch(messageType) {
|
|
1262
|
-
case 'PAYMENT':
|
|
1263
|
-
const paymentContent = await kelvdra.handlePayment(content, quoted);
|
|
1264
|
-
return await relayMessage(jid, paymentContent, {
|
|
1265
|
-
messageId: Utils_1.generateMessageID(),
|
|
1266
|
-
...getParticipantAttr()
|
|
1267
|
-
});
|
|
1268
|
-
|
|
1269
|
-
case 'PRODUCT':
|
|
1270
|
-
const productContent = await kelvdra.handleProduct(content, jid, quoted);
|
|
1271
|
-
const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
|
|
1272
|
-
return await relayMessage(jid, productMsg.message, {
|
|
1273
|
-
messageId: productMsg.key.id,
|
|
1274
|
-
...getParticipantAttr()
|
|
1275
|
-
});
|
|
1276
|
-
|
|
1277
|
-
case 'INTERACTIVE':
|
|
1278
|
-
const interactiveContent = await kelvdra.handleInteractive(content, jid, quoted);
|
|
1279
|
-
const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
|
|
1280
|
-
return await relayMessage(jid, interactiveMsg.message, {
|
|
1281
|
-
messageId: interactiveMsg.key.id,
|
|
1282
|
-
...getParticipantAttr()
|
|
1283
|
-
});
|
|
1284
|
-
case 'ALBUM':
|
|
1285
|
-
const albumContent = await kelvdra.handleAlbum(content, jid, quoted)
|
|
1286
|
-
return albumContent;
|
|
1287
|
-
|
|
1288
|
-
case 'EVENT':
|
|
1289
|
-
return await kelvdra.handleEvent(content, jid, quoted)
|
|
1290
|
-
|
|
1291
|
-
case 'POLL_RESULT':
|
|
1292
|
-
return await kelvdra.handlePollResult(content, jid, quoted)
|
|
1293
|
-
|
|
1294
|
-
case 'CAROUSEL':
|
|
1295
|
-
return await kelvdra.handleCarousel(content, jid, quoted);
|
|
1296
|
-
|
|
1297
|
-
case 'OLD_BUTTON':
|
|
1298
|
-
return await kelvdra.handleOldButtons(content, jid, quoted);
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
938
|
if (typeof content === 'object' &&
|
|
1302
939
|
'disappearingMessagesInChat' in content &&
|
|
1303
940
|
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
@@ -1380,7 +1017,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
1380
1017
|
});
|
|
1381
1018
|
if (config.emitOwnEvents) {
|
|
1382
1019
|
process.nextTick(async () => {
|
|
1383
|
-
await
|
|
1020
|
+
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
1384
1021
|
});
|
|
1385
1022
|
}
|
|
1386
1023
|
return fullMsg;
|