dct-dev-private-baileys 1.0.0

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