@baileys-md/baileys 11.0.3 → 11.1.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 (122) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/WAProto/index.js +4182 -13516
  4. package/WASignalGroup/GroupProtocol.js +1697 -0
  5. package/WASignalGroup/ciphertext_message.js +16 -0
  6. package/WASignalGroup/group_cipher.js +120 -0
  7. package/WASignalGroup/group_session_builder.js +46 -0
  8. package/WASignalGroup/index.js +5 -0
  9. package/WASignalGroup/keyhelper.js +21 -0
  10. package/WASignalGroup/protobufs.js +3 -0
  11. package/WASignalGroup/queue_job.js +69 -0
  12. package/WASignalGroup/sender_chain_key.js +50 -0
  13. package/WASignalGroup/sender_key_distribution_message.js +78 -0
  14. package/WASignalGroup/sender_key_message.js +92 -0
  15. package/WASignalGroup/sender_key_name.js +70 -0
  16. package/WASignalGroup/sender_key_record.js +56 -0
  17. package/WASignalGroup/sender_key_state.js +129 -0
  18. package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -4
  19. package/lib/Defaults/baileys-version.json +3 -0
  20. package/lib/Defaults/index.js +71 -52
  21. package/lib/Defaults/{phonenumber-mcc.js → phonenumber-mcc.json} +1 -1
  22. package/lib/Signal/libsignal.js +61 -41
  23. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  24. package/lib/Socket/Client/index.js +19 -3
  25. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  26. package/lib/Socket/Client/web-socket-client.js +62 -0
  27. package/lib/Socket/business.js +42 -37
  28. package/lib/Socket/chats.js +187 -194
  29. package/lib/Socket/groups.js +90 -87
  30. package/lib/Socket/index.js +8 -7
  31. package/lib/Socket/messages-recv.js +335 -360
  32. package/lib/Socket/messages-send.js +279 -156
  33. package/lib/Socket/newsletter.js +213 -144
  34. package/lib/Socket/registration.js +166 -0
  35. package/lib/Socket/socket.js +161 -128
  36. package/lib/Socket/usync.js +26 -19
  37. package/lib/Store/index.js +8 -0
  38. package/lib/Store/make-cache-manager-store.js +83 -0
  39. package/lib/{Utils → Store}/make-in-memory-store.js +27 -19
  40. package/lib/Store/make-mongo-store.js +567 -0
  41. package/lib/{Utils → Store}/make-ordered-dictionary.js +5 -2
  42. package/lib/{Utils → Store}/object-repository.js +4 -1
  43. package/lib/Types/Auth.js +2 -2
  44. package/lib/Types/Call.js +2 -2
  45. package/lib/Types/Chat.js +4 -8
  46. package/lib/Types/Contact.js +2 -2
  47. package/lib/Types/Events.js +2 -2
  48. package/lib/Types/GroupMetadata.js +2 -2
  49. package/lib/Types/Label.js +5 -3
  50. package/lib/Types/LabelAssociation.js +5 -3
  51. package/lib/Types/Message.js +7 -7
  52. package/lib/Types/Newsletter.js +17 -30
  53. package/lib/Types/Product.js +2 -2
  54. package/lib/Types/Signal.js +2 -2
  55. package/lib/Types/Socket.js +2 -3
  56. package/lib/Types/State.js +2 -2
  57. package/lib/Types/USync.js +2 -2
  58. package/lib/Types/index.js +31 -15
  59. package/lib/Utils/auth-utils.js +47 -31
  60. package/lib/Utils/baileys-event-stream.js +22 -15
  61. package/lib/Utils/business.js +69 -66
  62. package/lib/Utils/chat-utils.js +195 -200
  63. package/lib/Utils/crypto.js +85 -70
  64. package/lib/Utils/decode-wa-message.js +51 -46
  65. package/lib/Utils/event-buffer.js +46 -36
  66. package/lib/Utils/generics.js +188 -116
  67. package/lib/Utils/history.js +46 -37
  68. package/lib/Utils/index.js +33 -19
  69. package/lib/Utils/link-preview.js +55 -14
  70. package/lib/Utils/logger.js +7 -3
  71. package/lib/Utils/lt-hash.js +26 -23
  72. package/lib/Utils/make-mutex.js +10 -7
  73. package/lib/Utils/messages-media.js +368 -239
  74. package/lib/Utils/messages.js +510 -278
  75. package/lib/Utils/noise-handler.js +31 -22
  76. package/lib/Utils/process-message.js +148 -144
  77. package/lib/Utils/signal.js +64 -71
  78. package/lib/Utils/use-multi-file-auth-state.js +32 -14
  79. package/lib/Utils/validate-connection.js +115 -72
  80. package/lib/WABinary/constants.js +20 -1281
  81. package/lib/WABinary/decode.js +52 -15
  82. package/lib/WABinary/encode.js +48 -14
  83. package/lib/WABinary/generic-utils.js +39 -31
  84. package/lib/WABinary/index.js +21 -6
  85. package/lib/WABinary/jid-utils.js +40 -23
  86. package/lib/WABinary/types.js +2 -2
  87. package/lib/WAM/BinaryInfo.js +5 -2
  88. package/lib/WAM/constants.js +2366 -2257
  89. package/lib/WAM/encode.js +21 -17
  90. package/lib/WAM/index.js +19 -4
  91. package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
  92. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
  93. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
  94. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
  95. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
  96. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +6 -3
  97. package/lib/WAUSync/Protocols/index.js +20 -5
  98. package/lib/WAUSync/USyncQuery.js +32 -34
  99. package/lib/WAUSync/USyncUser.js +5 -2
  100. package/lib/WAUSync/index.js +19 -4
  101. package/lib/index.js +33 -11
  102. package/package.json +61 -21
  103. package/WAProto/GenerateStatics.sh +0 -3
  104. package/WAProto/WAProto.proto +0 -4633
  105. package/WAProto/fix-imports.js +0 -29
  106. package/lib/Defaults/baileys-version.js +0 -1
  107. package/lib/Signal/Group/ciphertext-message.js +0 -12
  108. package/lib/Signal/Group/group-session-builder.js +0 -30
  109. package/lib/Signal/Group/group_cipher.js +0 -94
  110. package/lib/Signal/Group/index.js +0 -12
  111. package/lib/Signal/Group/keyhelper.js +0 -19
  112. package/lib/Signal/Group/queue-job.js +0 -54
  113. package/lib/Signal/Group/sender-chain-key.js +0 -32
  114. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  115. package/lib/Signal/Group/sender-key-message.js +0 -67
  116. package/lib/Signal/Group/sender-key-name.js +0 -48
  117. package/lib/Signal/Group/sender-key-record.js +0 -50
  118. package/lib/Signal/Group/sender-key-state.js +0 -96
  119. package/lib/Socket/Client/types.js +0 -11
  120. package/lib/Socket/Client/websocket.js +0 -50
  121. package/lib/Socket/communities.js +0 -351
  122. package/lib/Socket/mex.js +0 -42
@@ -1,41 +1,46 @@
1
- import NodeCache from '@cacheable/node-cache';
2
- import { Boom } from '@hapi/boom';
3
- import { proto } from '../../WAProto/index.js';
4
- import { DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
5
- import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, normalizeMessageContent, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils/index.js';
6
- import { getUrlInfo } from '../Utils/link-preview.js';
7
- import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
8
- import { USyncQuery, USyncUser } from '../WAUSync/index.js';
9
- import { makeGroupsSocket } from './groups.js';
10
- import { makeNewsletterSocket } from './newsletter.js';
11
- export const makeMessagesSocket = (config) => {
12
- const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata } = config;
13
- const sock = makeNewsletterSocket(makeGroupsSocket(config));
14
- const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral } = sock;
15
- const userDevicesCache = config.userDevicesCache ||
16
- new NodeCache({
17
- stdTTL: DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
18
- useClones: false
19
- });
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 WAProto_1 = require("../../WAProto");
10
+ const Defaults_1 = require("../Defaults");
11
+ const Utils_1 = require("../Utils");
12
+ const link_preview_1 = require("../Utils/link-preview");
13
+ const WABinary_1 = require("../WABinary");
14
+ const WAUSync_1 = require("../WAUSync");
15
+ const newsletter_1 = require("./newsletter");
16
+ var ListType = WAProto_1.proto.Message.ListMessage.ListType;
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
+ const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
22
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
23
+ useClones: false
24
+ });
20
25
  let mediaConn;
21
26
  const refreshMediaConn = async (forceGet = false) => {
22
27
  const media = await mediaConn;
23
- if (!media || forceGet || new Date().getTime() - media.fetchDate.getTime() > media.ttl * 1000) {
28
+ if (!media || forceGet || (new Date().getTime() - media.fetchDate.getTime()) > media.ttl * 1000) {
24
29
  mediaConn = (async () => {
25
30
  const result = await query({
26
31
  tag: 'iq',
27
32
  attrs: {
28
33
  type: 'set',
29
34
  xmlns: 'w:m',
30
- to: S_WHATSAPP_NET
35
+ to: WABinary_1.S_WHATSAPP_NET,
31
36
  },
32
37
  content: [{ tag: 'media_conn', attrs: {} }]
33
38
  });
34
- const mediaConnNode = getBinaryNodeChild(result, 'media_conn');
39
+ const mediaConnNode = (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn');
35
40
  const node = {
36
- hosts: getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
41
+ hosts: (0, WABinary_1.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
37
42
  hostname: attrs.hostname,
38
- maxContentLengthBytes: +attrs.maxContentLengthBytes
43
+ maxContentLengthBytes: +attrs.maxContentLengthBytes,
39
44
  })),
40
45
  auth: mediaConnNode.attrs.auth,
41
46
  ttl: +mediaConnNode.attrs.ttl,
@@ -52,20 +57,17 @@ export const makeMessagesSocket = (config) => {
52
57
  * used for receipts of phone call, read, delivery etc.
53
58
  * */
54
59
  const sendReceipt = async (jid, participant, messageIds, type) => {
55
- if (!messageIds || messageIds.length === 0) {
56
- throw new Boom('missing ids in receipt');
57
- }
58
60
  const node = {
59
61
  tag: 'receipt',
60
62
  attrs: {
61
- id: messageIds[0]
62
- }
63
+ id: messageIds[0],
64
+ },
63
65
  };
64
66
  const isReadReceipt = type === 'read' || type === 'read-self';
65
67
  if (isReadReceipt) {
66
- node.attrs.t = unixTimestampSeconds().toString();
68
+ node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
67
69
  }
68
- if (type === 'sender' && isJidUser(jid)) {
70
+ if (type === 'sender' && (0, WABinary_1.isJidUser)(jid)) {
69
71
  node.attrs.recipient = jid;
70
72
  node.attrs.to = participant;
71
73
  }
@@ -76,7 +78,7 @@ export const makeMessagesSocket = (config) => {
76
78
  }
77
79
  }
78
80
  if (type) {
79
- node.attrs.type = type;
81
+ node.attrs.type = (0, WABinary_1.isJidNewsletter)(jid) ? 'read-self' : type;
80
82
  }
81
83
  const remainingMessageIds = messageIds.slice(1);
82
84
  if (remainingMessageIds.length) {
@@ -96,7 +98,7 @@ export const makeMessagesSocket = (config) => {
96
98
  };
97
99
  /** Correctly bulk send receipts to multiple chats, participants */
98
100
  const sendReceipts = async (keys, type) => {
99
- const recps = aggregateMessageKeysNotFromMe(keys);
101
+ const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
100
102
  for (const { jid, participant, messageIds } of recps) {
101
103
  await sendReceipt(jid, participant, messageIds, type);
102
104
  }
@@ -110,6 +112,7 @@ export const makeMessagesSocket = (config) => {
110
112
  };
111
113
  /** Fetch all the devices we've to send a message to */
112
114
  const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
115
+ var _a;
113
116
  const deviceResults = [];
114
117
  if (!useCache) {
115
118
  logger.debug('not using cache for devices');
@@ -117,8 +120,8 @@ export const makeMessagesSocket = (config) => {
117
120
  const toFetch = [];
118
121
  jids = Array.from(new Set(jids));
119
122
  for (let jid of jids) {
120
- const user = jidDecode(jid)?.user;
121
- jid = jidNormalizedUser(jid);
123
+ const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
124
+ jid = (0, WABinary_1.jidNormalizedUser)(jid);
122
125
  if (useCache) {
123
126
  const devices = userDevicesCache.get(user);
124
127
  if (devices) {
@@ -136,17 +139,19 @@ export const makeMessagesSocket = (config) => {
136
139
  if (!toFetch.length) {
137
140
  return deviceResults;
138
141
  }
139
- const query = new USyncQuery().withContext('message').withDeviceProtocol();
142
+ const query = new WAUSync_1.USyncQuery()
143
+ .withContext('message')
144
+ .withDeviceProtocol();
140
145
  for (const jid of toFetch) {
141
- query.withUser(new USyncUser().withId(jid));
146
+ query.withUser(new WAUSync_1.USyncUser().withId(jid));
142
147
  }
143
148
  const result = await sock.executeUSyncQuery(query);
144
149
  if (result) {
145
- const extracted = extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices);
150
+ const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
146
151
  const deviceMap = {};
147
152
  for (const item of extracted) {
148
153
  deviceMap[item.user] = deviceMap[item.user] || [];
149
- deviceMap[item.user]?.push(item);
154
+ deviceMap[item.user].push(item);
150
155
  deviceResults.push(item);
151
156
  }
152
157
  for (const key in deviceMap) {
@@ -162,10 +167,12 @@ export const makeMessagesSocket = (config) => {
162
167
  jidsRequiringFetch = jids;
163
168
  }
164
169
  else {
165
- const addrs = jids.map(jid => signalRepository.jidToSignalProtocolAddress(jid));
170
+ const addrs = jids.map(jid => (signalRepository
171
+ .jidToSignalProtocolAddress(jid)));
166
172
  const sessions = await authState.keys.get('session', addrs);
167
173
  for (const jid of jids) {
168
- const signalId = signalRepository.jidToSignalProtocolAddress(jid);
174
+ const signalId = signalRepository
175
+ .jidToSignalProtocolAddress(jid);
169
176
  if (!sessions[signalId]) {
170
177
  jidsRequiringFetch.push(jid);
171
178
  }
@@ -178,7 +185,7 @@ export const makeMessagesSocket = (config) => {
178
185
  attrs: {
179
186
  xmlns: 'encrypt',
180
187
  type: 'get',
181
- to: S_WHATSAPP_NET
188
+ to: WABinary_1.S_WHATSAPP_NET,
182
189
  },
183
190
  content: [
184
191
  {
@@ -186,33 +193,35 @@ export const makeMessagesSocket = (config) => {
186
193
  attrs: {},
187
194
  content: jidsRequiringFetch.map(jid => ({
188
195
  tag: 'user',
189
- attrs: { jid }
196
+ attrs: { jid },
190
197
  }))
191
198
  }
192
199
  ]
193
200
  });
194
- await parseAndInjectE2ESessions(result, signalRepository);
201
+ await (0, Utils_1.parseAndInjectE2ESessions)(result, signalRepository);
195
202
  didFetchNewSession = true;
196
203
  }
197
204
  return didFetchNewSession;
198
205
  };
199
206
  const sendPeerDataOperationMessage = async (pdoMessage) => {
207
+ var _a;
200
208
  //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
201
- if (!authState.creds.me?.id) {
202
- throw new Boom('Not authenticated');
209
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
210
+ throw new boom_1.Boom('Not authenticated');
203
211
  }
204
212
  const protocolMessage = {
205
213
  protocolMessage: {
206
214
  peerDataOperationRequestMessage: pdoMessage,
207
- type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
215
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
208
216
  }
209
217
  };
210
- const meJid = jidNormalizedUser(authState.creds.me.id);
218
+ const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
211
219
  const msgId = await relayMessage(meJid, protocolMessage, {
212
220
  additionalAttributes: {
213
221
  category: 'peer',
214
- push_priority: 'high_force'
215
- }
222
+ // eslint-disable-next-line camelcase
223
+ push_priority: 'high_force',
224
+ },
216
225
  });
217
226
  return msgId;
218
227
  };
@@ -227,52 +236,51 @@ export const makeMessagesSocket = (config) => {
227
236
  if (!jid) {
228
237
  return {};
229
238
  }
230
- const bytes = encodeWAMessage(patchedMessage);
231
- const { type, ciphertext } = await signalRepository.encryptMessage({ jid, data: bytes });
239
+ const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
240
+ const { type, ciphertext } = await signalRepository
241
+ .encryptMessage({ jid, data: bytes });
232
242
  if (type === 'pkmsg') {
233
243
  shouldIncludeDeviceIdentity = true;
234
244
  }
235
245
  const node = {
236
246
  tag: 'to',
237
247
  attrs: { jid },
238
- content: [
239
- {
248
+ content: [{
240
249
  tag: 'enc',
241
250
  attrs: {
242
251
  v: '2',
243
252
  type,
244
- ...(extraAttrs || {})
253
+ ...extraAttrs || {}
245
254
  },
246
255
  content: ciphertext
247
- }
248
- ]
256
+ }]
249
257
  };
250
258
  return node;
251
259
  }));
252
260
  return { nodes, shouldIncludeDeviceIdentity };
253
261
  };
254
262
  const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
263
+ var _a;
255
264
  const meId = authState.creds.me.id;
256
265
  let shouldIncludeDeviceIdentity = false;
257
- const { user, server } = jidDecode(jid);
266
+ const { user, server } = (0, WABinary_1.jidDecode)(jid);
258
267
  const statusJid = 'status@broadcast';
259
268
  const isGroup = server === 'g.us';
269
+ const isNewsletter = server == 'newsletter';
260
270
  const isStatus = jid === statusJid;
261
271
  const isLid = server === 'lid';
262
- const isNewsletter = server === 'newsletter';
263
- msgId = msgId || generateMessageIDV2(sock.user?.id);
272
+ msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
264
273
  useUserDevicesCache = useUserDevicesCache !== false;
265
274
  useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
266
275
  const participants = [];
267
- const destinationJid = !isStatus ? jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : 's.whatsapp.net') : statusJid;
276
+ const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
268
277
  const binaryNodeContent = [];
269
278
  const devices = [];
270
279
  const meMsg = {
271
280
  deviceSentMessage: {
272
281
  destinationJid,
273
282
  message
274
- },
275
- messageContextInfo: message.messageContextInfo
283
+ }
276
284
  };
277
285
  const extraAttrs = {};
278
286
  if (participant) {
@@ -280,47 +288,25 @@ export const makeMessagesSocket = (config) => {
280
288
  // only send to the specific device that asked for a retry
281
289
  // otherwise the message is sent out to every device that should be a recipient
282
290
  if (!isGroup && !isStatus) {
283
- additionalAttributes = { ...additionalAttributes, device_fanout: 'false' };
291
+ additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
284
292
  }
285
- const { user, device } = jidDecode(participant.jid);
293
+ const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
286
294
  devices.push({ user, device });
287
295
  }
288
296
  await authState.keys.transaction(async () => {
297
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
289
298
  const mediaType = getMediaType(message);
290
299
  if (mediaType) {
291
300
  extraAttrs['mediatype'] = mediaType;
292
301
  }
293
- if (isNewsletter) {
294
- // Patch message if needed, then encode as plaintext
295
- const patched = patchMessageBeforeSending ? await patchMessageBeforeSending(message, []) : message;
296
- const bytes = encodeNewsletterMessage(patched);
297
- binaryNodeContent.push({
298
- tag: 'plaintext',
299
- attrs: {},
300
- content: bytes
301
- });
302
- const stanza = {
303
- tag: 'message',
304
- attrs: {
305
- to: jid,
306
- id: msgId,
307
- type: getMessageType(message),
308
- ...(additionalAttributes || {})
309
- },
310
- content: binaryNodeContent
311
- };
312
- logger.debug({ msgId }, `sending newsletter message to ${jid}`);
313
- await sendNode(stanza);
314
- return;
315
- }
316
- if (normalizeMessageContent(message)?.pinInChatMessage) {
302
+ if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
317
303
  extraAttrs['decrypt-fail'] = 'hide';
318
304
  }
319
305
  if (isGroup || isStatus) {
320
306
  const [groupData, senderKeyMap] = await Promise.all([
321
307
  (async () => {
322
308
  let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
323
- if (groupData && Array.isArray(groupData?.participants)) {
309
+ if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
324
310
  logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
325
311
  }
326
312
  else if (!isStatus) {
@@ -337,14 +323,15 @@ export const makeMessagesSocket = (config) => {
337
323
  })()
338
324
  ]);
339
325
  if (!participant) {
340
- const participantsList = groupData && !isStatus ? groupData.participants.map(p => p.id) : [];
326
+ const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : [];
341
327
  if (isStatus && statusJidList) {
342
328
  participantsList.push(...statusJidList);
343
329
  }
344
330
  if (!isStatus) {
345
331
  additionalAttributes = {
346
332
  ...additionalAttributes,
347
- addressing_mode: groupData?.addressingMode || 'pn'
333
+ // eslint-disable-next-line camelcase
334
+ addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
348
335
  };
349
336
  }
350
337
  const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
@@ -352,18 +339,18 @@ export const makeMessagesSocket = (config) => {
352
339
  }
353
340
  const patched = await patchMessageBeforeSending(message);
354
341
  if (Array.isArray(patched)) {
355
- throw new Boom('Per-jid patching is not supported in groups');
342
+ throw new boom_1.Boom('Per-jid patching is not supported in groups');
356
343
  }
357
- const bytes = encodeWAMessage(patched);
344
+ const bytes = (0, Utils_1.encodeWAMessage)(patched);
358
345
  const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
359
346
  group: destinationJid,
360
347
  data: bytes,
361
- meId
348
+ meId,
362
349
  });
363
350
  const senderKeyJids = [];
364
351
  // ensure a connection is established with every device
365
352
  for (const { user, device } of devices) {
366
- const jid = jidEncode(user, groupData?.addressingMode === 'lid' ? 'lid' : 's.whatsapp.net', device);
353
+ const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
367
354
  if (!senderKeyMap[jid] || !!participant) {
368
355
  senderKeyJids.push(jid);
369
356
  // store that this person has had the sender keys sent to them
@@ -392,14 +379,37 @@ export const makeMessagesSocket = (config) => {
392
379
  });
393
380
  await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
394
381
  }
382
+ else if (isNewsletter) {
383
+ // Message edit
384
+ if ((_b = message.protocolMessage) === null || _b === void 0 ? void 0 : _b.editedMessage) {
385
+ msgId = (_c = message.protocolMessage.key) === null || _c === void 0 ? void 0 : _c.id;
386
+ message = message.protocolMessage.editedMessage;
387
+ }
388
+ // Message delete
389
+ if (((_d = message.protocolMessage) === null || _d === void 0 ? void 0 : _d.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
390
+ msgId = (_e = message.protocolMessage.key) === null || _e === void 0 ? void 0 : _e.id;
391
+ message = {};
392
+ }
393
+ const patched = await patchMessageBeforeSending(message, []);
394
+ if (Array.isArray(patched)) {
395
+ throw new boom_1.Boom('Per-jid patching is not supported in channel');
396
+ }
397
+ const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
398
+ binaryNodeContent.push({
399
+ tag: 'plaintext',
400
+ attrs: mediaType ? { mediatype: mediaType } : {},
401
+ content: bytes
402
+ });
403
+ }
395
404
  else {
396
- const { user: meUser } = jidDecode(meId);
405
+ const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
397
406
  if (!participant) {
398
407
  devices.push({ user });
399
- if (user !== meUser) {
400
- devices.push({ user: meUser });
401
- }
402
- if (additionalAttributes?.['category'] !== 'peer') {
408
+ // do not send message to self if the device is 0 (mobile)
409
+ if (!((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer' && user === meUser)) {
410
+ if (meDevice !== undefined && meDevice !== 0) {
411
+ devices.push({ user: meUser });
412
+ }
403
413
  const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
404
414
  devices.push(...additionalDevices);
405
415
  }
@@ -409,7 +419,7 @@ export const makeMessagesSocket = (config) => {
409
419
  const otherJids = [];
410
420
  for (const { user, device } of devices) {
411
421
  const isMe = user === meUser;
412
- const jid = jidEncode(isMe && isLid ? authState.creds?.me?.lid.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
422
+ 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);
413
423
  if (isMe) {
414
424
  meJids.push(jid);
415
425
  }
@@ -428,8 +438,8 @@ export const makeMessagesSocket = (config) => {
428
438
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
429
439
  }
430
440
  if (participants.length) {
431
- if (additionalAttributes?.['category'] === 'peer') {
432
- const peerNode = participants[0]?.content?.[0];
441
+ if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
442
+ const peerNode = (_j = (_h = participants[0]) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j[0];
433
443
  if (peerNode) {
434
444
  binaryNodeContent.push(peerNode); // push only enc
435
445
  }
@@ -446,7 +456,7 @@ export const makeMessagesSocket = (config) => {
446
456
  tag: 'message',
447
457
  attrs: {
448
458
  id: msgId,
449
- type: getMessageType(message),
459
+ type: isNewsletter ? getTypeMessage(message) : 'text',//getTypeMessage(message),
450
460
  ...(additionalAttributes || {})
451
461
  },
452
462
  content: binaryNodeContent
@@ -455,11 +465,11 @@ export const makeMessagesSocket = (config) => {
455
465
  // ensure the message is only sent to that person
456
466
  // if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
457
467
  if (participant) {
458
- if (isJidGroup(destinationJid)) {
468
+ if ((0, WABinary_1.isJidGroup)(destinationJid)) {
459
469
  stanza.attrs.to = destinationJid;
460
470
  stanza.attrs.participant = participant.jid;
461
471
  }
462
- else if (areJidsSameUser(participant.jid, meId)) {
472
+ else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
463
473
  stanza.attrs.to = participant.jid;
464
474
  stanza.attrs.recipient = destinationJid;
465
475
  }
@@ -471,28 +481,88 @@ export const makeMessagesSocket = (config) => {
471
481
  stanza.attrs.to = destinationJid;
472
482
  }
473
483
  if (shouldIncludeDeviceIdentity) {
474
- ;
475
484
  stanza.content.push({
476
485
  tag: 'device-identity',
477
486
  attrs: {},
478
- content: encodeSignedDeviceIdentity(authState.creds.account, true)
487
+ content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
479
488
  });
480
489
  logger.debug({ jid }, 'adding device identity');
481
490
  }
491
+ const buttonType = getButtonType(message);
492
+ if (buttonType) {
493
+ stanza.content.push({
494
+ tag: 'biz',
495
+ attrs: {},
496
+ content: [
497
+ {
498
+ tag: buttonType,
499
+ attrs: getButtonArgs(message),
500
+ }
501
+ ]
502
+ });
503
+ logger.debug({ jid }, 'adding business node');
504
+ }
482
505
  if (additionalNodes && additionalNodes.length > 0) {
483
- ;
484
506
  stanza.content.push(...additionalNodes);
485
507
  }
508
+ else {
509
+ if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && (((_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))) {
510
+ stanza.content.push({
511
+ tag: 'biz',
512
+ attrs: {},
513
+ content: [{
514
+ tag: 'interactive',
515
+ attrs: {
516
+ type: 'native_flow',
517
+ v: '1'
518
+ },
519
+ content: [{
520
+ tag: 'native_flow',
521
+ attrs: { name: 'quick_reply' }
522
+ }]
523
+ }]
524
+ });
525
+ }
526
+ }
486
527
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
487
528
  await sendNode(stanza);
488
529
  });
489
530
  return msgId;
490
531
  };
491
- const getMessageType = (message) => {
492
- if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
532
+ /*const getMessageType = (message) => {
533
+ if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3 || message.pollUpdateMessage) {
493
534
  return 'poll';
494
535
  }
495
536
  return 'text';
537
+ };*/
538
+ const getTypeMessage = (msg) => {
539
+ if (msg.viewOnceMessage) {
540
+ return getTypeMessage(msg.viewOnceMessage.message);
541
+ }
542
+ else if (msg.viewOnceMessageV2) {
543
+ return getTypeMessage(msg.viewOnceMessageV2.message);
544
+ }
545
+ else if (msg.viewOnceMessageV2Extension) {
546
+ return getTypeMessage(msg.viewOnceMessageV2Extension.message);
547
+ }
548
+ else if (msg.ephemeralMessage) {
549
+ return getTypeMessage(msg.ephemeralMessage.message);
550
+ }
551
+ else if (msg.documentWithCaptionMessage) {
552
+ return getTypeMessage(msg.documentWithCaptionMessage.message);
553
+ }
554
+ else if (msg.reactionMessage) {
555
+ return 'reaction';
556
+ }
557
+ else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
558
+ return 'reaction';
559
+ }
560
+ else if (getMediaType(msg)) {
561
+ return 'media';
562
+ }
563
+ else {
564
+ return 'text';
565
+ }
496
566
  };
497
567
  const getMediaType = (message) => {
498
568
  if (message.imageMessage) {
@@ -541,12 +611,45 @@ export const makeMessagesSocket = (config) => {
541
611
  return 'url';
542
612
  }
543
613
  };
614
+ const getButtonType = (message) => {
615
+ if (message.buttonsMessage) {
616
+ return 'buttons';
617
+ }
618
+ else if (message.buttonsResponseMessage) {
619
+ return 'buttons_response';
620
+ }
621
+ else if (message.interactiveResponseMessage) {
622
+ return 'interactive_response';
623
+ }
624
+ else if (message.listMessage) {
625
+ return 'list';
626
+ }
627
+ else if (message.listResponseMessage) {
628
+ return 'list_response';
629
+ }
630
+ };
631
+ const getButtonArgs = (message) => {
632
+ if (message.templateMessage) {
633
+ // TODO: Add attributes
634
+ return {};
635
+ }
636
+ else if (message.listMessage) {
637
+ const type = message.listMessage.listType;
638
+ if (!type) {
639
+ throw new boom_1.Boom('Expected list type inside message');
640
+ }
641
+ return { v: '2', type: ListType[type].toLowerCase() };
642
+ }
643
+ else {
644
+ return {};
645
+ }
646
+ };
544
647
  const getPrivacyTokens = async (jids) => {
545
- const t = unixTimestampSeconds().toString();
648
+ const t = (0, Utils_1.unixTimestampSeconds)().toString();
546
649
  const result = await query({
547
650
  tag: 'iq',
548
651
  attrs: {
549
- to: S_WHATSAPP_NET,
652
+ to: WABinary_1.S_WHATSAPP_NET,
550
653
  type: 'set',
551
654
  xmlns: 'privacy'
552
655
  },
@@ -557,7 +660,7 @@ export const makeMessagesSocket = (config) => {
557
660
  content: jids.map(jid => ({
558
661
  tag: 'token',
559
662
  attrs: {
560
- jid: jidNormalizedUser(jid),
663
+ jid: (0, WABinary_1.jidNormalizedUser)(jid),
561
664
  t,
562
665
  type: 'trusted_contact'
563
666
  }
@@ -567,8 +670,8 @@ export const makeMessagesSocket = (config) => {
567
670
  });
568
671
  return result;
569
672
  };
570
- const waUploadToServer = getWAUploadToServer(config, refreshMediaConn);
571
- const waitForMsgMediaUpdate = bindWaitForEvent(ev, 'messages.media-update');
673
+ const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
674
+ const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
572
675
  return {
573
676
  ...sock,
574
677
  getPrivacyTokens,
@@ -576,18 +679,19 @@ export const makeMessagesSocket = (config) => {
576
679
  relayMessage,
577
680
  sendReceipt,
578
681
  sendReceipts,
682
+ getButtonArgs,
579
683
  readMessages,
580
684
  refreshMediaConn,
581
685
  waUploadToServer,
582
686
  fetchPrivacySettings,
583
- sendPeerDataOperationMessage,
584
- createParticipantNodes,
585
687
  getUSyncDevices,
688
+ createParticipantNodes,
689
+ sendPeerDataOperationMessage,
586
690
  updateMediaMessage: async (message) => {
587
- const content = assertMediaContent(message.message);
691
+ const content = (0, Utils_1.assertMediaContent)(message.message);
588
692
  const mediaKey = content.mediaKey;
589
693
  const meId = authState.creds.me.id;
590
- const node = await encryptMediaRetryRequest(message.key, mediaKey, meId);
694
+ const node = await (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
591
695
  let error = undefined;
592
696
  await Promise.all([
593
697
  sendNode(node),
@@ -599,16 +703,13 @@ export const makeMessagesSocket = (config) => {
599
703
  }
600
704
  else {
601
705
  try {
602
- const media = await decryptMediaRetryData(result.media, mediaKey, result.key.id);
603
- if (media.result !== proto.MediaRetryNotification.ResultType.SUCCESS) {
604
- const resultStr = proto.MediaRetryNotification.ResultType[media.result];
605
- throw new Boom(`Media re-upload failed by device (${resultStr})`, {
606
- data: media,
607
- statusCode: getStatusCodeForMediaRetry(media.result) || 404
608
- });
706
+ const media = await (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
707
+ if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
708
+ const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
709
+ throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
609
710
  }
610
711
  content.directPath = media.directPath;
611
- content.url = getUrlFromDirectPath(content.directPath);
712
+ content.url = (0, Utils_1.getUrlFromDirectPath)(content.directPath);
612
713
  logger.debug({ directPath: media.directPath, key: result.key }, 'media update successful');
613
714
  }
614
715
  catch (err) {
@@ -622,87 +723,109 @@ export const makeMessagesSocket = (config) => {
622
723
  if (error) {
623
724
  throw error;
624
725
  }
625
- ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
726
+ ev.emit('messages.update', [
727
+ { key: message.key, update: { message: message.message } }
728
+ ]);
626
729
  return message;
627
730
  },
628
731
  sendMessage: async (jid, content, options = {}) => {
732
+ var _a, _b, _c;
629
733
  const userJid = authState.creds.me.id;
630
734
  if (typeof content === 'object' &&
631
735
  'disappearingMessagesInChat' in content &&
632
736
  typeof content['disappearingMessagesInChat'] !== 'undefined' &&
633
- isJidGroup(jid)) {
737
+ (0, WABinary_1.isJidGroup)(jid)) {
634
738
  const { disappearingMessagesInChat } = content;
635
- const value = typeof disappearingMessagesInChat === 'boolean'
636
- ? disappearingMessagesInChat
637
- ? WA_DEFAULT_EPHEMERAL
638
- : 0
639
- : disappearingMessagesInChat;
739
+ const value = typeof disappearingMessagesInChat === 'boolean' ?
740
+ (disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
741
+ disappearingMessagesInChat;
640
742
  await groupToggleEphemeral(jid, value);
641
743
  }
642
744
  else {
643
- const fullMsg = await generateWAMessage(jid, content, {
745
+ let mediaHandle;
746
+ const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
644
747
  logger,
645
748
  userJid,
646
- getUrlInfo: text => getUrlInfo(text, {
749
+ getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
647
750
  thumbnailWidth: linkPreviewImageThumbnailWidth,
648
751
  fetchOpts: {
649
752
  timeout: 3000,
650
- ...(axiosOptions || {})
753
+ ...axiosOptions || {}
651
754
  },
652
755
  logger,
653
- uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
756
+ uploadImage: generateHighQualityLinkPreview
757
+ ? waUploadToServer
758
+ : undefined
654
759
  }),
655
- //TODO: CACHE
656
760
  getProfilePicUrl: sock.profilePictureUrl,
657
- upload: waUploadToServer,
761
+ upload: async (readStream, opts) => {
762
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
763
+ mediaHandle = up.handle;
764
+ return up;
765
+ },
658
766
  mediaCache: config.mediaCache,
659
767
  options: config.options,
660
- messageId: generateMessageIDV2(sock.user?.id),
661
- ...options
768
+ messageId: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
769
+ ...options,
662
770
  });
663
771
  const isDeleteMsg = 'delete' in content && !!content.delete;
664
772
  const isEditMsg = 'edit' in content && !!content.edit;
665
773
  const isPinMsg = 'pin' in content && !!content.pin;
774
+ const isKeepMsg = 'keep' in content && content.keep;
666
775
  const isPollMessage = 'poll' in content && !!content.poll;
776
+ const isAiMsg = 'ai' in content && !!content.ai;
667
777
  const additionalAttributes = {};
668
778
  const additionalNodes = [];
669
779
  // required for delete
670
780
  if (isDeleteMsg) {
671
781
  // if the chat is a group, and I am not the author, then delete the message as an admin
672
- if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
782
+ if (((0, WABinary_1.isJidGroup)((_b = content.delete) === null || _b === void 0 ? void 0 : _b.remoteJid) && !((_c = content.delete) === null || _c === void 0 ? void 0 : _c.fromMe)) || (0, WABinary_1.isJidNewsletter)(jid)) {
673
783
  additionalAttributes.edit = '8';
674
784
  }
675
785
  else {
676
786
  additionalAttributes.edit = '7';
677
787
  }
788
+ // required for edit message
678
789
  }
679
790
  else if (isEditMsg) {
680
- additionalAttributes.edit = '1';
791
+ additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
792
+ // required for pin message
681
793
  }
682
794
  else if (isPinMsg) {
683
795
  additionalAttributes.edit = '2';
796
+ // required for keep message
797
+ }
798
+ else if (isKeepMsg) {
799
+ additionalAttributes.edit = '6';
800
+ // required for polling message
684
801
  }
685
802
  else if (isPollMessage) {
686
803
  additionalNodes.push({
687
804
  tag: 'meta',
688
805
  attrs: {
689
806
  polltype: 'creation'
690
- }
807
+ },
691
808
  });
809
+ // required to display AI icon on message
810
+ }
811
+ else if (isAiMsg) {
812
+ additionalNodes.push({
813
+ attrs: {
814
+ biz_bot: '1'
815
+ },
816
+ tag: "bot"
817
+ });
818
+ }
819
+ if (mediaHandle) {
820
+ additionalAttributes['media_id'] = mediaHandle;
692
821
  }
693
822
  if ('cachedGroupMetadata' in options) {
694
823
  console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
695
824
  }
696
- await relayMessage(jid, fullMsg.message, {
697
- messageId: fullMsg.key.id,
698
- useCachedGroupMetadata: options.useCachedGroupMetadata,
699
- additionalAttributes,
700
- statusJidList: options.statusJidList,
701
- additionalNodes
702
- });
825
+ await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
703
826
  if (config.emitOwnEvents) {
704
827
  process.nextTick(() => {
705
- processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
828
+ processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
706
829
  });
707
830
  }
708
831
  return fullMsg;
@@ -710,4 +833,4 @@ export const makeMessagesSocket = (config) => {
710
833
  }
711
834
  };
712
835
  };
713
- //# sourceMappingURL=messages-send.js.map
836
+ exports.makeMessagesSocket = makeMessagesSocket;