@rakku-kun/baileys 2.0.19 → 2.0.22
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/fix-imports.js +18 -22
- package/WAProto/index.js +18 -22
- package/lib/Defaults/index.d.ts +7 -8
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +17 -11
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Signal/libsignal.d.ts.map +1 -1
- package/lib/Signal/libsignal.js +59 -52
- package/lib/Signal/libsignal.js.map +1 -1
- package/lib/Signal/lid-mapping.d.ts.map +1 -1
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/business.d.ts +3 -18
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/chats.d.ts +2 -16
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +173 -238
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +3 -18
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/groups.d.ts +2 -13
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +138 -26
- package/lib/Socket/groups.js.map +1 -1
- package/lib/Socket/index.d.ts +3 -18
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/messages-recv.d.ts +6 -22
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +645 -736
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +2 -18
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +642 -152
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/newsletter.d.ts +1 -11
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +92 -3
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +2 -6
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +35 -61
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Types/Auth.d.ts +0 -1
- package/lib/Types/Auth.d.ts.map +1 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Call.d.ts.map +1 -1
- package/lib/Types/Chat.d.ts +0 -1
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Contact.d.ts +0 -2
- package/lib/Types/Contact.d.ts.map +1 -1
- package/lib/Types/Events.d.ts +1 -20
- package/lib/Types/Events.d.ts.map +1 -1
- package/lib/Types/GroupMetadata.d.ts +0 -4
- package/lib/Types/GroupMetadata.d.ts.map +1 -1
- package/lib/Types/Message.d.ts +200 -25
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/Signal.d.ts +1 -12
- package/lib/Types/Signal.d.ts.map +1 -1
- package/lib/Types/Socket.d.ts +0 -3
- package/lib/Types/Socket.d.ts.map +1 -1
- package/lib/Types/State.d.ts +0 -58
- package/lib/Types/State.d.ts.map +1 -1
- package/lib/Types/State.js +0 -43
- package/lib/Types/State.js.map +1 -1
- package/lib/Types/index.d.ts +1 -2
- package/lib/Types/index.d.ts.map +1 -1
- package/lib/Types/index.js +2 -1
- package/lib/Types/index.js.map +1 -1
- package/lib/Utils/auth-utils.d.ts +0 -5
- package/lib/Utils/auth-utils.d.ts.map +1 -1
- package/lib/Utils/auth-utils.js +0 -12
- package/lib/Utils/auth-utils.js.map +1 -1
- package/lib/Utils/browser-utils.d.ts.map +1 -1
- package/lib/Utils/browser-utils.js +33 -21
- package/lib/Utils/browser-utils.js.map +1 -1
- package/lib/Utils/chat-utils.d.ts +1 -31
- package/lib/Utils/chat-utils.d.ts.map +1 -1
- package/lib/Utils/chat-utils.js +20 -80
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/decode-wa-message.d.ts +0 -18
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +0 -34
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.d.ts +0 -2
- package/lib/Utils/event-buffer.d.ts.map +1 -1
- package/lib/Utils/event-buffer.js +1 -49
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts +0 -1
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +28 -10
- package/lib/Utils/generics.js.map +1 -1
- package/lib/Utils/history.d.ts +0 -2
- package/lib/Utils/history.d.ts.map +1 -1
- package/lib/Utils/history.js +9 -12
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/identity-change-handler.d.ts +0 -7
- package/lib/Utils/identity-change-handler.d.ts.map +1 -1
- package/lib/Utils/identity-change-handler.js +0 -1
- package/lib/Utils/identity-change-handler.js.map +1 -1
- package/lib/Utils/index.d.ts +2 -2
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +7 -2
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview.js +2 -2
- package/lib/Utils/link-preview.js.map +1 -1
- package/lib/Utils/message-retry-manager.d.ts +0 -5
- package/lib/Utils/message-retry-manager.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.js +0 -40
- package/lib/Utils/message-retry-manager.js.map +1 -1
- package/lib/Utils/messages-media.d.ts +1 -4
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +173 -131
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +1 -0
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +906 -100
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +1 -103
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/signal.d.ts +0 -13
- package/lib/Utils/signal.d.ts.map +1 -1
- package/lib/Utils/signal.js +0 -42
- package/lib/Utils/signal.js.map +1 -1
- package/lib/Utils/sync-action-utils.d.ts.map +1 -1
- package/lib/Utils/sync-action-utils.js +0 -1
- package/lib/Utils/sync-action-utils.js.map +1 -1
- package/lib/Utils/tc-token-utils.d.ts +1 -26
- package/lib/Utils/tc-token-utils.d.ts.map +1 -1
- package/lib/Utils/tc-token-utils.js +5 -151
- package/lib/Utils/tc-token-utils.js.map +1 -1
- package/lib/Utils/validate-connection.d.ts.map +1 -1
- package/lib/Utils/validate-connection.js +2 -12
- package/lib/Utils/validate-connection.js.map +1 -1
- package/lib/WABinary/generic-utils.js +15 -0
- package/lib/WABinary/index.js +1 -0
- package/lib/WABinary/jid-utils.js +2 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +3 -26
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/index.d.ts +0 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/index.js +2 -2
- package/lib/WAUSync/Protocols/index.js.map +1 -1
- package/lib/WAUSync/USyncQuery.d.ts +0 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
- package/lib/WAUSync/USyncQuery.js +2 -6
- package/lib/WAUSync/USyncQuery.js.map +1 -1
- package/lib/WAUSync/USyncUser.d.ts +0 -4
- package/lib/WAUSync/USyncUser.d.ts.map +1 -1
- package/lib/WAUSync/USyncUser.js +0 -8
- package/lib/WAUSync/USyncUser.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +24 -10
- package/package.json +1 -1
|
@@ -1,40 +1,38 @@
|
|
|
1
1
|
import NodeCache from '@cacheable/node-cache';
|
|
2
2
|
import { Boom } from '@hapi/boom';
|
|
3
|
+
import { randomBytes } from 'crypto';
|
|
3
4
|
import { proto } from '../../WAProto/index.js';
|
|
4
5
|
import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
5
|
-
import { aggregateMessageKeysNotFromMe, assertMediaContent,
|
|
6
|
+
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, generateWAMessageFromContent, prepareWAMessageMedia, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils/index.js';
|
|
6
7
|
import { getUrlInfo } from '../Utils/link-preview.js';
|
|
7
|
-
import { makeKeyedMutex
|
|
8
|
+
import { makeKeyedMutex } from '../Utils/make-mutex.js';
|
|
8
9
|
import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/reporting-utils.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
10
|
+
import { areJidsSameUser, getBinaryFilteredBizBot, getBinaryNodeChild, getBinaryNodeChildren, isHostedLidUser, isHostedPnUser, isJidGroup, isJidUser, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET, STORIES_JID } from '../WABinary/index.js';
|
|
11
|
+
import { delay } from '../Utils/generics.js';
|
|
12
|
+
|
|
11
13
|
import { USyncQuery, USyncUser } from '../WAUSync/index.js';
|
|
12
14
|
import { makeNewsletterSocket } from './newsletter.js';
|
|
15
|
+
// Inline helper — no external import needed
|
|
16
|
+
const _isNewsletterJid = (jid) => typeof jid === 'string' && jid.endsWith('@newsletter');
|
|
17
|
+
|
|
13
18
|
export const makeMessagesSocket = (config) => {
|
|
14
19
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
|
|
15
20
|
const sock = makeNewsletterSocket(config);
|
|
16
|
-
const { ev, authState, messageMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral
|
|
17
|
-
const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
|
|
18
|
-
/**
|
|
19
|
-
* Set of tctoken storage JIDs with a fire-and-forget `issuePrivacyTokens` IQ in flight.
|
|
20
|
-
* Prevents duplicate IQs from rapid back-to-back sends before `senderTimestamp` persists.
|
|
21
|
-
* Entries are always removed in `.finally()`, so the set is bounded by concurrency.
|
|
22
|
-
*/
|
|
23
|
-
const inFlightTcTokenIssuance = new Set();
|
|
21
|
+
const { ev, authState, messageMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral } = sock;
|
|
24
22
|
const userDevicesCache = config.userDevicesCache ||
|
|
25
23
|
new NodeCache({
|
|
26
24
|
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
|
27
25
|
useClones: false
|
|
28
26
|
});
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const peerSessionsCache = new NodeCache({
|
|
28
|
+
stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES,
|
|
29
|
+
useClones: false
|
|
30
|
+
});
|
|
31
31
|
// Initialize message retry manager if enabled
|
|
32
32
|
const messageRetryManager = enableRecentMessageCache ? new MessageRetryManager(logger, maxMsgRetryCount) : null;
|
|
33
33
|
// Prevent race conditions in Signal session encryption by user
|
|
34
34
|
const encryptionMutex = makeKeyedMutex();
|
|
35
35
|
let mediaConn;
|
|
36
|
-
/** Per-socket media host; updated whenever media_conn is fetched. Defaults to the public WhatsApp host. */
|
|
37
|
-
let mediaHost = DEF_MEDIA_HOST;
|
|
38
36
|
const refreshMediaConn = async (forceGet = false) => {
|
|
39
37
|
const media = await mediaConn;
|
|
40
38
|
if (!media || forceGet || new Date().getTime() - media.fetchDate.getTime() > media.ttl * 1000) {
|
|
@@ -60,9 +58,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
60
58
|
fetchDate: new Date()
|
|
61
59
|
};
|
|
62
60
|
logger.debug('fetched media conn');
|
|
63
|
-
if (node.hosts[0]) {
|
|
64
|
-
mediaHost = node.hosts[0].hostname;
|
|
65
|
-
}
|
|
66
61
|
return node;
|
|
67
62
|
})();
|
|
68
63
|
}
|
|
@@ -238,18 +233,16 @@ export const makeMessagesSocket = (config) => {
|
|
|
238
233
|
}, 'Processed device with LID priority');
|
|
239
234
|
}
|
|
240
235
|
}
|
|
241
|
-
|
|
242
|
-
if
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
await userDevicesCache.set(key, deviceMap[key]);
|
|
250
|
-
}
|
|
236
|
+
if (userDevicesCache.mset) {
|
|
237
|
+
// if the cache supports mset, we can set all devices in one go
|
|
238
|
+
await userDevicesCache.mset(Object.entries(deviceMap).map(([key, value]) => ({ key, value })));
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
for (const key in deviceMap) {
|
|
242
|
+
if (deviceMap[key])
|
|
243
|
+
await userDevicesCache.set(key, deviceMap[key]);
|
|
251
244
|
}
|
|
252
|
-
}
|
|
245
|
+
}
|
|
253
246
|
const userDeviceUpdates = {};
|
|
254
247
|
for (const [userId, devices] of Object.entries(deviceMap)) {
|
|
255
248
|
if (devices && devices.length > 0) {
|
|
@@ -295,13 +288,23 @@ export const makeMessagesSocket = (config) => {
|
|
|
295
288
|
};
|
|
296
289
|
const assertSessions = async (jids, force) => {
|
|
297
290
|
let didFetchNewSession = false;
|
|
298
|
-
const uniqueJids = [...new Set(jids)];
|
|
291
|
+
const uniqueJids = [...new Set(jids)]; // Deduplicate JIDs
|
|
299
292
|
const jidsRequiringFetch = [];
|
|
300
293
|
logger.debug({ jids }, 'assertSessions call with jids');
|
|
294
|
+
// Check peerSessionsCache and validate sessions using libsignal loadSession
|
|
301
295
|
for (const jid of uniqueJids) {
|
|
302
|
-
|
|
296
|
+
const signalId = signalRepository.jidToSignalProtocolAddress(jid);
|
|
297
|
+
const cachedSession = peerSessionsCache.get(signalId);
|
|
298
|
+
if (cachedSession !== undefined) {
|
|
299
|
+
if (cachedSession && !force) {
|
|
300
|
+
continue; // Session exists in cache
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
303
304
|
const sessionValidation = await signalRepository.validateSession(jid);
|
|
304
|
-
|
|
305
|
+
const hasSession = sessionValidation.exists;
|
|
306
|
+
peerSessionsCache.set(signalId, hasSession);
|
|
307
|
+
if (hasSession && !force) {
|
|
305
308
|
continue;
|
|
306
309
|
}
|
|
307
310
|
}
|
|
@@ -336,6 +339,11 @@ export const makeMessagesSocket = (config) => {
|
|
|
336
339
|
});
|
|
337
340
|
await parseAndInjectE2ESessions(result, signalRepository);
|
|
338
341
|
didFetchNewSession = true;
|
|
342
|
+
// Cache fetched sessions using wire JIDs
|
|
343
|
+
for (const wireJid of wireJids) {
|
|
344
|
+
const signalId = signalRepository.jidToSignalProtocolAddress(wireJid);
|
|
345
|
+
peerSessionsCache.set(signalId, true);
|
|
346
|
+
}
|
|
339
347
|
}
|
|
340
348
|
return didFetchNewSession;
|
|
341
349
|
};
|
|
@@ -425,8 +433,8 @@ export const makeMessagesSocket = (config) => {
|
|
|
425
433
|
}
|
|
426
434
|
return { nodes, shouldIncludeDeviceIdentity };
|
|
427
435
|
};
|
|
428
|
-
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
|
|
429
|
-
const meId =
|
|
436
|
+
const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList, AI = false }) => {
|
|
437
|
+
const meId = authState.creds.me.id;
|
|
430
438
|
const meLid = authState.creds.me?.lid;
|
|
431
439
|
const isRetryResend = Boolean(participant?.jid);
|
|
432
440
|
let shouldIncludeDeviceIdentity = isRetryResend;
|
|
@@ -471,13 +479,89 @@ export const makeMessagesSocket = (config) => {
|
|
|
471
479
|
extraAttrs['mediatype'] = mediaType;
|
|
472
480
|
}
|
|
473
481
|
if (isNewsletter) {
|
|
482
|
+
// Handle edit
|
|
483
|
+
if (message.protocolMessage?.editedMessage) {
|
|
484
|
+
msgId = message.protocolMessage.key?.id;
|
|
485
|
+
message = message.protocolMessage.editedMessage;
|
|
486
|
+
}
|
|
487
|
+
// Handle delete/revoke
|
|
488
|
+
if (message.protocolMessage?.type === proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
489
|
+
msgId = message.protocolMessage.key?.id;
|
|
490
|
+
message = {};
|
|
491
|
+
}
|
|
492
|
+
// ── Newsletter Button Compatibility Patch ──────────────────────
|
|
493
|
+
// interactiveMessage (quick_reply / single_select / cta_url) bisa
|
|
494
|
+
// dikirim ke newsletter langsung — WA menerima via proto encoding.
|
|
495
|
+
// listMessage & buttonsMessage dikonversi ke interactiveMessage
|
|
496
|
+
// supaya konsisten dengan cara bot menulis pesan.
|
|
497
|
+
// ──────────────────────────────────────────────────────────────
|
|
498
|
+
if (message.listMessage) {
|
|
499
|
+
const list = message.listMessage;
|
|
500
|
+
message = {
|
|
501
|
+
interactiveMessage: {
|
|
502
|
+
nativeFlowMessage: {
|
|
503
|
+
buttons: [{
|
|
504
|
+
name: 'single_select',
|
|
505
|
+
buttonParamsJson: JSON.stringify({
|
|
506
|
+
title: list.buttonText || 'Select',
|
|
507
|
+
sections: (list.sections || []).map(sec => ({
|
|
508
|
+
title: sec.title || '',
|
|
509
|
+
highlight_label: '',
|
|
510
|
+
rows: (sec.rows || []).map(row => ({
|
|
511
|
+
header: '',
|
|
512
|
+
title: row.title || '',
|
|
513
|
+
description: row.description || '',
|
|
514
|
+
id: row.rowId || row.id || ''
|
|
515
|
+
}))
|
|
516
|
+
}))
|
|
517
|
+
})
|
|
518
|
+
}],
|
|
519
|
+
messageParamsJson: '',
|
|
520
|
+
messageVersion: 1
|
|
521
|
+
},
|
|
522
|
+
body: { text: list.description || '' },
|
|
523
|
+
...(list.footerText ? { footer: { text: list.footerText } } : {}),
|
|
524
|
+
...(list.title ? { header: { title: list.title, hasMediaAttachment: false, subtitle: '' } } : {})
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
else if (message.buttonsMessage) {
|
|
529
|
+
const bMsg = message.buttonsMessage;
|
|
530
|
+
message = {
|
|
531
|
+
interactiveMessage: {
|
|
532
|
+
nativeFlowMessage: {
|
|
533
|
+
buttons: (bMsg.buttons || []).map(btn => ({
|
|
534
|
+
name: 'quick_reply',
|
|
535
|
+
buttonParamsJson: JSON.stringify({
|
|
536
|
+
display_text: btn.buttonText?.displayText || btn.buttonText || '',
|
|
537
|
+
id: btn.buttonId || btn.buttonText?.displayText || ''
|
|
538
|
+
})
|
|
539
|
+
})),
|
|
540
|
+
messageParamsJson: '',
|
|
541
|
+
messageVersion: 1
|
|
542
|
+
},
|
|
543
|
+
body: { text: bMsg.contentText || bMsg.text || '' },
|
|
544
|
+
...(bMsg.footerText ? { footer: { text: bMsg.footerText } } : {}),
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
// ── End Newsletter Button Compatibility Patch ──────────────────
|
|
474
549
|
const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
|
|
550
|
+
if (Array.isArray(patched)) {
|
|
551
|
+
throw new Error('Per-jid patching is not supported in channel');
|
|
552
|
+
}
|
|
475
553
|
const bytes = encodeNewsletterMessage(patched);
|
|
554
|
+
// Set mediatype for interactive messages
|
|
555
|
+
if (patched.interactiveMessage && !extraAttrs['mediatype']) {
|
|
556
|
+
extraAttrs['mediatype'] = 'interactive';
|
|
557
|
+
}
|
|
558
|
+
// extraAttrs already has mediatype set above if media message
|
|
476
559
|
binaryNodeContent.push({
|
|
477
560
|
tag: 'plaintext',
|
|
478
|
-
attrs:
|
|
561
|
+
attrs: extraAttrs,
|
|
479
562
|
content: bytes
|
|
480
563
|
});
|
|
564
|
+
logger.debug({ msgId, extraAttrs }, `sending newsletter message to ${jid}`);
|
|
481
565
|
const stanza = {
|
|
482
566
|
tag: 'message',
|
|
483
567
|
attrs: {
|
|
@@ -488,7 +572,6 @@ export const makeMessagesSocket = (config) => {
|
|
|
488
572
|
},
|
|
489
573
|
content: binaryNodeContent
|
|
490
574
|
};
|
|
491
|
-
logger.debug({ msgId }, `sending newsletter message to ${jid}`);
|
|
492
575
|
await sendNode(stanza);
|
|
493
576
|
return;
|
|
494
577
|
}
|
|
@@ -535,6 +618,147 @@ export const makeMessagesSocket = (config) => {
|
|
|
535
618
|
addressing_mode: groupData?.addressingMode || 'lid'
|
|
536
619
|
};
|
|
537
620
|
}
|
|
621
|
+
// Ensure groupStatusMessageV2 always has messageContextInfo.messageSecret
|
|
622
|
+
if (message?.groupStatusMessageV2 && !message?.messageContextInfo?.messageSecret) {
|
|
623
|
+
const { randomBytes } = await import('node:crypto');
|
|
624
|
+
message = {
|
|
625
|
+
...message,
|
|
626
|
+
messageContextInfo: {
|
|
627
|
+
...(message.messageContextInfo || {}),
|
|
628
|
+
messageSecret: randomBytes(32)
|
|
629
|
+
},
|
|
630
|
+
groupStatusMessageV2: {
|
|
631
|
+
...message.groupStatusMessageV2,
|
|
632
|
+
message: {
|
|
633
|
+
...(message.groupStatusMessageV2.message || {}),
|
|
634
|
+
messageContextInfo: {
|
|
635
|
+
...(message.groupStatusMessageV2.message?.messageContextInfo || {}),
|
|
636
|
+
messageSecret: message.messageContextInfo?.messageSecret || randomBytes(32)
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
// ── Group Interactive Message Compatibility Patch ──────────────
|
|
643
|
+
// WhatsApp groups do NOT render listMessage, buttonsMessage, or
|
|
644
|
+
// templateMessage natively in MD protocol. All must be converted
|
|
645
|
+
// to interactiveMessage with nativeFlowMessage so they display
|
|
646
|
+
// and are interactive in group chats.
|
|
647
|
+
// ──────────────────────────────────────────────────────────────
|
|
648
|
+
|
|
649
|
+
// 1. listMessage → interactiveMessage single_select
|
|
650
|
+
if (message.listMessage) {
|
|
651
|
+
const list = message.listMessage;
|
|
652
|
+
const interactiveMessage = {
|
|
653
|
+
nativeFlowMessage: {
|
|
654
|
+
buttons: [{
|
|
655
|
+
name: 'single_select',
|
|
656
|
+
buttonParamsJson: JSON.stringify({
|
|
657
|
+
title: list.buttonText || 'Select',
|
|
658
|
+
sections: (list.sections || []).map(section => ({
|
|
659
|
+
title: section.title || '',
|
|
660
|
+
highlight_label: '',
|
|
661
|
+
rows: (section.rows || []).map(row => ({
|
|
662
|
+
header: '',
|
|
663
|
+
title: row.title || '',
|
|
664
|
+
description: row.description || '',
|
|
665
|
+
id: row.rowId || row.id || ''
|
|
666
|
+
}))
|
|
667
|
+
}))
|
|
668
|
+
})
|
|
669
|
+
}],
|
|
670
|
+
messageParamsJson: '',
|
|
671
|
+
messageVersion: 1
|
|
672
|
+
},
|
|
673
|
+
body: { text: list.description || '' },
|
|
674
|
+
footer: list.footerText ? { text: list.footerText } : undefined,
|
|
675
|
+
header: list.title ? { title: list.title, hasMediaAttachment: false, subtitle: '' } : undefined,
|
|
676
|
+
contextInfo: list.contextInfo
|
|
677
|
+
};
|
|
678
|
+
message = { interactiveMessage };
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// 2. buttonsMessage → interactiveMessage nativeFlowMessage quick_reply buttons
|
|
682
|
+
else if (message.buttonsMessage) {
|
|
683
|
+
const bMsg = message.buttonsMessage;
|
|
684
|
+
const buttons = (bMsg.buttons || []).map(btn => ({
|
|
685
|
+
name: 'quick_reply',
|
|
686
|
+
buttonParamsJson: JSON.stringify({
|
|
687
|
+
display_text: btn.buttonText?.displayText || btn.buttonText || '',
|
|
688
|
+
id: btn.buttonId || btn.buttonText?.displayText || ''
|
|
689
|
+
})
|
|
690
|
+
}));
|
|
691
|
+
const interactiveMessage = {
|
|
692
|
+
nativeFlowMessage: {
|
|
693
|
+
buttons,
|
|
694
|
+
messageParamsJson: '',
|
|
695
|
+
messageVersion: 1
|
|
696
|
+
},
|
|
697
|
+
body: { text: bMsg.contentText || bMsg.text || '' },
|
|
698
|
+
footer: bMsg.footerText ? { text: bMsg.footerText } : undefined,
|
|
699
|
+
header: bMsg.text
|
|
700
|
+
? { title: bMsg.text, hasMediaAttachment: false, subtitle: '' }
|
|
701
|
+
: (bMsg.imageMessage || bMsg.videoMessage || bMsg.documentMessage
|
|
702
|
+
? { hasMediaAttachment: true, ...(bMsg.imageMessage ? { imageMessage: bMsg.imageMessage } : {}), ...(bMsg.videoMessage ? { videoMessage: bMsg.videoMessage } : {}) }
|
|
703
|
+
: undefined),
|
|
704
|
+
contextInfo: bMsg.contextInfo
|
|
705
|
+
};
|
|
706
|
+
message = { interactiveMessage };
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// 3. templateMessage (hydratedFourRowTemplate) → interactiveMessage nativeFlowMessage
|
|
710
|
+
else if (message.templateMessage) {
|
|
711
|
+
const tmpl = message.templateMessage.hydratedTemplate || message.templateMessage.fourRowTemplate;
|
|
712
|
+
if (tmpl) {
|
|
713
|
+
const hydratedButtons = tmpl.hydratedButtons || [];
|
|
714
|
+
const buttons = hydratedButtons.map(hBtn => {
|
|
715
|
+
if (hBtn.quickReplyButton) {
|
|
716
|
+
return {
|
|
717
|
+
name: 'quick_reply',
|
|
718
|
+
buttonParamsJson: JSON.stringify({
|
|
719
|
+
display_text: hBtn.quickReplyButton.displayText || '',
|
|
720
|
+
id: hBtn.quickReplyButton.id || hBtn.quickReplyButton.displayText || ''
|
|
721
|
+
})
|
|
722
|
+
};
|
|
723
|
+
} else if (hBtn.urlButton) {
|
|
724
|
+
return {
|
|
725
|
+
name: 'cta_url',
|
|
726
|
+
buttonParamsJson: JSON.stringify({
|
|
727
|
+
display_text: hBtn.urlButton.displayText || '',
|
|
728
|
+
url: hBtn.urlButton.url || '',
|
|
729
|
+
merchant_url: hBtn.urlButton.url || ''
|
|
730
|
+
})
|
|
731
|
+
};
|
|
732
|
+
} else if (hBtn.callButton) {
|
|
733
|
+
return {
|
|
734
|
+
name: 'cta_call',
|
|
735
|
+
buttonParamsJson: JSON.stringify({
|
|
736
|
+
display_text: hBtn.callButton.displayText || '',
|
|
737
|
+
phone_number: hBtn.callButton.phoneNumber || ''
|
|
738
|
+
})
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
return null;
|
|
742
|
+
}).filter(Boolean);
|
|
743
|
+
const interactiveMessage = {
|
|
744
|
+
nativeFlowMessage: {
|
|
745
|
+
buttons,
|
|
746
|
+
messageParamsJson: '',
|
|
747
|
+
messageVersion: 1
|
|
748
|
+
},
|
|
749
|
+
body: { text: tmpl.hydratedContentText || tmpl.contentText || '' },
|
|
750
|
+
footer: tmpl.hydratedFooterText ? { text: tmpl.hydratedFooterText } : undefined,
|
|
751
|
+
header: tmpl.hydratedTitleText
|
|
752
|
+
? { title: tmpl.hydratedTitleText, hasMediaAttachment: false, subtitle: '' }
|
|
753
|
+
: (tmpl.imageMessage || tmpl.videoMessage || tmpl.documentMessage
|
|
754
|
+
? { hasMediaAttachment: true, ...(tmpl.imageMessage ? { imageMessage: tmpl.imageMessage } : {}), ...(tmpl.videoMessage ? { videoMessage: tmpl.videoMessage } : {}) }
|
|
755
|
+
: undefined),
|
|
756
|
+
contextInfo: tmpl.contextInfo
|
|
757
|
+
};
|
|
758
|
+
message = { interactiveMessage };
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
// ── End Group Interactive Message Compatibility Patch ──────────
|
|
538
762
|
const patched = await patchMessageBeforeSending(message);
|
|
539
763
|
if (Array.isArray(patched)) {
|
|
540
764
|
throw new Boom('Per-jid patching is not supported in groups');
|
|
@@ -670,42 +894,14 @@ export const makeMessagesSocket = (config) => {
|
|
|
670
894
|
if (isRetryResend) {
|
|
671
895
|
const isParticipantLid = isLidUser(participant.jid);
|
|
672
896
|
const isMe = areJidsSameUser(participant.jid, isParticipantLid ? meLid : meId);
|
|
673
|
-
let messageToSend = message;
|
|
674
|
-
if (isGroupOrStatus) {
|
|
675
|
-
let groupSenderIdentity;
|
|
676
|
-
if (meLid && (await signalRepository.hasSenderKey({ group: destinationJid, meId: meLid }))) {
|
|
677
|
-
groupSenderIdentity = meLid;
|
|
678
|
-
}
|
|
679
|
-
else if (await signalRepository.hasSenderKey({ group: destinationJid, meId })) {
|
|
680
|
-
groupSenderIdentity = meId;
|
|
681
|
-
}
|
|
682
|
-
if (groupSenderIdentity) {
|
|
683
|
-
try {
|
|
684
|
-
const skdm = await signalRepository.getSenderKeyDistributionMessage({
|
|
685
|
-
group: destinationJid,
|
|
686
|
-
meId: groupSenderIdentity
|
|
687
|
-
});
|
|
688
|
-
messageToSend = {
|
|
689
|
-
...message,
|
|
690
|
-
senderKeyDistributionMessage: {
|
|
691
|
-
groupId: destinationJid,
|
|
692
|
-
axolotlSenderKeyDistributionMessage: skdm
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
catch (err) {
|
|
697
|
-
logger.warn({ err, jid: destinationJid }, 'failed to build SKDM for retry, sending without it');
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
897
|
const encodedMessageToSend = isMe
|
|
702
898
|
? encodeWAMessage({
|
|
703
899
|
deviceSentMessage: {
|
|
704
900
|
destinationJid,
|
|
705
|
-
message
|
|
901
|
+
message
|
|
706
902
|
}
|
|
707
903
|
})
|
|
708
|
-
: encodeWAMessage(
|
|
904
|
+
: encodeWAMessage(message);
|
|
709
905
|
const { type, ciphertext: encryptedContent } = await signalRepository.encryptMessage({
|
|
710
906
|
data: encodedMessageToSend,
|
|
711
907
|
jid: participant.jid
|
|
@@ -796,30 +992,9 @@ export const makeMessagesSocket = (config) => {
|
|
|
796
992
|
logger.warn({ jid, trace: error?.stack }, 'failed to attach reporting token');
|
|
797
993
|
}
|
|
798
994
|
}
|
|
799
|
-
|
|
800
|
-
const
|
|
801
|
-
|
|
802
|
-
// Resolve destination to LID for tctoken storage — matches Signal session key pattern
|
|
803
|
-
const tcTokenJid = is1on1Send ? await resolveTcTokenJid(destinationJid, getLIDForPN) : destinationJid;
|
|
804
|
-
const contactTcTokenData = is1on1Send ? await authState.keys.get('tctoken', [tcTokenJid]) : {};
|
|
805
|
-
const existingTokenEntry = contactTcTokenData[tcTokenJid];
|
|
806
|
-
let tcTokenBuffer = existingTokenEntry?.token;
|
|
807
|
-
// Treat expired tokens the same as missing — clear from cache
|
|
808
|
-
if (tcTokenBuffer?.length && isTcTokenExpired(existingTokenEntry?.timestamp)) {
|
|
809
|
-
logger.debug({ jid: destinationJid, timestamp: existingTokenEntry?.timestamp }, 'tctoken expired, clearing');
|
|
810
|
-
tcTokenBuffer = undefined;
|
|
811
|
-
// Preserve senderTimestamp so the fire-and-forget issuance dedupe survives cleanup.
|
|
812
|
-
const cleared = existingTokenEntry?.senderTimestamp !== undefined
|
|
813
|
-
? { token: Buffer.alloc(0), senderTimestamp: existingTokenEntry.senderTimestamp }
|
|
814
|
-
: null;
|
|
815
|
-
try {
|
|
816
|
-
await authState.keys.set({ tctoken: { [tcTokenJid]: cleared } });
|
|
817
|
-
}
|
|
818
|
-
catch (err) {
|
|
819
|
-
logger.debug({ jid: destinationJid, err: err?.message }, 'failed to persist tctoken expiry cleanup');
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
if (tcTokenBuffer?.length && sock.serverProps.privacyTokenOn1to1) {
|
|
995
|
+
const contactTcTokenData = !isGroup && !isRetryResend && !isStatus ? await authState.keys.get('tctoken', [destinationJid]) : {};
|
|
996
|
+
const tcTokenBuffer = contactTcTokenData[destinationJid]?.token;
|
|
997
|
+
if (tcTokenBuffer) {
|
|
823
998
|
;
|
|
824
999
|
stanza.content.push({
|
|
825
1000
|
tag: 'tctoken',
|
|
@@ -827,54 +1002,24 @@ export const makeMessagesSocket = (config) => {
|
|
|
827
1002
|
content: tcTokenBuffer
|
|
828
1003
|
});
|
|
829
1004
|
}
|
|
830
|
-
if (
|
|
1005
|
+
if (AI && !isGroup && !isStatus && !isNewsletter) {
|
|
1006
|
+
const existingBizBot = getBinaryFilteredBizBot(additionalNodes || []);
|
|
1007
|
+
if (existingBizBot) {
|
|
1008
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
1009
|
+
stanza.content.push(...additionalNodes);
|
|
1010
|
+
}
|
|
1011
|
+
} else {
|
|
1012
|
+
stanza.content.push({ tag: 'bot', attrs: { biz_bot: '1' } });
|
|
1013
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
|
1014
|
+
stanza.content.push(...additionalNodes);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
} else if (additionalNodes && additionalNodes.length > 0) {
|
|
831
1018
|
;
|
|
832
1019
|
stanza.content.push(...additionalNodes);
|
|
833
1020
|
}
|
|
834
1021
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
|
835
1022
|
await sendNode(stanza);
|
|
836
|
-
// Fire-and-forget: issue our token to the contact AFTER message send.
|
|
837
|
-
// WA Web skips protocol messages and PSA/bot contacts (TcTokenChatAction: isRegularUser)
|
|
838
|
-
const isProtocolMsg = !!normalizeMessageContent(message)?.protocolMessage;
|
|
839
|
-
const isBotOrPSA = destinationJid === PSA_WID || isJidBot(destinationJid) || isJidMetaAI(destinationJid);
|
|
840
|
-
if (is1on1Send &&
|
|
841
|
-
!isProtocolMsg &&
|
|
842
|
-
!isBotOrPSA &&
|
|
843
|
-
shouldSendNewTcToken(existingTokenEntry?.senderTimestamp) &&
|
|
844
|
-
!inFlightTcTokenIssuance.has(tcTokenJid)) {
|
|
845
|
-
inFlightTcTokenIssuance.add(tcTokenJid);
|
|
846
|
-
const issueTimestamp = unixTimestampSeconds();
|
|
847
|
-
const getPNForLID = signalRepository.lidMapping.getPNForLID.bind(signalRepository.lidMapping);
|
|
848
|
-
resolveIssuanceJid(destinationJid, sock.serverProps.lidTrustedTokenIssueToLid, getLIDForPN, getPNForLID)
|
|
849
|
-
.then(issueJid => issuePrivacyTokens([issueJid], issueTimestamp))
|
|
850
|
-
.then(async (result) => {
|
|
851
|
-
await storeTcTokensFromIqResult({
|
|
852
|
-
result,
|
|
853
|
-
fallbackJid: tcTokenJid,
|
|
854
|
-
keys: authState.keys,
|
|
855
|
-
getLIDForPN
|
|
856
|
-
});
|
|
857
|
-
const currentData = await authState.keys.get('tctoken', [tcTokenJid]);
|
|
858
|
-
const currentEntry = currentData[tcTokenJid];
|
|
859
|
-
const indexWrite = await buildMergedTcTokenIndexWrite(authState.keys, [tcTokenJid]);
|
|
860
|
-
await authState.keys.set({
|
|
861
|
-
tctoken: {
|
|
862
|
-
[tcTokenJid]: {
|
|
863
|
-
token: Buffer.alloc(0),
|
|
864
|
-
...currentEntry,
|
|
865
|
-
senderTimestamp: issueTimestamp
|
|
866
|
-
},
|
|
867
|
-
...indexWrite
|
|
868
|
-
}
|
|
869
|
-
});
|
|
870
|
-
})
|
|
871
|
-
.catch(err => {
|
|
872
|
-
logger.debug({ jid: destinationJid, err: err?.message }, 'fire-and-forget tctoken issuance failed');
|
|
873
|
-
})
|
|
874
|
-
.finally(() => {
|
|
875
|
-
inFlightTcTokenIssuance.delete(tcTokenJid);
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
1023
|
// Add message to retry cache if enabled
|
|
879
1024
|
if (messageRetryManager && !participant) {
|
|
880
1025
|
messageRetryManager.addRecentMessage(destinationJid, msgId, message);
|
|
@@ -883,6 +1028,11 @@ export const makeMessagesSocket = (config) => {
|
|
|
883
1028
|
return msgId;
|
|
884
1029
|
};
|
|
885
1030
|
const getMessageType = (message) => {
|
|
1031
|
+
// groupStatusMessageV2 must be checked BEFORE normalizeMessageContent
|
|
1032
|
+
// because normalizeMessageContent will unwrap it into inner message
|
|
1033
|
+
if (message?.groupStatusMessageV2 || message?.groupStatusMessage) {
|
|
1034
|
+
return 'text';
|
|
1035
|
+
}
|
|
886
1036
|
const normalizedMessage = normalizeMessageContent(message);
|
|
887
1037
|
if (!normalizedMessage)
|
|
888
1038
|
return 'text';
|
|
@@ -898,6 +1048,9 @@ export const makeMessagesSocket = (config) => {
|
|
|
898
1048
|
if (normalizedMessage.eventMessage) {
|
|
899
1049
|
return 'event';
|
|
900
1050
|
}
|
|
1051
|
+
if (normalizedMessage.interactiveMessage) {
|
|
1052
|
+
return 'text';
|
|
1053
|
+
}
|
|
901
1054
|
if (getMediaType(normalizedMessage) !== '') {
|
|
902
1055
|
return 'media';
|
|
903
1056
|
}
|
|
@@ -910,6 +1063,9 @@ export const makeMessagesSocket = (config) => {
|
|
|
910
1063
|
else if (message.videoMessage) {
|
|
911
1064
|
return message.videoMessage.gifPlayback ? 'gif' : 'video';
|
|
912
1065
|
}
|
|
1066
|
+
else if (message.ptvMessage) {
|
|
1067
|
+
return 'video';
|
|
1068
|
+
}
|
|
913
1069
|
else if (message.audioMessage) {
|
|
914
1070
|
return message.audioMessage.ptt ? 'ptt' : 'audio';
|
|
915
1071
|
}
|
|
@@ -928,6 +1084,9 @@ export const makeMessagesSocket = (config) => {
|
|
|
928
1084
|
else if (message.stickerMessage) {
|
|
929
1085
|
return 'sticker';
|
|
930
1086
|
}
|
|
1087
|
+
else if (message.stickerPackMessage) {
|
|
1088
|
+
return 'sticker_pack';
|
|
1089
|
+
}
|
|
931
1090
|
else if (message.listMessage) {
|
|
932
1091
|
return 'list';
|
|
933
1092
|
}
|
|
@@ -951,8 +1110,8 @@ export const makeMessagesSocket = (config) => {
|
|
|
951
1110
|
}
|
|
952
1111
|
return '';
|
|
953
1112
|
};
|
|
954
|
-
const
|
|
955
|
-
const t =
|
|
1113
|
+
const getPrivacyTokens = async (jids) => {
|
|
1114
|
+
const t = unixTimestampSeconds().toString();
|
|
956
1115
|
const result = await query({
|
|
957
1116
|
tag: 'iq',
|
|
958
1117
|
attrs: {
|
|
@@ -979,28 +1138,73 @@ export const makeMessagesSocket = (config) => {
|
|
|
979
1138
|
};
|
|
980
1139
|
const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
|
|
981
1140
|
const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
if (
|
|
988
|
-
|
|
1141
|
+
// ── Button type helpers (ported from itsukichan) ──────────────────────────
|
|
1142
|
+
const getButtonType = (message) => {
|
|
1143
|
+
if (message.listMessage) return 'list';
|
|
1144
|
+
if (message.buttonsMessage) return 'buttons';
|
|
1145
|
+
if (message.templateMessage) return 'template';
|
|
1146
|
+
if (message.interactiveMessage?.nativeFlowMessage) return 'native_flow';
|
|
1147
|
+
if (message.interactiveMessage?.shopStorefrontMessage) return 'shop';
|
|
1148
|
+
if (message.interactiveMessage?.collectionMessage) return 'collection';
|
|
1149
|
+
if (message.interactiveMessage?.carouselMessage) return 'carousel';
|
|
1150
|
+
if (message.interactiveMessage) return 'interactive';
|
|
1151
|
+
return null;
|
|
1152
|
+
};
|
|
1153
|
+
const getButtonArgs = (message) => {
|
|
1154
|
+
const nativeFlow = message.interactiveMessage?.nativeFlowMessage;
|
|
1155
|
+
const firstButtonName = nativeFlow?.buttons?.[0]?.name;
|
|
1156
|
+
const nativeFlowSpecials = [
|
|
1157
|
+
'mpm', 'cta_catalog', 'send_location',
|
|
1158
|
+
'call_permission_request', 'wa_payment_transaction_details',
|
|
1159
|
+
'automated_greeting_message_view_catalog'
|
|
1160
|
+
];
|
|
1161
|
+
const ts = unixTimestampSeconds().toString();
|
|
1162
|
+
const bizBase = { actual_actors: '2', host_storage: '2', privacy_mode_ts: ts };
|
|
1163
|
+
const qualityControl = { tag: 'quality_control', attrs: { source_type: 'third_party' } };
|
|
1164
|
+
if (nativeFlow && (firstButtonName === 'review_and_pay' || firstButtonName === 'payment_info')) {
|
|
1165
|
+
return {
|
|
1166
|
+
tag: 'biz',
|
|
1167
|
+
attrs: { native_flow_name: firstButtonName === 'review_and_pay' ? 'order_details' : firstButtonName }
|
|
1168
|
+
};
|
|
1169
|
+
} else if (nativeFlow && nativeFlowSpecials.includes(firstButtonName)) {
|
|
1170
|
+
return {
|
|
1171
|
+
tag: 'biz', attrs: bizBase,
|
|
1172
|
+
content: [{
|
|
1173
|
+
tag: 'interactive', attrs: { type: 'native_flow', v: '1' },
|
|
1174
|
+
content: [{ tag: 'native_flow', attrs: { v: '2', name: firstButtonName } }]
|
|
1175
|
+
}, qualityControl]
|
|
1176
|
+
};
|
|
1177
|
+
} else if (nativeFlow || message.buttonsMessage || message.templateMessage || message.interactiveMessage) {
|
|
1178
|
+
// All interactive types in groups use native_flow biz node
|
|
1179
|
+
// This covers: nativeFlowMessage, buttonsMessage→interactiveMessage,
|
|
1180
|
+
// templateMessage→interactiveMessage, and direct interactiveMessage
|
|
1181
|
+
return {
|
|
1182
|
+
tag: 'biz', attrs: bizBase,
|
|
1183
|
+
content: [{
|
|
1184
|
+
tag: 'interactive', attrs: { type: 'native_flow', v: '1' },
|
|
1185
|
+
content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }]
|
|
1186
|
+
}, qualityControl]
|
|
1187
|
+
};
|
|
1188
|
+
} else if (message.listMessage) {
|
|
1189
|
+
// Standalone listMessage (private chat) keeps the list biz node
|
|
1190
|
+
return {
|
|
1191
|
+
tag: 'biz', attrs: bizBase,
|
|
1192
|
+
content: [{ tag: 'list', attrs: { v: '2', type: 'product_list' } }, qualityControl]
|
|
1193
|
+
};
|
|
1194
|
+
} else {
|
|
1195
|
+
return { tag: 'biz', attrs: bizBase };
|
|
989
1196
|
}
|
|
990
|
-
}
|
|
1197
|
+
};
|
|
1198
|
+
// ── End button type helpers ───────────────────────────────────────────────
|
|
991
1199
|
return {
|
|
992
1200
|
...sock,
|
|
993
|
-
|
|
994
|
-
devicesMutex,
|
|
995
|
-
issuePrivacyTokens,
|
|
1201
|
+
getPrivacyTokens,
|
|
996
1202
|
assertSessions,
|
|
997
1203
|
relayMessage,
|
|
998
1204
|
sendReceipt,
|
|
999
1205
|
sendReceipts,
|
|
1000
1206
|
readMessages,
|
|
1001
1207
|
refreshMediaConn,
|
|
1002
|
-
// Function (not getter) so the spread in chats.ts preserves the live closure binding.
|
|
1003
|
-
getMediaHost: () => mediaHost,
|
|
1004
1208
|
waUploadToServer,
|
|
1005
1209
|
fetchPrivacySettings,
|
|
1006
1210
|
sendPeerDataOperationMessage,
|
|
@@ -1033,7 +1237,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
1033
1237
|
});
|
|
1034
1238
|
}
|
|
1035
1239
|
content.directPath = media.directPath;
|
|
1036
|
-
content.url = getUrlFromDirectPath(content.directPath
|
|
1240
|
+
content.url = getUrlFromDirectPath(content.directPath);
|
|
1037
1241
|
logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
|
|
1038
1242
|
}
|
|
1039
1243
|
catch (err) {
|
|
@@ -1050,8 +1254,259 @@ export const makeMessagesSocket = (config) => {
|
|
|
1050
1254
|
ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
|
|
1051
1255
|
return message;
|
|
1052
1256
|
},
|
|
1257
|
+
resize: async (media, width, height) => {
|
|
1258
|
+
const { getStream, toBuffer } = await import('../Utils/messages-media.js');
|
|
1259
|
+
let sharp;
|
|
1260
|
+
try { sharp = (await import('sharp')).default; } catch (_) {}
|
|
1261
|
+
if (!sharp) throw new Error('sharp is required for resize');
|
|
1262
|
+
const { stream } = await getStream(media);
|
|
1263
|
+
const buf = await toBuffer(stream);
|
|
1264
|
+
return sharp(buf).resize(width, height, { fit: 'cover' }).toBuffer();
|
|
1265
|
+
},
|
|
1266
|
+
sendStatusMentions: async (content, jids = []) => {
|
|
1267
|
+
const userJid = jidNormalizedUser(authState.creds.me.id);
|
|
1268
|
+
let allUsers = new Set();
|
|
1269
|
+
allUsers.add(userJid);
|
|
1270
|
+
|
|
1271
|
+
for (const id of jids) {
|
|
1272
|
+
const isGroup = isJidGroup(id);
|
|
1273
|
+
const isPrivate = isJidUser(id);
|
|
1274
|
+
if (isGroup) {
|
|
1275
|
+
try {
|
|
1276
|
+
const metadata = (cachedGroupMetadata ? await cachedGroupMetadata(id) : null) || await groupMetadata(id);
|
|
1277
|
+
const participants = metadata.participants.map(p => jidNormalizedUser(p.id));
|
|
1278
|
+
participants.forEach(j => allUsers.add(j));
|
|
1279
|
+
} catch (error) {
|
|
1280
|
+
logger.error(`Error getting metadata for group ${id}: ${error}`);
|
|
1281
|
+
}
|
|
1282
|
+
} else if (isPrivate) {
|
|
1283
|
+
allUsers.add(jidNormalizedUser(id));
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
const uniqueUsers = Array.from(allUsers);
|
|
1288
|
+
const getRandomHexColor = () => '#' + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0');
|
|
1289
|
+
|
|
1290
|
+
const isMedia = content.image || content.video || content.audio;
|
|
1291
|
+
const isAudio = !!content.audio;
|
|
1292
|
+
|
|
1293
|
+
const messageContent = { ...content };
|
|
1294
|
+
|
|
1295
|
+
if (isMedia && !isAudio) {
|
|
1296
|
+
if (messageContent.text) {
|
|
1297
|
+
messageContent.caption = messageContent.text;
|
|
1298
|
+
delete messageContent.text;
|
|
1299
|
+
}
|
|
1300
|
+
delete messageContent.ptt;
|
|
1301
|
+
delete messageContent.font;
|
|
1302
|
+
delete messageContent.backgroundColor;
|
|
1303
|
+
delete messageContent.textColor;
|
|
1304
|
+
}
|
|
1305
|
+
if (isAudio) {
|
|
1306
|
+
delete messageContent.text;
|
|
1307
|
+
delete messageContent.caption;
|
|
1308
|
+
delete messageContent.font;
|
|
1309
|
+
delete messageContent.textColor;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
const font = !isMedia ? (content.font ?? Math.floor(Math.random() * 9)) : undefined;
|
|
1313
|
+
const textColor = !isMedia ? (content.textColor ?? getRandomHexColor()) : undefined;
|
|
1314
|
+
const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor ?? getRandomHexColor()) : undefined;
|
|
1315
|
+
const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined;
|
|
1316
|
+
|
|
1317
|
+
let msg;
|
|
1318
|
+
let mediaHandle;
|
|
1319
|
+
try {
|
|
1320
|
+
msg = await generateWAMessage(STORIES_JID, messageContent, {
|
|
1321
|
+
logger,
|
|
1322
|
+
userJid,
|
|
1323
|
+
getUrlInfo: text => getUrlInfo(text, {
|
|
1324
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
|
1325
|
+
fetchOpts: { timeout: 3000 },
|
|
1326
|
+
logger,
|
|
1327
|
+
uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
|
|
1328
|
+
}),
|
|
1329
|
+
upload: async (encFilePath, opts) => {
|
|
1330
|
+
const up = await waUploadToServer(encFilePath, { ...opts });
|
|
1331
|
+
mediaHandle = up.handle;
|
|
1332
|
+
return up;
|
|
1333
|
+
},
|
|
1334
|
+
mediaCache: config.mediaCache,
|
|
1335
|
+
options: config.options,
|
|
1336
|
+
font,
|
|
1337
|
+
textColor,
|
|
1338
|
+
backgroundColor,
|
|
1339
|
+
ptt
|
|
1340
|
+
});
|
|
1341
|
+
} catch (error) {
|
|
1342
|
+
logger.error(`Error generating status message: ${error}`);
|
|
1343
|
+
throw error;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
await relayMessage(STORIES_JID, msg.message, {
|
|
1347
|
+
messageId: msg.key.id,
|
|
1348
|
+
statusJidList: uniqueUsers,
|
|
1349
|
+
additionalNodes: [{
|
|
1350
|
+
tag: 'meta',
|
|
1351
|
+
attrs: {},
|
|
1352
|
+
content: [{
|
|
1353
|
+
tag: 'mentioned_users',
|
|
1354
|
+
attrs: {},
|
|
1355
|
+
content: jids.map(jid => ({
|
|
1356
|
+
tag: 'to',
|
|
1357
|
+
attrs: { jid: jidNormalizedUser(jid) }
|
|
1358
|
+
}))
|
|
1359
|
+
}]
|
|
1360
|
+
}]
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
for (const id of jids) {
|
|
1364
|
+
try {
|
|
1365
|
+
const normalizedId = jidNormalizedUser(id);
|
|
1366
|
+
const isPrivate = isJidUser(normalizedId);
|
|
1367
|
+
const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage';
|
|
1368
|
+
const protocolMessage = {
|
|
1369
|
+
[type]: {
|
|
1370
|
+
message: {
|
|
1371
|
+
protocolMessage: {
|
|
1372
|
+
key: msg.key,
|
|
1373
|
+
type: 25
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
},
|
|
1377
|
+
messageContextInfo: {
|
|
1378
|
+
messageSecret: randomBytes(32)
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
const statusMsg = await generateWAMessageFromContent(normalizedId, protocolMessage, {});
|
|
1382
|
+
await relayMessage(normalizedId, statusMsg.message, {
|
|
1383
|
+
additionalNodes: [{
|
|
1384
|
+
tag: 'meta',
|
|
1385
|
+
attrs: isPrivate
|
|
1386
|
+
? { is_status_mention: 'true' }
|
|
1387
|
+
: { is_group_status_mention: 'true' }
|
|
1388
|
+
}]
|
|
1389
|
+
});
|
|
1390
|
+
await delay(2000);
|
|
1391
|
+
} catch (error) {
|
|
1392
|
+
logger.error(`Error sending status mention to ${id}: ${error}`);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
return msg;
|
|
1397
|
+
},
|
|
1053
1398
|
sendMessage: async (jid, content, options = {}) => {
|
|
1054
1399
|
const userJid = authState.creds.me.id;
|
|
1400
|
+
// ── Normalize: buttons[].nativeFlowInfo -> interactiveButtons ──────
|
|
1401
|
+
if (
|
|
1402
|
+
typeof content === 'object' &&
|
|
1403
|
+
Array.isArray(content.buttons) &&
|
|
1404
|
+
content.buttons.length > 0 &&
|
|
1405
|
+
content.buttons.some(b => b.nativeFlowInfo)
|
|
1406
|
+
) {
|
|
1407
|
+
const interactiveButtons = content.buttons.map(b => {
|
|
1408
|
+
if (b.nativeFlowInfo) {
|
|
1409
|
+
return {
|
|
1410
|
+
name: b.nativeFlowInfo.name,
|
|
1411
|
+
buttonParamsJson: b.nativeFlowInfo.paramsJson || '{}'
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
return {
|
|
1415
|
+
name: 'quick_reply',
|
|
1416
|
+
buttonParamsJson: JSON.stringify({
|
|
1417
|
+
display_text: b.buttonText?.displayText || b.buttonId || 'Button',
|
|
1418
|
+
id: b.buttonId || b.buttonText?.displayText || 'btn'
|
|
1419
|
+
})
|
|
1420
|
+
};
|
|
1421
|
+
});
|
|
1422
|
+
const { buttons, headerType, viewOnce, ...rest } = content;
|
|
1423
|
+
content = { ...rest, interactiveButtons };
|
|
1424
|
+
}
|
|
1425
|
+
// ── Interactive Button (sendButton logic) ──────────────────────────
|
|
1426
|
+
if (typeof content === 'object' && Array.isArray(content.interactiveButtons) && content.interactiveButtons.length > 0) {
|
|
1427
|
+
const {
|
|
1428
|
+
text = '',
|
|
1429
|
+
caption = '',
|
|
1430
|
+
title = '',
|
|
1431
|
+
footer = '',
|
|
1432
|
+
interactiveButtons,
|
|
1433
|
+
hasMediaAttachment = false,
|
|
1434
|
+
image = null,
|
|
1435
|
+
video = null,
|
|
1436
|
+
document = null,
|
|
1437
|
+
mimetype = null,
|
|
1438
|
+
jpegThumbnail = null,
|
|
1439
|
+
location = null,
|
|
1440
|
+
product = null,
|
|
1441
|
+
businessOwnerJid = null,
|
|
1442
|
+
externalAdReply = null,
|
|
1443
|
+
} = content;
|
|
1444
|
+
// Normalize buttons
|
|
1445
|
+
const processedButtons = [];
|
|
1446
|
+
for (let i = 0; i < interactiveButtons.length; i++) {
|
|
1447
|
+
const btn = interactiveButtons[i];
|
|
1448
|
+
if (!btn || typeof btn !== 'object') throw new Error(`interactiveButtons[${i}] must be an object`);
|
|
1449
|
+
if (btn.name && btn.buttonParamsJson) { processedButtons.push(btn); continue; }
|
|
1450
|
+
if (btn.id || btn.text || btn.displayText) {
|
|
1451
|
+
processedButtons.push({ name: 'quick_reply', buttonParamsJson: JSON.stringify({ display_text: btn.text || btn.displayText || `Button ${i + 1}`, id: btn.id || `quick_${i + 1}` }) });
|
|
1452
|
+
continue;
|
|
1453
|
+
}
|
|
1454
|
+
if (btn.buttonId && btn.buttonText?.displayText) {
|
|
1455
|
+
processedButtons.push({ name: 'quick_reply', buttonParamsJson: JSON.stringify({ display_text: btn.buttonText.displayText, id: btn.buttonId }) });
|
|
1456
|
+
continue;
|
|
1457
|
+
}
|
|
1458
|
+
throw new Error(`interactiveButtons[${i}] has invalid shape`);
|
|
1459
|
+
}
|
|
1460
|
+
let messageContent = {};
|
|
1461
|
+
// Header
|
|
1462
|
+
if (image) {
|
|
1463
|
+
const mi = Buffer.isBuffer(image) ? { image } : { image: { url: typeof image === 'object' ? image.url : image } };
|
|
1464
|
+
const pm = await prepareWAMessageMedia(mi, { upload: waUploadToServer });
|
|
1465
|
+
messageContent.header = { title: title || '', hasMediaAttachment: true, imageMessage: pm.imageMessage };
|
|
1466
|
+
} else if (video) {
|
|
1467
|
+
const mi = Buffer.isBuffer(video) ? { video } : { video: { url: typeof video === 'object' ? video.url : video } };
|
|
1468
|
+
const pm = await prepareWAMessageMedia(mi, { upload: waUploadToServer });
|
|
1469
|
+
messageContent.header = { title: title || '', hasMediaAttachment: true, videoMessage: pm.videoMessage };
|
|
1470
|
+
} else if (document) {
|
|
1471
|
+
const mi = Buffer.isBuffer(document) ? { document } : { document: { url: typeof document === 'object' ? document.url : document } };
|
|
1472
|
+
if (mimetype && typeof mi.document === 'object') mi.document.mimetype = mimetype;
|
|
1473
|
+
if (jpegThumbnail) {
|
|
1474
|
+
const thumb = Buffer.isBuffer(jpegThumbnail) ? jpegThumbnail : await (async () => { try { const r = await fetch(jpegThumbnail); return Buffer.from(await r.arrayBuffer()); } catch { return undefined; } })();
|
|
1475
|
+
if (thumb) mi.document.jpegThumbnail = thumb;
|
|
1476
|
+
}
|
|
1477
|
+
const pm = await prepareWAMessageMedia(mi, { upload: waUploadToServer });
|
|
1478
|
+
messageContent.header = { title: title || '', hasMediaAttachment: true, documentMessage: pm.documentMessage };
|
|
1479
|
+
} else if (location && typeof location === 'object') {
|
|
1480
|
+
messageContent.header = { title: title || location.name || 'Location', hasMediaAttachment: false, locationMessage: { degreesLatitude: location.degreesLatitude || location.degressLatitude || 0, degreesLongitude: location.degreesLongitude || location.degressLongitude || 0, name: location.name || '', address: location.address || '' } };
|
|
1481
|
+
} else if (product && typeof product === 'object') {
|
|
1482
|
+
let productImageMessage = null;
|
|
1483
|
+
if (product.productImage) {
|
|
1484
|
+
const mi = Buffer.isBuffer(product.productImage) ? { image: product.productImage } : { image: { url: typeof product.productImage === 'object' ? product.productImage.url : product.productImage } };
|
|
1485
|
+
const pm = await prepareWAMessageMedia(mi, { upload: waUploadToServer });
|
|
1486
|
+
productImageMessage = pm.imageMessage;
|
|
1487
|
+
}
|
|
1488
|
+
messageContent.header = { title: title || product.title || 'Product', hasMediaAttachment: false, productMessage: { product: { productImage: productImageMessage, productId: product.productId || '', title: product.title || '', description: product.description || '', currencyCode: product.currencyCode || 'USD', priceAmount1000: parseInt(product.priceAmount1000) || 0, retailerId: product.retailerId || '', url: product.url || '', productImageCount: product.productImageCount || 1 }, businessOwnerJid: businessOwnerJid || product.businessOwnerJid || userJid } };
|
|
1489
|
+
} else if (title) {
|
|
1490
|
+
messageContent.header = { title, hasMediaAttachment: false };
|
|
1491
|
+
}
|
|
1492
|
+
const hasMedia = !!(image || video || document || location || product);
|
|
1493
|
+
const bodyText = hasMedia ? caption : text || caption;
|
|
1494
|
+
if (bodyText) messageContent.body = { text: bodyText };
|
|
1495
|
+
if (footer) messageContent.footer = { text: footer };
|
|
1496
|
+
messageContent.nativeFlowMessage = { buttons: processedButtons };
|
|
1497
|
+
// Context info
|
|
1498
|
+
if (externalAdReply && typeof externalAdReply === 'object') {
|
|
1499
|
+
messageContent.contextInfo = { externalAdReply: { title: externalAdReply.title || '', body: externalAdReply.body || '', mediaType: externalAdReply.mediaType || 1, sourceUrl: externalAdReply.sourceUrl || externalAdReply.url || '', thumbnailUrl: externalAdReply.thumbnailUrl || externalAdReply.thumbnail || '', renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false, showAdAttribution: externalAdReply.showAdAttribution !== false, containsAutoReply: externalAdReply.containsAutoReply || false, ...(externalAdReply.mediaUrl && { mediaUrl: externalAdReply.mediaUrl }), ...(Buffer.isBuffer(externalAdReply.thumbnail) && { thumbnail: externalAdReply.thumbnail }), ...(externalAdReply.jpegThumbnail && { jpegThumbnail: externalAdReply.jpegThumbnail }) }, ...(options.mentionedJid && { mentionedJid: options.mentionedJid }) };
|
|
1500
|
+
} else if (options.mentionedJid) {
|
|
1501
|
+
messageContent.contextInfo = { mentionedJid: options.mentionedJid };
|
|
1502
|
+
}
|
|
1503
|
+
const payload = proto.Message.InteractiveMessage.create(messageContent);
|
|
1504
|
+
const msg = generateWAMessageFromContent(jid, { viewOnceMessage: { message: { interactiveMessage: payload } } }, { userJid, quoted: options?.quoted || null });
|
|
1505
|
+
const additionalNodes = [{ tag: 'biz', attrs: {}, content: [{ tag: 'interactive', attrs: { type: 'native_flow', v: '1' }, content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }] }] }];
|
|
1506
|
+
await relayMessage(jid, msg.message, { messageId: msg.key.id, additionalNodes });
|
|
1507
|
+
return msg;
|
|
1508
|
+
}
|
|
1509
|
+
// ── End Interactive Button ─────────────────────────────────────────
|
|
1055
1510
|
if (typeof content === 'object' &&
|
|
1056
1511
|
'disappearingMessagesInChat' in content &&
|
|
1057
1512
|
typeof content['disappearingMessagesInChat'] !== 'undefined' &&
|
|
@@ -1065,6 +1520,7 @@ export const makeMessagesSocket = (config) => {
|
|
|
1065
1520
|
await groupToggleEphemeral(jid, value);
|
|
1066
1521
|
}
|
|
1067
1522
|
else {
|
|
1523
|
+
let mediaHandle;
|
|
1068
1524
|
const fullMsg = await generateWAMessage(jid, content, {
|
|
1069
1525
|
logger,
|
|
1070
1526
|
userJid,
|
|
@@ -1080,12 +1536,36 @@ export const makeMessagesSocket = (config) => {
|
|
|
1080
1536
|
//TODO: CACHE
|
|
1081
1537
|
getProfilePicUrl: sock.profilePictureUrl,
|
|
1082
1538
|
getCallLink: sock.createCallLink,
|
|
1083
|
-
|
|
1539
|
+
newsletter: _isNewsletterJid(jid),
|
|
1540
|
+
upload: async (encFilePath, opts) => {
|
|
1541
|
+
const up = await waUploadToServer(encFilePath, { ...opts, newsletter: _isNewsletterJid(jid) });
|
|
1542
|
+
mediaHandle = up.handle;
|
|
1543
|
+
return up;
|
|
1544
|
+
},
|
|
1084
1545
|
mediaCache: config.mediaCache,
|
|
1085
1546
|
options: config.options,
|
|
1086
1547
|
messageId: generateMessageIDV2(sock.user?.id),
|
|
1087
1548
|
...options
|
|
1088
1549
|
});
|
|
1550
|
+
if (content?.audio && options?.contextInfo) {
|
|
1551
|
+
const msgContent = fullMsg.message;
|
|
1552
|
+
if (msgContent?.audioMessage) {
|
|
1553
|
+
msgContent.audioMessage.contextInfo = options.contextInfo;
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
// Extract handle from newsletter upload (set by prepareWAMessageMedia)
|
|
1557
|
+
if (!mediaHandle) {
|
|
1558
|
+
const msgContent = fullMsg.message;
|
|
1559
|
+
const msgTypes = ['audioMessage','imageMessage','videoMessage','documentMessage','stickerMessage'];
|
|
1560
|
+
for (const t of msgTypes) {
|
|
1561
|
+
if (msgContent?.[t]?._uploadHandle) {
|
|
1562
|
+
mediaHandle = msgContent[t]._uploadHandle;
|
|
1563
|
+
|
|
1564
|
+
delete msgContent[t]._uploadHandle;
|
|
1565
|
+
break;
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1089
1569
|
const isEventMsg = 'event' in content && !!content.event;
|
|
1090
1570
|
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
1091
1571
|
const isEditMsg = 'edit' in content && !!content.edit;
|
|
@@ -1125,12 +1605,22 @@ export const makeMessagesSocket = (config) => {
|
|
|
1125
1605
|
}
|
|
1126
1606
|
});
|
|
1127
1607
|
}
|
|
1608
|
+
// Auto-attach biz node for button/list/interactive messages
|
|
1609
|
+
const buttonType = getButtonType(fullMsg.message);
|
|
1610
|
+
if (buttonType) {
|
|
1611
|
+
const btnNode = getButtonArgs(fullMsg.message);
|
|
1612
|
+
if (btnNode) additionalNodes.push(btnNode);
|
|
1613
|
+
}
|
|
1614
|
+
if (mediaHandle) {
|
|
1615
|
+
additionalAttributes['media_id'] = mediaHandle;
|
|
1616
|
+
}
|
|
1128
1617
|
await relayMessage(jid, fullMsg.message, {
|
|
1129
1618
|
messageId: fullMsg.key.id,
|
|
1130
1619
|
useCachedGroupMetadata: options.useCachedGroupMetadata,
|
|
1131
1620
|
additionalAttributes,
|
|
1132
1621
|
statusJidList: options.statusJidList,
|
|
1133
|
-
additionalNodes
|
|
1622
|
+
additionalNodes,
|
|
1623
|
+
AI: options.ai || false
|
|
1134
1624
|
});
|
|
1135
1625
|
if (config.emitOwnEvents) {
|
|
1136
1626
|
process.nextTick(async () => {
|