wolfsocket 1.0.6 → 1.0.7
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/WAProto.proto +10 -1
- package/WAProto/index.d.ts +26 -0
- package/WAProto/index.js +18415 -8908
- package/lib/Defaults/index.d.ts +6 -0
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +18 -1
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Signal/lid-mapping.js +1 -1
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/business.d.ts +174 -6
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/channelPollVote.d.ts +44 -0
- package/lib/Socket/channelPollVote.d.ts.map +1 -0
- package/lib/Socket/channelPollVote.js +65 -0
- package/lib/Socket/channelPollVote.js.map +1 -0
- package/lib/Socket/channelSchedule.d.ts +229 -0
- package/lib/Socket/channelSchedule.d.ts.map +1 -0
- package/lib/Socket/channelSchedule.js +465 -0
- package/lib/Socket/channelSchedule.js.map +1 -0
- package/lib/Socket/channelStatus.d.ts +317 -0
- package/lib/Socket/channelStatus.d.ts.map +1 -0
- package/lib/Socket/channelStatus.js +479 -0
- package/lib/Socket/channelStatus.js.map +1 -0
- package/lib/Socket/chats.d.ts +30 -5
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +117 -2
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +176 -7
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/communities.js +22 -6
- package/lib/Socket/communities.js.map +1 -1
- package/lib/Socket/groupHistory.d.ts +38 -0
- package/lib/Socket/groupHistory.d.ts.map +1 -0
- package/lib/Socket/groupHistory.js +88 -0
- package/lib/Socket/groupHistory.js.map +1 -0
- package/lib/Socket/groupStatus.d.ts +6 -0
- package/lib/Socket/groupStatus.d.ts.map +1 -1
- package/lib/Socket/groupStatus.js +19 -3
- package/lib/Socket/groupStatus.js.map +1 -1
- package/lib/Socket/groups.d.ts +11 -5
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +9 -2
- package/lib/Socket/groups.js.map +1 -1
- package/lib/Socket/index.d.ts +174 -6
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/messages-recv.d.ts +174 -6
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +152 -34
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +211 -8
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +510 -133
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/newsletter.d.ts +11 -5
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletterDirectory.d.ts +201 -0
- package/lib/Socket/newsletterDirectory.d.ts.map +1 -0
- package/lib/Socket/newsletterDirectory.js +291 -0
- package/lib/Socket/newsletterDirectory.js.map +1 -0
- package/lib/Socket/payment.d.ts +37 -0
- package/lib/Socket/payment.d.ts.map +1 -0
- package/lib/Socket/payment.js +124 -0
- package/lib/Socket/payment.js.map +1 -0
- package/lib/Socket/report.d.ts +70 -0
- package/lib/Socket/report.d.ts.map +1 -0
- package/lib/Socket/report.js +265 -0
- package/lib/Socket/report.js.map +1 -0
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +17 -5
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Socket/stickerPack.d.ts +29 -0
- package/lib/Socket/stickerPack.d.ts.map +1 -0
- package/lib/Socket/stickerPack.js +130 -0
- package/lib/Socket/stickerPack.js.map +1 -0
- package/lib/Socket/username.d.ts +55 -0
- package/lib/Socket/username.d.ts.map +1 -0
- package/lib/Socket/username.js +114 -0
- package/lib/Socket/username.js.map +1 -0
- package/lib/Types/ChannelStatus.d.ts +34 -0
- package/lib/Types/ChannelStatus.d.ts.map +1 -0
- package/lib/Types/ChannelStatus.js +2 -0
- package/lib/Types/ChannelStatus.js.map +1 -0
- package/lib/Types/Chat.d.ts +17 -0
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Chat.js.map +1 -1
- package/lib/Types/Events.d.ts +4 -0
- package/lib/Types/Events.d.ts.map +1 -1
- package/lib/Types/GroupMetadata.d.ts +2 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -1
- package/lib/Types/Message.d.ts +123 -3
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Payment.d.ts +47 -0
- package/lib/Types/Payment.d.ts.map +1 -0
- package/lib/Types/Payment.js +2 -0
- package/lib/Types/Payment.js.map +1 -0
- package/lib/Types/Report.d.ts +219 -0
- package/lib/Types/Report.d.ts.map +1 -0
- package/lib/Types/Report.js +166 -0
- package/lib/Types/Report.js.map +1 -0
- package/lib/Types/StickerPack.d.ts +52 -0
- package/lib/Types/StickerPack.d.ts.map +1 -0
- package/lib/Types/StickerPack.js +2 -0
- package/lib/Types/StickerPack.js.map +1 -0
- package/lib/Types/Username.d.ts +19 -0
- package/lib/Types/Username.d.ts.map +1 -0
- package/lib/Types/Username.js +2 -0
- package/lib/Types/Username.js.map +1 -0
- package/lib/Types/index.d.ts +5 -0
- package/lib/Types/index.d.ts.map +1 -1
- package/lib/Types/index.js +5 -0
- package/lib/Types/index.js.map +1 -1
- package/lib/Utils/chat-utils.d.ts.map +1 -1
- package/lib/Utils/chat-utils.js +19 -1
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +4 -1
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.js +21 -1
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.js +1 -1
- package/lib/Utils/group-history.d.ts +37 -0
- package/lib/Utils/group-history.d.ts.map +1 -0
- package/lib/Utils/group-history.js +55 -0
- package/lib/Utils/group-history.js.map +1 -0
- package/lib/Utils/index.d.ts +3 -0
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +3 -0
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview.d.ts.map +1 -1
- package/lib/Utils/link-preview.js +21 -7
- package/lib/Utils/link-preview.js.map +1 -1
- package/lib/Utils/message-retry-manager.d.ts +4 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.js +11 -0
- package/lib/Utils/message-retry-manager.js.map +1 -1
- package/lib/Utils/messages-media.d.ts +25 -9
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +114 -27
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +89 -2
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +414 -15
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/offline-node-processor.d.ts +1 -1
- package/lib/Utils/offline-node-processor.d.ts.map +1 -1
- package/lib/Utils/process-message.d.ts +25 -0
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +60 -2
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/reporting-utils.d.ts +7 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -1
- package/lib/Utils/reporting-utils.js +7 -0
- package/lib/Utils/reporting-utils.js.map +1 -1
- package/lib/Utils/sync-key-auto-resolve.d.ts +10 -0
- package/lib/Utils/sync-key-auto-resolve.d.ts.map +1 -0
- package/lib/Utils/sync-key-auto-resolve.js +33 -0
- package/lib/Utils/sync-key-auto-resolve.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -1
- package/lib/Utils/use-multi-file-auth-state.js +34 -2
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -1
- package/lib/Utils/validate-connection.d.ts.map +1 -1
- package/lib/Utils/validate-connection.js +3 -2
- package/lib/Utils/validate-connection.js.map +1 -1
- package/lib/Utils/zip.d.ts +11 -0
- package/lib/Utils/zip.d.ts.map +1 -0
- package/lib/Utils/zip.js +88 -0
- package/lib/Utils/zip.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +7 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +88 -0
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/package.json +3 -3
|
@@ -2,19 +2,78 @@ 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 {
|
|
5
|
+
import { SPAM_FLOWS, SPAM_REPORT_REASONS } from '../Types/Report.js';
|
|
6
|
+
import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, decryptMediaRetryData, DEF_MEDIA_HOST, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, encryptPollVote, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, getKeyAuthor, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, isViewOnceMessage, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, sha256, shouldIncludeBizBinaryNode, unixTimestampSeconds } from '../Utils/index.js';
|
|
6
7
|
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
7
8
|
import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex.js';
|
|
8
9
|
import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
|
|
9
|
-
import { sendGroupStatus } from './groupStatus.js';
|
|
10
10
|
import { buildMergedTcTokenIndexWrite, isTcTokenExpired, resolveIssuanceJid, resolveTcTokenJid, shouldSendNewTcToken, storeTcTokensFromIqResult } from '../Utils/tc-token-utils.js';
|
|
11
|
-
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidBot, isJidGroup, isJidMetaAI, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, PSA_WID, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
11
|
+
import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, getBizBinaryNode, isHostedLidUser, isHostedPnUser, isJidBot, isJidGroup, isJidMetaAI, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, PSA_WID, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
12
12
|
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
13
|
+
import { CHANNEL_STATUS_ECHO_TIMEOUT_MS, fetchChannelStatusResponses, fetchChannelStatuses, reactChannelStatus, revokeChannelStatus, sendChannelStatus, sendChannelStatusViewReceipt } from './channelStatus.js';
|
|
14
|
+
import { newsletterSendPollVote as sendNewsletterPollVote } from './channelPollVote.js';
|
|
15
|
+
import { cancelChannelPost, fetchChannelScheduledPosts, rescheduleChannelPost, scheduleChannelPost, sendChannelPostNow } from './channelSchedule.js';
|
|
16
|
+
import { newsletterDirectoryList as listNewsletterDirectory, newsletterDirectorySearch as searchNewsletterDirectory } from './newsletterDirectory.js';
|
|
17
|
+
import { sendGroupHistory } from './groupHistory.js';
|
|
18
|
+
import { sendGroupStatus } from './groupStatus.js';
|
|
13
19
|
import { makeNewsletterSocket } from './newsletter.js';
|
|
20
|
+
import { cancelPaymentRequest, declinePaymentRequest, requestPayment, sendPayment, sendPaymentInvite } from './payment.js';
|
|
21
|
+
import { reportAndBlock, reportChannelStatus, reportContact, reportEvent, reportGroup, reportNewsletter, reportSpam, reportStatus, reportTarget } from './report.js';
|
|
22
|
+
import { sendStickerPack } from './stickerPack.js';
|
|
23
|
+
import { checkUsername, checkUsernameMulti, deleteUsername, fetchContactUsernames, findUserByUsername, getMyUsername, getUsernameRecommendations, setUsername, setUsernamePin, setUsernameQueryIds, USERNAME_CHECK_RESULT, USERNAME_QUERY_IDS, USERNAME_SOURCE } from './username.js';
|
|
24
|
+
/**
|
|
25
|
+
* Whether a device JID is one of our own devices. A LID device is compared with
|
|
26
|
+
* our LID and any other device with our PN: areJidsSameUser compares only the
|
|
27
|
+
* user part, and a PN can share its digits with our LID.
|
|
28
|
+
*/
|
|
29
|
+
export const isOwnDeviceJid = (jid, meId, meLid) => isLidUser(jid) || isHostedLidUser(jid) ? !!meLid && areJidsSameUser(jid, meLid) : areJidsSameUser(jid, meId);
|
|
30
|
+
/**
|
|
31
|
+
* Stanza addressing for a resend to a single device (a retry). A resend to one
|
|
32
|
+
* of our own devices must name the chat as `recipient`; that device is
|
|
33
|
+
* addressed by LID as well as by PN, as handleReceipt already assumes.
|
|
34
|
+
*/
|
|
35
|
+
export const buildRetryResendAddressing = (destinationJid, participantJid, meId, meLid) => {
|
|
36
|
+
if (isJidGroup(destinationJid)) {
|
|
37
|
+
return { to: destinationJid, participant: participantJid };
|
|
38
|
+
}
|
|
39
|
+
if (isOwnDeviceJid(participantJid, meId, meLid)) {
|
|
40
|
+
return { to: participantJid, recipient: destinationJid };
|
|
41
|
+
}
|
|
42
|
+
return { to: participantJid };
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Add the close-friends audience marker to status content.
|
|
46
|
+
* Any contextInfo already on the content (e.g. mentions) is kept.
|
|
47
|
+
* Exported for testing; the socket wrapper is
|
|
48
|
+
* sendCloseFriendsStatus.
|
|
49
|
+
*/
|
|
50
|
+
export const closeFriendsStatusContent = (content) => {
|
|
51
|
+
const existing = 'contextInfo' in content ? content.contextInfo : undefined;
|
|
52
|
+
return {
|
|
53
|
+
...content,
|
|
54
|
+
contextInfo: {
|
|
55
|
+
...existing,
|
|
56
|
+
statusAudienceMetadata: {
|
|
57
|
+
audienceType: proto.ContextInfo.StatusAudienceMetadata.AudienceType.CLOSE_FRIENDS
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Build the receipt key used to mark a status as viewed.
|
|
64
|
+
* The key is read as someone else's message (fromMe: false) with
|
|
65
|
+
* the status author as participant.
|
|
66
|
+
* Exported for testing; the socket wrapper is markStatusViewed.
|
|
67
|
+
*/
|
|
68
|
+
export const buildStatusViewKey = (key, participant) => ({
|
|
69
|
+
...key,
|
|
70
|
+
fromMe: false,
|
|
71
|
+
participant
|
|
72
|
+
});
|
|
14
73
|
export const makeMessagesSocket = (config) => {
|
|
15
|
-
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
|
|
74
|
+
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount, getMessage } = config;
|
|
16
75
|
const sock = makeNewsletterSocket(config);
|
|
17
|
-
const { ev, authState, messageMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, registerSocketEndHandler } = sock;
|
|
76
|
+
const { ev, authState, messageMutex, signalRepository, upsertMessage, query, generateMessageTag, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, registerSocketEndHandler } = sock;
|
|
18
77
|
const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
|
|
19
78
|
/**
|
|
20
79
|
* Set of tctoken storage JIDs with a fire-and-forget `issuePrivacyTokens` IQ in flight.
|
|
@@ -340,22 +399,20 @@ export const makeMessagesSocket = (config) => {
|
|
|
340
399
|
}
|
|
341
400
|
return didFetchNewSession;
|
|
342
401
|
};
|
|
343
|
-
const
|
|
344
|
-
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
|
402
|
+
const sendPeerMessage = async (protocolMessage) => {
|
|
345
403
|
if (!authState.creds.me?.id) {
|
|
346
404
|
throw new Boom('Not authenticated');
|
|
347
405
|
}
|
|
348
|
-
const protocolMessage = {
|
|
349
|
-
protocolMessage: {
|
|
350
|
-
peerDataOperationRequestMessage: pdoMessage,
|
|
351
|
-
type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
406
|
const meJid = jidNormalizedUser(authState.creds.me.id);
|
|
355
|
-
|
|
407
|
+
// On-demand history sync must carry privacy_sensitive: '1' or the
|
|
408
|
+
// server drops the request silently (upstream #2853).
|
|
409
|
+
const isHistorySync = protocolMessage?.peerDataOperationRequestMessage?.peerDataOperationRequestType ===
|
|
410
|
+
proto.Message.PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND;
|
|
411
|
+
const msgId = await relayMessage(meJid, { protocolMessage }, {
|
|
356
412
|
additionalAttributes: {
|
|
357
413
|
category: 'peer',
|
|
358
|
-
push_priority: 'high_force'
|
|
414
|
+
push_priority: 'high_force',
|
|
415
|
+
...(isHistorySync ? { privacy_sensitive: '1' } : {})
|
|
359
416
|
},
|
|
360
417
|
additionalNodes: [
|
|
361
418
|
{
|
|
@@ -366,6 +423,34 @@ export const makeMessagesSocket = (config) => {
|
|
|
366
423
|
});
|
|
367
424
|
return msgId;
|
|
368
425
|
};
|
|
426
|
+
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
|
427
|
+
return sendPeerMessage({
|
|
428
|
+
peerDataOperationRequestMessage: pdoMessage,
|
|
429
|
+
type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
// Ask the phone (primary device) to share app-state sync keys we are
|
|
433
|
+
// missing, e.g. the rotated key the server now encrypts chat state with.
|
|
434
|
+
// Mirrors whatsmeow's requestAppStateKeys: a peer protocol message of
|
|
435
|
+
// type APP_STATE_SYNC_KEY_REQUEST, sent to our own JID. The phone is
|
|
436
|
+
// expected to answer with an APP_STATE_SYNC_KEY_SHARE, which Baileys
|
|
437
|
+
// already handles in process-message.ts (stores the key, emits
|
|
438
|
+
// creds.update with myAppStateKeyId). Whatsmeow throttles this to one
|
|
439
|
+
// request per key per 24h; callers should do the same. Unproven whether
|
|
440
|
+
// the phone answers for a rotated key on an imported (non-linked) session.
|
|
441
|
+
const requestAppStateSyncKey = async (keyIds) => {
|
|
442
|
+
if (!keyIds?.length) {
|
|
443
|
+
throw new Boom('At least one app state sync key ID is required', { statusCode: 400 });
|
|
444
|
+
}
|
|
445
|
+
const msgId = await sendPeerMessage({
|
|
446
|
+
type: proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_REQUEST,
|
|
447
|
+
appStateSyncKeyRequest: {
|
|
448
|
+
keyIds: keyIds.map(keyId => ({ keyId: Buffer.from(keyId, 'base64') }))
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
logger.info({ keyIds, msgId }, 'requested app state sync keys from phone');
|
|
452
|
+
return msgId;
|
|
453
|
+
};
|
|
369
454
|
const createParticipantNodes = async (recipientJids, message, extraAttrs, dsmMessage) => {
|
|
370
455
|
if (!recipientJids.length) {
|
|
371
456
|
return { nodes: [], shouldIncludeDeviceIdentity: false };
|
|
@@ -426,7 +511,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
426
511
|
}
|
|
427
512
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
428
513
|
};
|
|
429
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
|
|
514
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, addBizAttributes }) => {
|
|
430
515
|
const meId = assertMeId(authState.creds);
|
|
431
516
|
const meLid = authState.creds.me?.lid;
|
|
432
517
|
const isRetryResend = Boolean(participant?.jid);
|
|
@@ -455,16 +540,10 @@ export const makeMessagesSocket = (config) => {
|
|
|
455
540
|
messageContextInfo: message.messageContextInfo
|
|
456
541
|
};
|
|
457
542
|
const extraAttrs = {};
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
const { user, device } = jidDecode(participant.jid);
|
|
463
|
-
devices.push({
|
|
464
|
-
user,
|
|
465
|
-
device,
|
|
466
|
-
jid: participant.jid
|
|
467
|
-
});
|
|
543
|
+
// a retry resend is encrypted once, in the dedicated retry block below;
|
|
544
|
+
// adding the participant to the regular fan-out would encrypt it twice (479)
|
|
545
|
+
if (participant && !isGroup && !isStatus) {
|
|
546
|
+
additionalAttributes = { ...additionalAttributes, device_fanout: 'false' };
|
|
468
547
|
}
|
|
469
548
|
await authState.keys.transaction(async () => {
|
|
470
549
|
const mediaType = getMediaType(normalizeMessageContent(message) || message);
|
|
@@ -476,7 +555,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
476
555
|
const bytes = encodeNewsletterMessage(patched);
|
|
477
556
|
binaryNodeContent.push({
|
|
478
557
|
tag: 'plaintext',
|
|
479
|
-
attrs: {},
|
|
558
|
+
attrs: mediaType ? { mediatype: mediaType } : {},
|
|
480
559
|
content: bytes
|
|
481
560
|
});
|
|
482
561
|
const stanza = {
|
|
@@ -493,7 +572,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
493
572
|
await sendNode(stanza);
|
|
494
573
|
return;
|
|
495
574
|
}
|
|
496
|
-
if (normalizeMessageContent(message)?.pinInChatMessage || normalizeMessageContent(message)?.reactionMessage) {
|
|
575
|
+
if (normalizeMessageContent(message)?.pinInChatMessage || normalizeMessageContent(message)?.reactionMessage || normalizeMessageContent(message)?.pollUpdateMessage) {
|
|
497
576
|
extraAttrs['decrypt-fail'] = 'hide'; // todo: expand for reactions and other types
|
|
498
577
|
}
|
|
499
578
|
if (isGroupOrStatus && !isRetryResend) {
|
|
@@ -560,7 +639,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
560
639
|
//todo: revamp all this logic
|
|
561
640
|
// the goal is to follow with what I said above for each group, and instead of a true false map of ids, we can set an array full of those the app has already sent pkmsgs
|
|
562
641
|
senderKeyRecipients.push(deviceJid);
|
|
563
|
-
senderKeyMap[deviceJid] = true;
|
|
564
642
|
}
|
|
565
643
|
}
|
|
566
644
|
if (senderKeyRecipients.length) {
|
|
@@ -576,6 +654,12 @@ export const makeMessagesSocket = (config) => {
|
|
|
576
654
|
const result = await createParticipantNodes(senderKeyRecipients, senderKeyMsg, extraAttrs);
|
|
577
655
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
|
|
578
656
|
participants.push(...result.nodes);
|
|
657
|
+
// A prepared SKDM is tracked per device; failed encryptions must be retried on the next send.
|
|
658
|
+
for (const { attrs } of result.nodes) {
|
|
659
|
+
if (attrs.jid) {
|
|
660
|
+
senderKeyMap[attrs.jid] = true;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
579
663
|
}
|
|
580
664
|
binaryNodeContent.push({
|
|
581
665
|
tag: 'enc',
|
|
@@ -669,8 +753,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
669
753
|
shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
|
|
670
754
|
}
|
|
671
755
|
if (isRetryResend) {
|
|
672
|
-
const
|
|
673
|
-
const isMe = areJidsSameUser(participant.jid, isParticipantLid ? meLid : meId);
|
|
756
|
+
const isMe = isOwnDeviceJid(participant.jid, meId, meLid);
|
|
674
757
|
let messageToSend = message;
|
|
675
758
|
if (isGroupOrStatus) {
|
|
676
759
|
let groupSenderIdentity;
|
|
@@ -707,6 +790,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
707
790
|
}
|
|
708
791
|
})
|
|
709
792
|
: encodeWAMessage(messageToSend);
|
|
793
|
+
await assertSessions([participant.jid]);
|
|
710
794
|
const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({
|
|
711
795
|
data: encodedMessageToSend,
|
|
712
796
|
jid: participant.jid
|
|
@@ -750,17 +834,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
750
834
|
// ensure the message is only sent to that person
|
|
751
835
|
// if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
|
|
752
836
|
if (participant) {
|
|
753
|
-
|
|
754
|
-
stanza.attrs.to = destinationJid;
|
|
755
|
-
stanza.attrs.participant = participant.jid;
|
|
756
|
-
}
|
|
757
|
-
else if (areJidsSameUser(participant.jid, meId)) {
|
|
758
|
-
stanza.attrs.to = participant.jid;
|
|
759
|
-
stanza.attrs.recipient = destinationJid;
|
|
760
|
-
}
|
|
761
|
-
else {
|
|
762
|
-
stanza.attrs.to = participant.jid;
|
|
763
|
-
}
|
|
837
|
+
Object.assign(stanza.attrs, buildRetryResendAddressing(destinationJid, participant.jid, meId, meLid));
|
|
764
838
|
}
|
|
765
839
|
else {
|
|
766
840
|
stanza.attrs.to = destinationJid;
|
|
@@ -774,6 +848,12 @@ export const makeMessagesSocket = (config) => {
|
|
|
774
848
|
});
|
|
775
849
|
logger.debug({ jid }, 'adding device identity');
|
|
776
850
|
}
|
|
851
|
+
// WA Web marks view once sends at the stanza level too, not just in the
|
|
852
|
+
// protobuf wrapper. Adding it here also covers retry resends.
|
|
853
|
+
if (isViewOnceMessage(message)) {
|
|
854
|
+
;
|
|
855
|
+
stanza.content.push({ tag: 'meta', attrs: { view_once: 'true' } });
|
|
856
|
+
}
|
|
777
857
|
if (!isNewsletter &&
|
|
778
858
|
!isRetryResend &&
|
|
779
859
|
reportingMessage?.messageContextInfo?.messageSecret &&
|
|
@@ -828,9 +908,19 @@ export const makeMessagesSocket = (config) => {
|
|
|
828
908
|
content: tcTokenBuffer
|
|
829
909
|
});
|
|
830
910
|
}
|
|
911
|
+
let alreadyHasBizNode = false;
|
|
831
912
|
if (additionalNodes && additionalNodes.length > 0) {
|
|
832
913
|
;
|
|
833
914
|
stanza.content.push(...additionalNodes);
|
|
915
|
+
alreadyHasBizNode = !addBizAttributes && additionalNodes.some(node => node.tag === 'biz');
|
|
916
|
+
}
|
|
917
|
+
const normalizedMsg = normalizeMessageContent(message);
|
|
918
|
+
// Biz binary node: required for buttons/list/template/native-flow
|
|
919
|
+
// messages to render (and for the secureMetaServiceLabel biz shelf).
|
|
920
|
+
if (normalizedMsg &&
|
|
921
|
+
((!alreadyHasBizNode && shouldIncludeBizBinaryNode(normalizedMsg)) || addBizAttributes)) {
|
|
922
|
+
;
|
|
923
|
+
stanza.content.push(getBizBinaryNode(normalizedMsg));
|
|
834
924
|
}
|
|
835
925
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
836
926
|
await sendNode(stanza);
|
|
@@ -893,7 +983,8 @@ export const makeMessagesSocket = (config) => {
|
|
|
893
983
|
if (normalizedMessage.pollCreationMessage ||
|
|
894
984
|
normalizedMessage.pollCreationMessageV2 ||
|
|
895
985
|
normalizedMessage.pollCreationMessageV3 ||
|
|
896
|
-
normalizedMessage.pollUpdateMessage
|
|
986
|
+
normalizedMessage.pollUpdateMessage ||
|
|
987
|
+
normalizedMessage.pollAddOptionMessage) {
|
|
897
988
|
return 'poll';
|
|
898
989
|
}
|
|
899
990
|
if (normalizedMessage.eventMessage) {
|
|
@@ -989,6 +1080,264 @@ export const makeMessagesSocket = (config) => {
|
|
|
989
1080
|
messageRetryManager.clear();
|
|
990
1081
|
}
|
|
991
1082
|
});
|
|
1083
|
+
const usernameDeps = {
|
|
1084
|
+
query,
|
|
1085
|
+
generateMessageTag,
|
|
1086
|
+
executeUSyncQuery: sock.executeUSyncQuery
|
|
1087
|
+
};
|
|
1088
|
+
const reportDeps = {
|
|
1089
|
+
query,
|
|
1090
|
+
meJid: authState.creds.me?.id,
|
|
1091
|
+
updateBlockStatus: sock.updateBlockStatus
|
|
1092
|
+
};
|
|
1093
|
+
const stickerPackDeps = {
|
|
1094
|
+
relayMessage,
|
|
1095
|
+
upload: waUploadToServer,
|
|
1096
|
+
userJid: authState.creds.me?.id,
|
|
1097
|
+
logger
|
|
1098
|
+
};
|
|
1099
|
+
const paymentDeps = {
|
|
1100
|
+
relayMessage,
|
|
1101
|
+
userJid: authState.creds.me?.id,
|
|
1102
|
+
meJid: authState.creds.me?.id
|
|
1103
|
+
};
|
|
1104
|
+
/**
|
|
1105
|
+
* Delete a message for everyone (revoke) — it is removed for all
|
|
1106
|
+
* participants. In a group, an admin can delete someone else's message.
|
|
1107
|
+
*/
|
|
1108
|
+
const deleteMessage = async (jid, key) => {
|
|
1109
|
+
const fullMsg = await generateWAMessage(jid, { delete: key }, {
|
|
1110
|
+
logger,
|
|
1111
|
+
userJid: authState.creds.me.id,
|
|
1112
|
+
upload: waUploadToServer,
|
|
1113
|
+
messageId: generateMessageIDV2(sock.user?.id)
|
|
1114
|
+
});
|
|
1115
|
+
await relayMessage(jid, fullMsg.message, {
|
|
1116
|
+
messageId: fullMsg.key.id,
|
|
1117
|
+
additionalAttributes: {
|
|
1118
|
+
// group + not the author => delete as an admin
|
|
1119
|
+
edit: isJidGroup(key.remoteJid) && !key.fromMe ? '8' : '7'
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
if (config.emitOwnEvents) {
|
|
1123
|
+
process.nextTick(async () => {
|
|
1124
|
+
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
return fullMsg;
|
|
1128
|
+
};
|
|
1129
|
+
const sendMessage = async (jid, content, options = {}) => {
|
|
1130
|
+
const userJid = authState.creds.me.id;
|
|
1131
|
+
if (typeof content === 'object' &&
|
|
1132
|
+
'disappearingMessagesInChat' in content &&
|
|
1133
|
+
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
1134
|
+
isJidGroup(jid)) {
|
|
1135
|
+
const { disappearingMessagesInChat } = content;
|
|
1136
|
+
const value = typeof disappearingMessagesInChat === 'boolean'
|
|
1137
|
+
? disappearingMessagesInChat
|
|
1138
|
+
? WA_DEFAULT_EPHEMERAL
|
|
1139
|
+
: 0
|
|
1140
|
+
: disappearingMessagesInChat;
|
|
1141
|
+
await groupToggleEphemeral(jid, value);
|
|
1142
|
+
}
|
|
1143
|
+
else {
|
|
1144
|
+
const fullMsg = await generateWAMessage(jid, content, {
|
|
1145
|
+
logger,
|
|
1146
|
+
userJid,
|
|
1147
|
+
getUrlInfo: text => getUrlInfo(text, {
|
|
1148
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1149
|
+
fetchOpts: {
|
|
1150
|
+
timeout: 3000,
|
|
1151
|
+
...(httpRequestOptions || {})
|
|
1152
|
+
},
|
|
1153
|
+
logger,
|
|
1154
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1155
|
+
}),
|
|
1156
|
+
//TODO: CACHE
|
|
1157
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
1158
|
+
getCallLink: sock.createCallLink,
|
|
1159
|
+
upload: waUploadToServer,
|
|
1160
|
+
mediaCache: config.mediaCache,
|
|
1161
|
+
options: config.options,
|
|
1162
|
+
messageId: generateMessageIDV2(sock.user?.id),
|
|
1163
|
+
...options
|
|
1164
|
+
});
|
|
1165
|
+
const isEventMsg = 'event' in content && !!content.event;
|
|
1166
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
1167
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
|
1168
|
+
const isPinMsg = 'pin' in content && !!content.pin;
|
|
1169
|
+
const isPollMessage = 'poll' in content && !!content.poll;
|
|
1170
|
+
const additionalAttributes = {};
|
|
1171
|
+
const additionalNodes = [];
|
|
1172
|
+
// required for delete
|
|
1173
|
+
if (isDeleteMsg) {
|
|
1174
|
+
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
1175
|
+
if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
1176
|
+
additionalAttributes.edit = '8';
|
|
1177
|
+
}
|
|
1178
|
+
else {
|
|
1179
|
+
additionalAttributes.edit = '7';
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
else if (isEditMsg) {
|
|
1183
|
+
additionalAttributes.edit = '1';
|
|
1184
|
+
}
|
|
1185
|
+
else if (isPinMsg) {
|
|
1186
|
+
additionalAttributes.edit = '2';
|
|
1187
|
+
}
|
|
1188
|
+
else if (isPollMessage) {
|
|
1189
|
+
additionalNodes.push({
|
|
1190
|
+
tag: 'meta',
|
|
1191
|
+
attrs: {
|
|
1192
|
+
polltype: 'creation'
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
else if (isEventMsg) {
|
|
1197
|
+
additionalNodes.push({
|
|
1198
|
+
tag: 'meta',
|
|
1199
|
+
attrs: {
|
|
1200
|
+
event_type: 'creation'
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
// Interactive messages in 1:1 chats also carry the `bot` node
|
|
1205
|
+
// (gifted-btns does the same for private chats).
|
|
1206
|
+
if (!isJidGroup(jid) &&
|
|
1207
|
+
('nativeFlow' in content || 'interactiveButtons' in content)) {
|
|
1208
|
+
additionalNodes.push({ tag: 'bot', attrs: { biz_bot: '1' } });
|
|
1209
|
+
}
|
|
1210
|
+
await relayMessage(jid, fullMsg.message, {
|
|
1211
|
+
messageId: fullMsg.key.id,
|
|
1212
|
+
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1213
|
+
additionalAttributes,
|
|
1214
|
+
statusJidList: options.statusJidList,
|
|
1215
|
+
additionalNodes
|
|
1216
|
+
});
|
|
1217
|
+
if (config.emitOwnEvents) {
|
|
1218
|
+
process.nextTick(async () => {
|
|
1219
|
+
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
return fullMsg;
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
/**
|
|
1226
|
+
* Pin a message in a chat for everyone, for `duration` seconds.
|
|
1227
|
+
* The server accepts 24 hours (86400), 7 days (604800) or
|
|
1228
|
+
* 30 days (2592000); defaults to 24 hours.
|
|
1229
|
+
*
|
|
1230
|
+
* Safety: the message must exist in the chat first. Pinning a
|
|
1231
|
+
* message that is not there gets the account flagged, so the pin
|
|
1232
|
+
* is only sent after the message is found in the store. A missing
|
|
1233
|
+
* message is refused here instead of sent.
|
|
1234
|
+
*/
|
|
1235
|
+
const pinMessage = async (jid, key, duration = 86400) => {
|
|
1236
|
+
if (key.remoteJid && key.remoteJid !== jid) {
|
|
1237
|
+
throw new Error(`refusing to pin message ${key.id}: it belongs to ${key.remoteJid}, not ${jid}`);
|
|
1238
|
+
}
|
|
1239
|
+
const found = typeof getMessage === 'function' ? await getMessage({ ...key, remoteJid: jid }) : undefined;
|
|
1240
|
+
if (!found) {
|
|
1241
|
+
throw new Error(`refusing to pin message ${key.id} in ${jid}: message not found in this chat`);
|
|
1242
|
+
}
|
|
1243
|
+
return sendMessage(jid, { pin: key, type: proto.PinInChat.Type.PIN_FOR_ALL, time: duration });
|
|
1244
|
+
};
|
|
1245
|
+
/** Remove a pin from a message in a chat. */
|
|
1246
|
+
const unpinMessage = async (jid, key) => {
|
|
1247
|
+
return sendMessage(jid, { pin: key, type: proto.PinInChat.Type.UNPIN_FOR_ALL });
|
|
1248
|
+
};
|
|
1249
|
+
/**
|
|
1250
|
+
* Post a personal status (story) visible to your contacts.
|
|
1251
|
+
* Same content shapes as sendMessage: { text }, { image, caption },
|
|
1252
|
+
* { video, caption }, { audio, ptt }, { sticker }, etc.
|
|
1253
|
+
*/
|
|
1254
|
+
const sendPersonalStatus = async (content, options = {}) => {
|
|
1255
|
+
return sendMessage('status@broadcast', content, options);
|
|
1256
|
+
};
|
|
1257
|
+
/**
|
|
1258
|
+
* Post a personal status visible only to the given close friends.
|
|
1259
|
+
* The status carries the close-friends audience marker and is
|
|
1260
|
+
* fanned out only to `closeFriendJids`.
|
|
1261
|
+
*/
|
|
1262
|
+
const sendCloseFriendsStatus = async (content, closeFriendJids, options = {}) => {
|
|
1263
|
+
return sendMessage('status@broadcast', closeFriendsStatusContent(content), {
|
|
1264
|
+
...options,
|
|
1265
|
+
statusJidList: closeFriendJids
|
|
1266
|
+
});
|
|
1267
|
+
};
|
|
1268
|
+
/**
|
|
1269
|
+
* Mark a status as viewed. `key` is the status message key —
|
|
1270
|
+
* group status keys carry the group JID, personal status keys
|
|
1271
|
+
* carry 'status@broadcast'. `participant` is the status author
|
|
1272
|
+
* and defaults to your own JID.
|
|
1273
|
+
*/
|
|
1274
|
+
const markStatusViewed = async (key, participant) => {
|
|
1275
|
+
await readMessages([buildStatusViewKey(key, participant ?? authState.creds.me?.id)]);
|
|
1276
|
+
};
|
|
1277
|
+
/**
|
|
1278
|
+
* React to a status (group or personal). `jid` is the group JID
|
|
1279
|
+
* for a group status, or 'status@broadcast' for a personal status
|
|
1280
|
+
* (pass your own JID in `statusJidList` for personal statuses,
|
|
1281
|
+
* as the reaction is fanned out to that list).
|
|
1282
|
+
*/
|
|
1283
|
+
const reactToStatus = async (jid, key, emoji, statusJidList) => {
|
|
1284
|
+
return sendMessage(jid, { react: { key, text: emoji } }, statusJidList ? { statusJidList } : {});
|
|
1285
|
+
};
|
|
1286
|
+
/**
|
|
1287
|
+
* Report spam two ways: by target JID (`sock.reportSpam(jid, options?)`,
|
|
1288
|
+
* one IQ, one summary) or by messages (`sock.reportSpam(messages,
|
|
1289
|
+
* options?)`, one IQ per message, one result per message).
|
|
1290
|
+
*/
|
|
1291
|
+
const reportSpamSocket = ((targetOrMessages, options = {}) => typeof targetOrMessages === 'string'
|
|
1292
|
+
? reportTarget(targetOrMessages, reportDeps, options)
|
|
1293
|
+
: reportSpam(targetOrMessages, reportDeps, options));
|
|
1294
|
+
/**
|
|
1295
|
+
* Vote on a poll by option name. The vote is encrypted with the poll
|
|
1296
|
+
* creation message's secret, so pass it in `pollInfo` — the fork does
|
|
1297
|
+
* not look the creation message up in any store. `creatorJid` defaults
|
|
1298
|
+
* to the author of `pollCreationMessageKey` (the same derivation the
|
|
1299
|
+
* vote decryption uses). The voter JID is the bot's LID when the poll
|
|
1300
|
+
* is LID-addressed, else its phone JID — receivers decrypt with the
|
|
1301
|
+
* voter JID from the vote message's key, so the wrong form makes the
|
|
1302
|
+
* vote undecryptable and it never counts. The vote is sent through the
|
|
1303
|
+
* raw pollUpdateMessage passthrough, so no new send plumbing was needed.
|
|
1304
|
+
*/
|
|
1305
|
+
const sendPollVote = async (jid, pollCreationMessageKey, options, pollInfo) => {
|
|
1306
|
+
const meIdNormalised = jidNormalizedUser(assertMeId(authState.creds));
|
|
1307
|
+
const meLidNormalised = authState.creds.me?.lid ? jidNormalizedUser(authState.creds.me.lid) : null;
|
|
1308
|
+
const pollMsgId = pollCreationMessageKey.id;
|
|
1309
|
+
if (!pollMsgId) {
|
|
1310
|
+
throw new Boom('pollCreationMessageKey needs an id', { statusCode: 400 });
|
|
1311
|
+
}
|
|
1312
|
+
const optionNames = Array.isArray(options) ? options : [options];
|
|
1313
|
+
if (!optionNames.length) {
|
|
1314
|
+
throw new Boom('sendPollVote needs at least one option', { statusCode: 400 });
|
|
1315
|
+
}
|
|
1316
|
+
// The vote is decrypted by other clients with the voter JID from the
|
|
1317
|
+
// vote message's key. In a LID-addressed group that is the voter's
|
|
1318
|
+
// LID, but meIdNormalised is the phone JID — encrypting with it makes
|
|
1319
|
+
// the vote fail AES-GCM auth on every client so it never counts, even
|
|
1320
|
+
// though the send succeeds (2026-11-21, "Alice" poll: vote reported
|
|
1321
|
+
// sent with an ID but the poll stayed 0/0). Use the LID when the poll
|
|
1322
|
+
// is LID-addressed.
|
|
1323
|
+
const creatorJid = pollInfo.creatorJid || getKeyAuthor(pollCreationMessageKey, meIdNormalised);
|
|
1324
|
+
const voterJid = (creatorJid.endsWith('@lid') || pollCreationMessageKey.participant?.endsWith('@lid') || pollCreationMessageKey.addressingMode === 'lid') && meLidNormalised
|
|
1325
|
+
? meLidNormalised
|
|
1326
|
+
: meIdNormalised;
|
|
1327
|
+
const vote = encryptPollVote({ selectedOptions: optionNames.map(name => sha256(Buffer.from(name))) }, {
|
|
1328
|
+
pollCreatorJid: creatorJid,
|
|
1329
|
+
pollMsgId,
|
|
1330
|
+
pollEncKey: pollInfo.messageSecret,
|
|
1331
|
+
voterJid
|
|
1332
|
+
});
|
|
1333
|
+
return sendMessage(jid, {
|
|
1334
|
+
pollUpdateMessage: {
|
|
1335
|
+
pollCreationMessageKey,
|
|
1336
|
+
vote,
|
|
1337
|
+
senderTimestampMs: Date.now()
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
};
|
|
992
1341
|
return {
|
|
993
1342
|
...sock,
|
|
994
1343
|
userDevicesCache,
|
|
@@ -999,8 +1348,121 @@ export const makeMessagesSocket = (config) => {
|
|
|
999
1348
|
sendGroupStatus: (jid, content, options = {}) => sendGroupStatus(jid, content, {
|
|
1000
1349
|
relayMessage,
|
|
1001
1350
|
waUploadToServer,
|
|
1351
|
+
userJid: authState.creds.me?.id,
|
|
1352
|
+
linkPreviewImageThumbnailWidth,
|
|
1353
|
+
generateHighQualityLinkPreview,
|
|
1354
|
+
httpRequestOptions,
|
|
1355
|
+
logger
|
|
1356
|
+
}, options),
|
|
1357
|
+
sendChannelStatus: (jid, content, options = {}) => sendChannelStatus(jid, content, {
|
|
1358
|
+
sendNode,
|
|
1359
|
+
waUploadToServer,
|
|
1002
1360
|
userJid: authState.creds.me?.id
|
|
1003
1361
|
}, options),
|
|
1362
|
+
newsletterSendStatus: async (jid, content, options = {}) => {
|
|
1363
|
+
const sent = await sendChannelStatus(jid, content, {
|
|
1364
|
+
sendNode,
|
|
1365
|
+
waUploadToServer,
|
|
1366
|
+
userJid: authState.creds.me?.id
|
|
1367
|
+
}, options);
|
|
1368
|
+
// The server-assigned id of a posted status only arrives in the
|
|
1369
|
+
// server echo of that status (an incoming <status> stanza,
|
|
1370
|
+
// surfaced as 'newsletter.status'). The echo is a network round
|
|
1371
|
+
// trip away, so attaching the listener right after the send
|
|
1372
|
+
// cannot miss it. It is matched by the stanza id from the send.
|
|
1373
|
+
// If the echo does not arrive in time (or the server rejected
|
|
1374
|
+
// the post), the server id stays undefined — the send itself
|
|
1375
|
+
// already went out.
|
|
1376
|
+
const newsletterStatusServerId = await new Promise(resolve => {
|
|
1377
|
+
const onStatus = (status) => {
|
|
1378
|
+
if (status.channelJid === jid && status.id === sent.id) {
|
|
1379
|
+
clearTimeout(timer);
|
|
1380
|
+
ev.off('newsletter.status', onStatus);
|
|
1381
|
+
resolve(status.serverId);
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
const timer = setTimeout(() => {
|
|
1385
|
+
ev.off('newsletter.status', onStatus);
|
|
1386
|
+
resolve(undefined);
|
|
1387
|
+
}, CHANNEL_STATUS_ECHO_TIMEOUT_MS);
|
|
1388
|
+
ev.on('newsletter.status', onStatus);
|
|
1389
|
+
});
|
|
1390
|
+
return { ...sent, newsletterStatusServerId };
|
|
1391
|
+
},
|
|
1392
|
+
newsletterReactStatus: (jid, serverId, reaction) => reactChannelStatus(jid, serverId, reaction, { query, generateMessageTag }),
|
|
1393
|
+
newsletterRevokeStatus: (jid, statusId) => revokeChannelStatus(jid, statusId, { query, generateMessageTag }),
|
|
1394
|
+
newsletterFetchStatus: (jid, options) => fetchChannelStatuses(jid, options, { query, generateMessageTag }),
|
|
1395
|
+
newsletterFetchStatusResponses: (jid, serverId, options) => fetchChannelStatusResponses(jid, serverId, options, { query, generateMessageTag }),
|
|
1396
|
+
newsletterSendStatusViewReceipt: (jid, receiptStanzaId, sortId) => sendChannelStatusViewReceipt(jid, receiptStanzaId, sortId, { sendNode }),
|
|
1397
|
+
newsletterScheduleChannelPost: (jid, content, publishAtMs, options = {}) => scheduleChannelPost(jid, content, publishAtMs, {
|
|
1398
|
+
sendNode,
|
|
1399
|
+
waUploadToServer,
|
|
1400
|
+
userJid: authState.creds.me?.id
|
|
1401
|
+
}, options),
|
|
1402
|
+
newsletterRescheduleChannelPost: (jid, clientId, content, publishAtMs, options = {}) => rescheduleChannelPost(jid, clientId, content, publishAtMs, {
|
|
1403
|
+
sendNode,
|
|
1404
|
+
waUploadToServer,
|
|
1405
|
+
userJid: authState.creds.me?.id,
|
|
1406
|
+
query,
|
|
1407
|
+
generateMessageTag
|
|
1408
|
+
}, options),
|
|
1409
|
+
newsletterSendChannelPostNow: (jid, clientId, content, options = {}) => sendChannelPostNow(jid, clientId, content, {
|
|
1410
|
+
sendNode,
|
|
1411
|
+
waUploadToServer,
|
|
1412
|
+
userJid: authState.creds.me?.id,
|
|
1413
|
+
query,
|
|
1414
|
+
generateMessageTag
|
|
1415
|
+
}, options),
|
|
1416
|
+
newsletterCancelChannelPost: (jid, clientId) => cancelChannelPost(jid, clientId, { query, generateMessageTag }),
|
|
1417
|
+
newsletterFetchChannelScheduledPosts: (jid, options) => fetchChannelScheduledPosts(jid, options, { query, generateMessageTag }),
|
|
1418
|
+
newsletterDirectorySearch: (searchText, options = {}) => searchNewsletterDirectory(searchText, options, { query, generateMessageTag }),
|
|
1419
|
+
newsletterDirectoryList: (options = {}) => listNewsletterDirectory(options, { query, generateMessageTag }),
|
|
1420
|
+
pinMessage,
|
|
1421
|
+
unpinMessage,
|
|
1422
|
+
sendPersonalStatus,
|
|
1423
|
+
sendCloseFriendsStatus,
|
|
1424
|
+
markStatusViewed,
|
|
1425
|
+
reactToStatus,
|
|
1426
|
+
sendGroupHistory: (jid, receivers, messages, options = {}) => sendGroupHistory(jid, receivers, messages, {
|
|
1427
|
+
relayMessage,
|
|
1428
|
+
waUploadToServer,
|
|
1429
|
+
userJid: authState.creds.me?.id,
|
|
1430
|
+
logger
|
|
1431
|
+
}, options),
|
|
1432
|
+
checkUsername: (username, includeSuggestions = true, sessionId) => checkUsername(username, usernameDeps, includeSuggestions, sessionId),
|
|
1433
|
+
checkUsernameMulti: (usernames) => checkUsernameMulti(usernames, usernameDeps),
|
|
1434
|
+
setUsername: (username, options = {}) => setUsername(username, usernameDeps, options),
|
|
1435
|
+
deleteUsername: () => deleteUsername(usernameDeps),
|
|
1436
|
+
getMyUsername: () => getMyUsername(usernameDeps),
|
|
1437
|
+
getUsernameRecommendations: (source = null) => getUsernameRecommendations(usernameDeps, source),
|
|
1438
|
+
setUsernamePin: (pin) => setUsernamePin(pin, usernameDeps),
|
|
1439
|
+
findUserByUsername: (username, pin) => findUserByUsername(username, usernameDeps, pin),
|
|
1440
|
+
fetchContactUsernames: (...jids) => fetchContactUsernames(jids, usernameDeps),
|
|
1441
|
+
setUsernameQueryIds: (ids) => setUsernameQueryIds(ids),
|
|
1442
|
+
USERNAME_QUERY_IDS,
|
|
1443
|
+
USERNAME_CHECK_RESULT,
|
|
1444
|
+
USERNAME_SOURCE,
|
|
1445
|
+
reportSpam: reportSpamSocket,
|
|
1446
|
+
reportContact: (jid, messages, options = {}) => reportContact(jid, messages, reportDeps, options),
|
|
1447
|
+
reportGroup: (jid, messages, options = {}) => reportGroup(jid, messages, reportDeps, options),
|
|
1448
|
+
reportStatus: (jid, messages, options = {}) => reportStatus(jid, messages, reportDeps, options),
|
|
1449
|
+
reportNewsletter: (jid, messages, options = {}) => reportNewsletter(jid, messages, reportDeps, options),
|
|
1450
|
+
reportChannelStatus: (jid, messages, options = {}) => reportChannelStatus(jid, messages, reportDeps, options),
|
|
1451
|
+
reportEvent: (jid, messages, options = {}) => reportEvent(jid, messages, reportDeps, options),
|
|
1452
|
+
reportAndBlock: (jid, messages, options = {}) => reportAndBlock(jid, messages, reportDeps, options),
|
|
1453
|
+
SPAM_FLOWS,
|
|
1454
|
+
SPAM_REPORT_REASONS,
|
|
1455
|
+
getPNForLID: (lid) => signalRepository.lidMapping.getPNForLID(lid),
|
|
1456
|
+
getPNsForLIDs: (lids) => signalRepository.lidMapping.getPNsForLIDs(lids),
|
|
1457
|
+
getLIDForPN: (pn) => signalRepository.lidMapping.getLIDForPN(pn),
|
|
1458
|
+
getLIDsForPNs: (pns) => signalRepository.lidMapping.getLIDsForPNs(pns),
|
|
1459
|
+
sendStickerPack: (jid, pack) => sendStickerPack(jid, pack, stickerPackDeps),
|
|
1460
|
+
requestPayment: (jid, options) => requestPayment(jid, options, paymentDeps),
|
|
1461
|
+
sendPayment: (jid, options) => sendPayment(jid, options, paymentDeps),
|
|
1462
|
+
declinePaymentRequest: (jid, key) => declinePaymentRequest(jid, key, paymentDeps),
|
|
1463
|
+
cancelPaymentRequest: (jid, key) => cancelPaymentRequest(jid, key, paymentDeps),
|
|
1464
|
+
sendPaymentInvite: (jid, options = {}) => sendPaymentInvite(jid, options, paymentDeps),
|
|
1465
|
+
deleteMessage,
|
|
1004
1466
|
sendReceipt,
|
|
1005
1467
|
sendReceipts,
|
|
1006
1468
|
readMessages,
|
|
@@ -1010,6 +1472,8 @@ export const makeMessagesSocket = (config) => {
|
|
|
1010
1472
|
waUploadToServer,
|
|
1011
1473
|
fetchPrivacySettings,
|
|
1012
1474
|
sendPeerDataOperationMessage,
|
|
1475
|
+
sendPeerMessage,
|
|
1476
|
+
requestAppStateSyncKey,
|
|
1013
1477
|
createParticipantNodes,
|
|
1014
1478
|
getUSyncDevices,
|
|
1015
1479
|
messageRetryManager,
|
|
@@ -1056,96 +1520,9 @@ export const makeMessagesSocket = (config) => {
|
|
|
1056
1520
|
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
|
|
1057
1521
|
return message;
|
|
1058
1522
|
},
|
|
1059
|
-
sendMessage
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
'disappearingMessagesInChat' in content &&
|
|
1063
|
-
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
1064
|
-
isJidGroup(jid)) {
|
|
1065
|
-
const { disappearingMessagesInChat } = content;
|
|
1066
|
-
const value = typeof disappearingMessagesInChat === 'boolean'
|
|
1067
|
-
? disappearingMessagesInChat
|
|
1068
|
-
? WA_DEFAULT_EPHEMERAL
|
|
1069
|
-
: 0
|
|
1070
|
-
: disappearingMessagesInChat;
|
|
1071
|
-
await groupToggleEphemeral(jid, value);
|
|
1072
|
-
}
|
|
1073
|
-
else {
|
|
1074
|
-
const fullMsg = await generateWAMessage(jid, content, {
|
|
1075
|
-
logger,
|
|
1076
|
-
userJid,
|
|
1077
|
-
getUrlInfo: text => getUrlInfo(text, {
|
|
1078
|
-
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1079
|
-
fetchOpts: {
|
|
1080
|
-
timeout: 3000,
|
|
1081
|
-
...(httpRequestOptions || {})
|
|
1082
|
-
},
|
|
1083
|
-
logger,
|
|
1084
|
-
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1085
|
-
}),
|
|
1086
|
-
//TODO: CACHE
|
|
1087
|
-
getProfilePicUrl: sock.profilePictureUrl,
|
|
1088
|
-
getCallLink: sock.createCallLink,
|
|
1089
|
-
upload: waUploadToServer,
|
|
1090
|
-
mediaCache: config.mediaCache,
|
|
1091
|
-
options: config.options,
|
|
1092
|
-
messageId: generateMessageIDV2(sock.user?.id),
|
|
1093
|
-
...options
|
|
1094
|
-
});
|
|
1095
|
-
const isEventMsg = 'event' in content && !!content.event;
|
|
1096
|
-
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
1097
|
-
const isEditMsg = 'edit' in content && !!content.edit;
|
|
1098
|
-
const isPinMsg = 'pin' in content && !!content.pin;
|
|
1099
|
-
const isPollMessage = 'poll' in content && !!content.poll;
|
|
1100
|
-
const additionalAttributes = {};
|
|
1101
|
-
const additionalNodes = [];
|
|
1102
|
-
// required for delete
|
|
1103
|
-
if (isDeleteMsg) {
|
|
1104
|
-
// if the chat is a group, and I am not the author, then delete the message as an admin
|
|
1105
|
-
if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
|
|
1106
|
-
additionalAttributes.edit = '8';
|
|
1107
|
-
}
|
|
1108
|
-
else {
|
|
1109
|
-
additionalAttributes.edit = '7';
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
else if (isEditMsg) {
|
|
1113
|
-
additionalAttributes.edit = '1';
|
|
1114
|
-
}
|
|
1115
|
-
else if (isPinMsg) {
|
|
1116
|
-
additionalAttributes.edit = '2';
|
|
1117
|
-
}
|
|
1118
|
-
else if (isPollMessage) {
|
|
1119
|
-
additionalNodes.push({
|
|
1120
|
-
tag: 'meta',
|
|
1121
|
-
attrs: {
|
|
1122
|
-
polltype: 'creation'
|
|
1123
|
-
}
|
|
1124
|
-
});
|
|
1125
|
-
}
|
|
1126
|
-
else if (isEventMsg) {
|
|
1127
|
-
additionalNodes.push({
|
|
1128
|
-
tag: 'meta',
|
|
1129
|
-
attrs: {
|
|
1130
|
-
event_type: 'creation'
|
|
1131
|
-
}
|
|
1132
|
-
});
|
|
1133
|
-
}
|
|
1134
|
-
await relayMessage(jid, fullMsg.message, {
|
|
1135
|
-
messageId: fullMsg.key.id,
|
|
1136
|
-
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1137
|
-
additionalAttributes,
|
|
1138
|
-
statusJidList: options.statusJidList,
|
|
1139
|
-
additionalNodes
|
|
1140
|
-
});
|
|
1141
|
-
if (config.emitOwnEvents) {
|
|
1142
|
-
process.nextTick(async () => {
|
|
1143
|
-
await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
|
|
1144
|
-
});
|
|
1145
|
-
}
|
|
1146
|
-
return fullMsg;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1523
|
+
sendMessage,
|
|
1524
|
+
sendPollVote,
|
|
1525
|
+
newsletterSendPollVote: (jid, parentServerId, options) => sendNewsletterPollVote(jid, parentServerId, options, { query, generateMessageTag }),
|
|
1149
1526
|
};
|
|
1150
1527
|
};
|
|
1151
1528
|
//# sourceMappingURL=messages-send.js.map
|