cuki-bailx 1.2.5 → 1.2.6

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 (157) hide show
  1. package/LICENSE +21 -0
  2. package/WAProto/GenerateStatics.sh +4 -0
  3. package/WAProto/WAProto.proto +4775 -0
  4. package/WAProto/index.js +56886 -17506
  5. package/engine-requirements.js +1 -1
  6. package/lib/Defaults/index.js +98 -108
  7. package/lib/Defaults/vyzen-baileysx-version.json +3 -0
  8. package/lib/Signal/libsignal.js +2 -0
  9. package/lib/Socket/Client/index.js +2 -3
  10. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +54 -5
  11. package/lib/Socket/chats.js +224 -173
  12. package/lib/Socket/groups.js +20 -5
  13. package/lib/Socket/index.js +2 -2
  14. package/lib/Socket/messages-recv.js +10 -66
  15. package/lib/Socket/messages-send.js +379 -312
  16. package/lib/Socket/newsletter.js +54 -40
  17. package/lib/Socket/socket.js +58 -32
  18. package/lib/Store/index.js +1 -3
  19. package/lib/Store/make-in-memory-store.js +27 -15
  20. package/lib/Store/make-ordered-dictionary.js +2 -2
  21. package/lib/Types/Label.js +1 -1
  22. package/lib/Types/LabelAssociation.js +1 -1
  23. package/lib/Types/Message.js +0 -2
  24. package/lib/Types/Newsletter.js +3 -17
  25. package/lib/Types/index.js +2 -2
  26. package/lib/Utils/auth-utils.js +6 -13
  27. package/lib/Utils/baileys-event-stream.js +1 -1
  28. package/lib/Utils/browser-utils.js +35 -0
  29. package/lib/Utils/business.js +2 -2
  30. package/lib/Utils/chat-utils.js +36 -35
  31. package/lib/Utils/crypto.js +71 -29
  32. package/lib/Utils/decode-wa-message.js +65 -56
  33. package/lib/Utils/event-buffer.js +13 -9
  34. package/lib/Utils/generics.js +107 -29
  35. package/lib/Utils/history.js +4 -6
  36. package/lib/Utils/index.js +2 -0
  37. package/lib/Utils/link-preview.js +34 -1
  38. package/lib/Utils/lt-hash.js +6 -6
  39. package/lib/Utils/message-retry-manager.js +128 -0
  40. package/lib/Utils/messages-media.js +263 -115
  41. package/lib/Utils/messages.js +500 -93
  42. package/lib/Utils/noise-handler.js +18 -23
  43. package/lib/Utils/process-message.js +108 -25
  44. package/lib/Utils/signal.js +37 -35
  45. package/lib/Utils/use-multi-file-auth-state.js +51 -6
  46. package/lib/Utils/validate-connection.js +90 -66
  47. package/lib/WABinary/constants.js +1276 -13
  48. package/lib/WABinary/decode.js +26 -13
  49. package/lib/WABinary/encode.js +39 -17
  50. package/lib/WABinary/generic-utils.js +2 -85
  51. package/lib/WABinary/jid-utils.js +28 -5
  52. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  53. package/lib/index.js +18 -5
  54. package/package.json +109 -104
  55. package/lib/Defaults/baileys-version.json +0 -3
  56. package/lib/Defaults/index.d.ts +0 -53
  57. package/lib/Defaults/phonenumber-mcc.json +0 -223
  58. package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
  59. package/lib/Signal/Group/group-session-builder.d.ts +0 -14
  60. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  61. package/lib/Signal/Group/index.d.ts +0 -11
  62. package/lib/Signal/Group/keyhelper.d.ts +0 -10
  63. package/lib/Signal/Group/queue-job.d.ts +0 -1
  64. package/lib/Signal/Group/sender-chain-key.d.ts +0 -13
  65. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -16
  66. package/lib/Signal/Group/sender-key-message.d.ts +0 -18
  67. package/lib/Signal/Group/sender-key-name.d.ts +0 -17
  68. package/lib/Signal/Group/sender-key-record.d.ts +0 -30
  69. package/lib/Signal/Group/sender-key-state.d.ts +0 -38
  70. package/lib/Signal/Group/sender-message-key.d.ts +0 -11
  71. package/lib/Signal/libsignal.d.ts +0 -3
  72. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  73. package/lib/Socket/Client/index.d.ts +0 -3
  74. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  75. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  76. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  77. package/lib/Socket/business.d.ts +0 -171
  78. package/lib/Socket/chats.d.ts +0 -80
  79. package/lib/Socket/dugong.d.ts +0 -219
  80. package/lib/Socket/dugong.js +0 -441
  81. package/lib/Socket/groups.d.ts +0 -115
  82. package/lib/Socket/index.d.ts +0 -173
  83. package/lib/Socket/messages-recv.d.ts +0 -161
  84. package/lib/Socket/messages-send.d.ts +0 -149
  85. package/lib/Socket/newsletter.d.ts +0 -134
  86. package/lib/Socket/registration.d.ts +0 -267
  87. package/lib/Socket/registration.js +0 -166
  88. package/lib/Socket/socket.d.ts +0 -43
  89. package/lib/Socket/socket.js.bak +0 -630
  90. package/lib/Socket/usync.d.ts +0 -36
  91. package/lib/Store/index.d.ts +0 -3
  92. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  93. package/lib/Store/make-cache-manager-store.js +0 -83
  94. package/lib/Store/make-in-memory-store.d.ts +0 -118
  95. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  96. package/lib/Store/object-repository.d.ts +0 -10
  97. package/lib/Types/Auth.d.ts +0 -110
  98. package/lib/Types/Call.d.ts +0 -13
  99. package/lib/Types/Chat.d.ts +0 -102
  100. package/lib/Types/Contact.d.ts +0 -19
  101. package/lib/Types/Events.d.ts +0 -157
  102. package/lib/Types/GroupMetadata.d.ts +0 -55
  103. package/lib/Types/Label.d.ts +0 -35
  104. package/lib/Types/LabelAssociation.d.ts +0 -29
  105. package/lib/Types/Message.d.ts +0 -273
  106. package/lib/Types/Newsletter.d.ts +0 -92
  107. package/lib/Types/Product.d.ts +0 -78
  108. package/lib/Types/Signal.d.ts +0 -57
  109. package/lib/Types/Socket.d.ts +0 -111
  110. package/lib/Types/State.d.ts +0 -27
  111. package/lib/Types/USync.d.ts +0 -25
  112. package/lib/Types/index.d.ts +0 -57
  113. package/lib/Utils/auth-utils.d.ts +0 -18
  114. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  115. package/lib/Utils/business.d.ts +0 -22
  116. package/lib/Utils/chat-utils.d.ts +0 -71
  117. package/lib/Utils/crypto.d.ts +0 -41
  118. package/lib/Utils/decode-wa-message.d.ts +0 -19
  119. package/lib/Utils/event-buffer.d.ts +0 -35
  120. package/lib/Utils/generics.d.ts +0 -92
  121. package/lib/Utils/history.d.ts +0 -15
  122. package/lib/Utils/index.d.ts +0 -17
  123. package/lib/Utils/link-preview.d.ts +0 -21
  124. package/lib/Utils/logger.d.ts +0 -4
  125. package/lib/Utils/lt-hash.d.ts +0 -12
  126. package/lib/Utils/make-mutex.d.ts +0 -7
  127. package/lib/Utils/messages-media.d.ts +0 -116
  128. package/lib/Utils/messages.d.ts +0 -77
  129. package/lib/Utils/noise-handler.d.ts +0 -21
  130. package/lib/Utils/process-message.d.ts +0 -41
  131. package/lib/Utils/signal.d.ts +0 -32
  132. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  133. package/lib/Utils/validate-connection.d.ts +0 -11
  134. package/lib/WABinary/constants.d.ts +0 -27
  135. package/lib/WABinary/decode.d.ts +0 -7
  136. package/lib/WABinary/encode.d.ts +0 -3
  137. package/lib/WABinary/generic-utils.d.ts +0 -16
  138. package/lib/WABinary/index.d.ts +0 -5
  139. package/lib/WABinary/jid-utils.d.ts +0 -31
  140. package/lib/WABinary/types.d.ts +0 -18
  141. package/lib/WAM/BinaryInfo.d.ts +0 -17
  142. package/lib/WAM/constants.d.ts +0 -38
  143. package/lib/WAM/encode.d.ts +0 -3
  144. package/lib/WAM/index.d.ts +0 -3
  145. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  146. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  147. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  148. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  149. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  150. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  151. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  152. package/lib/WAUSync/USyncQuery.d.ts +0 -28
  153. package/lib/WAUSync/USyncUser.d.ts +0 -12
  154. package/lib/WAUSync/index.d.ts +0 -3
  155. package/lib/index.d.ts +0 -12
  156. package/lib/index.js.bak +0 -48
  157. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -1,44 +1,25 @@
1
1
  "use strict";
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
4
+ };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.makeMessagesSocket = void 0;
7
7
  const boom_1 = require("@hapi/boom");
8
- const node_cache_1 = __importDefault(require("node-cache"));
8
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
9
+ const crypto_1 = require("crypto");
9
10
  const WAProto_1 = require("../../WAProto");
10
11
  const Defaults_1 = require("../Defaults");
11
- const axios_1 = require("axios")
12
12
  const Utils_1 = require("../Utils");
13
13
  const link_preview_1 = require("../Utils/link-preview");
14
14
  const WABinary_1 = require("../WABinary");
15
+ const WAUSync_1 = require("../WAUSync");
15
16
  const newsletter_1 = require("./newsletter");
16
- const kikyy = require('./dugong');
17
- var ListType = WAProto_1.proto.Message.ListMessage.ListType;
18
17
  const makeMessagesSocket = (config) => {
19
- const {
20
- logger,
21
- linkPreviewImageThumbnailWidth,
22
- generateHighQualityLinkPreview,
23
- options: axiosOptions,
24
- patchMessageBeforeSending
25
- } = config;
18
+ const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
26
19
  const sock = (0, newsletter_1.makeNewsletterSocket)(config);
27
- const {
28
- ev,
29
- authState,
30
- processingMutex,
31
- signalRepository,
32
- upsertMessage,
33
- query,
34
- fetchPrivacySettings,
35
- generateMessageTag,
36
- sendNode,
37
- groupMetadata,
38
- groupToggleEphemeral
39
- } = sock;
20
+ const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, } = sock;
40
21
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
41
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
22
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
42
23
  useClones: false
43
24
  });
44
25
  let mediaConn;
@@ -97,7 +78,7 @@ const makeMessagesSocket = (config) => {
97
78
  }
98
79
  }
99
80
  if (type) {
100
- node.attrs.type = (0, WABinary_1.isJidNewsLetter)(jid) ? 'read-self' : type;
81
+ node.attrs.type = (0, WABinary_1.isJidNewsletter)(jid) ? 'read-self' : type;
101
82
  }
102
83
  const remainingMessageIds = messageIds.slice(1);
103
84
  if (remainingMessageIds.length) {
@@ -136,66 +117,46 @@ const makeMessagesSocket = (config) => {
136
117
  if (!useCache) {
137
118
  logger.debug('not using cache for devices');
138
119
  }
139
- const users = [];
120
+ const toFetch = [];
140
121
  jids = Array.from(new Set(jids));
141
122
  for (let jid of jids) {
142
123
  const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
143
124
  jid = (0, WABinary_1.jidNormalizedUser)(jid);
144
- const devices = userDevicesCache.get(user);
145
- if (devices && useCache) {
146
- deviceResults.push(...devices);
147
- logger.trace({ user }, 'using cache for devices');
125
+ if (useCache) {
126
+ const devices = userDevicesCache.get(user);
127
+ if (devices) {
128
+ deviceResults.push(...devices);
129
+ logger.trace({ user }, 'using cache for devices');
130
+ }
131
+ else {
132
+ toFetch.push(jid);
133
+ }
148
134
  }
149
135
  else {
150
- users.push({ tag: 'user', attrs: { jid } });
136
+ toFetch.push(jid);
151
137
  }
152
138
  }
153
- if (!users.length) {
139
+ if (!toFetch.length) {
154
140
  return deviceResults;
155
141
  }
156
- const iq = {
157
- tag: 'iq',
158
- attrs: {
159
- to: WABinary_1.S_WHATSAPP_NET,
160
- type: 'get',
161
- xmlns: 'usync',
162
- },
163
- content: [
164
- {
165
- tag: 'usync',
166
- attrs: {
167
- sid: generateMessageTag(),
168
- mode: 'query',
169
- last: 'true',
170
- index: '0',
171
- context: 'message',
172
- },
173
- content: [
174
- {
175
- tag: 'query',
176
- attrs: {},
177
- content: [
178
- {
179
- tag: 'devices',
180
- attrs: { version: '2' }
181
- }
182
- ]
183
- },
184
- { tag: 'list', attrs: {}, content: users }
185
- ]
186
- },
187
- ],
188
- };
189
- const result = await query(iq);
190
- const extracted = (0, Utils_1.extractDeviceJids)(result, authState.creds.me.id, ignoreZeroDevices);
191
- const deviceMap = {};
192
- for (const item of extracted) {
193
- deviceMap[item.user] = deviceMap[item.user] || [];
194
- deviceMap[item.user].push(item);
195
- deviceResults.push(item);
196
- }
197
- for (const key in deviceMap) {
198
- userDevicesCache.set(key, deviceMap[key]);
142
+ const query = new WAUSync_1.USyncQuery()
143
+ .withContext('message')
144
+ .withDeviceProtocol();
145
+ for (const jid of toFetch) {
146
+ query.withUser(new WAUSync_1.USyncUser().withId(jid));
147
+ }
148
+ const result = await sock.executeUSyncQuery(query);
149
+ if (result) {
150
+ const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
151
+ const deviceMap = {};
152
+ for (const item of extracted) {
153
+ deviceMap[item.user] = deviceMap[item.user] || [];
154
+ deviceMap[item.user].push(item);
155
+ deviceResults.push(item);
156
+ }
157
+ for (const key in deviceMap) {
158
+ userDevicesCache.set(key, deviceMap[key]);
159
+ }
199
160
  }
200
161
  return deviceResults;
201
162
  };
@@ -242,11 +203,40 @@ const makeMessagesSocket = (config) => {
242
203
  }
243
204
  return didFetchNewSession;
244
205
  };
206
+ const sendPeerDataOperationMessage = async (pdoMessage) => {
207
+ var _a;
208
+ //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
209
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
210
+ throw new boom_1.Boom('Not authenticated');
211
+ }
212
+ const protocolMessage = {
213
+ protocolMessage: {
214
+ peerDataOperationRequestMessage: pdoMessage,
215
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
216
+ }
217
+ };
218
+ const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
219
+ const msgId = await relayMessage(meJid, protocolMessage, {
220
+ additionalAttributes: {
221
+ category: 'peer',
222
+ // eslint-disable-next-line camelcase
223
+ push_priority: 'high_force',
224
+ },
225
+ });
226
+ return msgId;
227
+ };
245
228
  const createParticipantNodes = async (jids, message, extraAttrs) => {
246
- const patched = await patchMessageBeforeSending(message, jids);
247
- const bytes = (0, Utils_1.encodeWAMessage)(patched);
229
+ let patched = await patchMessageBeforeSending(message, jids);
230
+ if (!Array.isArray(patched)) {
231
+ patched = jids ? jids.map(jid => ({ recipientJid: jid, ...patched })) : [patched];
232
+ }
248
233
  let shouldIncludeDeviceIdentity = false;
249
- const nodes = await Promise.all(jids.map(async (jid) => {
234
+ const nodes = await Promise.all(patched.map(async (patchedMessageWithJid) => {
235
+ const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid;
236
+ if (!jid) {
237
+ return {};
238
+ }
239
+ const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
250
240
  const { type, ciphertext } = await signalRepository
251
241
  .encryptMessage({ jid, data: bytes });
252
242
  if (type === 'pkmsg') {
@@ -268,20 +258,20 @@ const makeMessagesSocket = (config) => {
268
258
  return node;
269
259
  }));
270
260
  return { nodes, shouldIncludeDeviceIdentity };
271
- }; //apela
272
- const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList, AI = true }) => {
261
+ };
262
+ const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
263
+ var _a;
273
264
  const meId = authState.creds.me.id;
274
265
  let shouldIncludeDeviceIdentity = false;
275
- let didPushAdditional = false
276
266
  const { user, server } = (0, WABinary_1.jidDecode)(jid);
277
267
  const statusJid = 'status@broadcast';
278
268
  const isGroup = server === 'g.us';
269
+ const isNewsletter = server === 'newsletter';
279
270
  const isStatus = jid === statusJid;
280
271
  const isLid = server === 'lid';
281
- const isPrivate = server === 's.whatsapp.net'
282
- const isNewsletter = server === 'newsletter';
283
- msgId = msgId || (0, Utils_1.generateMessageID)();
272
+ msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
284
273
  useUserDevicesCache = useUserDevicesCache !== false;
274
+ useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
285
275
  const participants = [];
286
276
  const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
287
277
  const binaryNodeContent = [];
@@ -290,8 +280,10 @@ const makeMessagesSocket = (config) => {
290
280
  deviceSentMessage: {
291
281
  destinationJid,
292
282
  message
293
- }
283
+ },
284
+ messageContextInfo: message.messageContextInfo
294
285
  };
286
+ const extraAttrs = {};
295
287
  if (participant) {
296
288
  // when the retry request is not for a group
297
289
  // only send to the specific device that asked for a retry
@@ -303,16 +295,22 @@ const makeMessagesSocket = (config) => {
303
295
  devices.push({ user, device });
304
296
  }
305
297
  await authState.keys.transaction(async () => {
306
- var _a, _b, _c, _d, _e, _f;
298
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
307
299
  const mediaType = getMediaType(message);
300
+ if (mediaType) {
301
+ extraAttrs['mediatype'] = mediaType;
302
+ }
303
+ if ((_a = (0, Utils_1.normalizeMessageContent)(message)) === null || _a === void 0 ? void 0 : _a.pinInChatMessage) {
304
+ extraAttrs['decrypt-fail'] = 'hide';
305
+ }
308
306
  if (isGroup || isStatus) {
309
307
  const [groupData, senderKeyMap] = await Promise.all([
310
308
  (async () => {
311
- let groupData = cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
312
- if (groupData) {
309
+ let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
310
+ if (groupData && Array.isArray(groupData === null || groupData === void 0 ? void 0 : groupData.participants)) {
313
311
  logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
314
312
  }
315
- if (!groupData && !isStatus) {
313
+ else if (!isStatus) {
316
314
  groupData = await groupMetadata(jid);
317
315
  }
318
316
  return groupData;
@@ -330,10 +328,20 @@ const makeMessagesSocket = (config) => {
330
328
  if (isStatus && statusJidList) {
331
329
  participantsList.push(...statusJidList);
332
330
  }
331
+ if (!isStatus) {
332
+ additionalAttributes = {
333
+ ...additionalAttributes,
334
+ // eslint-disable-next-line camelcase
335
+ addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
336
+ };
337
+ }
333
338
  const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
334
339
  devices.push(...additionalDevices);
335
340
  }
336
- const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
341
+ const patched = await patchMessageBeforeSending(message);
342
+ if (Array.isArray(patched)) {
343
+ throw new boom_1.Boom('Per-jid patching is not supported in groups');
344
+ }
337
345
  const bytes = (0, Utils_1.encodeWAMessage)(patched);
338
346
  const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
339
347
  group: destinationJid,
@@ -361,7 +369,7 @@ const makeMessagesSocket = (config) => {
361
369
  }
362
370
  };
363
371
  await assertSessions(senderKeyJids, false);
364
- const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, mediaType ? { mediatype: mediaType } : undefined);
372
+ const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs);
365
373
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
366
374
  participants.push(...result.nodes);
367
375
  }
@@ -374,17 +382,20 @@ const makeMessagesSocket = (config) => {
374
382
  }
375
383
  else if (isNewsletter) {
376
384
  // Message edit
377
- if ((_a = message.protocolMessage) === null || _a === void 0 ? void 0 : _a.editedMessage) {
378
- msgId = (_b = message.protocolMessage.key) === null || _b === void 0 ? void 0 : _b.id;
385
+ if ((_b = message.protocolMessage) === null || _b === void 0 ? void 0 : _b.editedMessage) {
386
+ msgId = (_c = message.protocolMessage.key) === null || _c === void 0 ? void 0 : _c.id;
379
387
  message = message.protocolMessage.editedMessage;
380
388
  }
381
389
  // Message delete
382
- if (((_c = message.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
383
- msgId = (_d = message.protocolMessage.key) === null || _d === void 0 ? void 0 : _d.id;
390
+ if (((_d = message.protocolMessage) === null || _d === void 0 ? void 0 : _d.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
391
+ msgId = (_e = message.protocolMessage.key) === null || _e === void 0 ? void 0 : _e.id;
384
392
  message = {};
385
393
  }
386
394
  const patched = await patchMessageBeforeSending(message, []);
387
- const bytes = WAProto_1.proto.Message.encode(patched).finish();
395
+ if (Array.isArray(patched)) {
396
+ throw new boom_1.Boom('Per-jid patching is not supported in channel');
397
+ }
398
+ const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
388
399
  binaryNodeContent.push({
389
400
  tag: 'plaintext',
390
401
  attrs: mediaType ? { mediatype: mediaType } : {},
@@ -392,22 +403,23 @@ const makeMessagesSocket = (config) => {
392
403
  });
393
404
  }
394
405
  else {
395
- const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
406
+ const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
396
407
  if (!participant) {
397
408
  devices.push({ user });
398
- // do not send message to self if the device is 0 (mobile)
399
- if (meDevice !== undefined && meDevice !== 0) {
409
+ if (user !== meUser) {
400
410
  devices.push({ user: meUser });
401
411
  }
402
- const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
403
- devices.push(...additionalDevices);
412
+ if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
413
+ const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
414
+ devices.push(...additionalDevices);
415
+ }
404
416
  }
405
417
  const allJids = [];
406
418
  const meJids = [];
407
419
  const otherJids = [];
408
420
  for (const { user, device } of devices) {
409
421
  const isMe = user === meUser;
410
- const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_f = (_e = authState.creds) === null || _e === void 0 ? void 0 : _e.me) === null || _f === void 0 ? void 0 : _f.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);
411
423
  if (isMe) {
412
424
  meJids.push(jid);
413
425
  }
@@ -418,19 +430,27 @@ const makeMessagesSocket = (config) => {
418
430
  }
419
431
  await assertSessions(allJids, false);
420
432
  const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
421
- createParticipantNodes(meJids, meMsg, mediaType ? { mediatype: mediaType } : undefined),
422
- createParticipantNodes(otherJids, message, mediaType ? { mediatype: mediaType } : undefined)
433
+ createParticipantNodes(meJids, meMsg, extraAttrs),
434
+ createParticipantNodes(otherJids, message, extraAttrs)
423
435
  ]);
424
436
  participants.push(...meNodes);
425
437
  participants.push(...otherNodes);
426
438
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
427
439
  }
428
440
  if (participants.length) {
429
- binaryNodeContent.push({
430
- tag: 'participants',
431
- attrs: {},
432
- content: participants
433
- });
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];
443
+ if (peerNode) {
444
+ binaryNodeContent.push(peerNode); // push only enc
445
+ }
446
+ }
447
+ else {
448
+ binaryNodeContent.push({
449
+ tag: 'participants',
450
+ attrs: {},
451
+ content: participants
452
+ });
453
+ }
434
454
  }
435
455
  const stanza = {
436
456
  tag: 'message',
@@ -468,128 +488,121 @@ const makeMessagesSocket = (config) => {
468
488
  });
469
489
  logger.debug({ jid }, 'adding device identity');
470
490
  }
471
-
472
- const messages = Utils_1.normalizeMessageContent(message)
473
- const buttonType = getButtonType(messages);
474
- if(!isNewsletter && buttonType) {
475
- const content = WABinary_1.getAdditionalNode(buttonType)
476
- const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
477
-
478
- if (filteredNode) {
479
- didPushAdditional = true
480
- stanza.content.push(...additionalNodes)
481
- }
482
- else {
483
- stanza.content.push(...content)
484
- }
485
- logger.debug({ jid }, 'adding business node')
486
- }
487
-
488
491
  if (additionalNodes && additionalNodes.length > 0) {
489
492
  stanza.content.push(...additionalNodes);
490
493
  }
491
-
492
- if (AI && isPrivate) {
493
- const botNode = {
494
- tag: 'bot',
495
- attrs: {
496
- biz_bot: '1'
497
- }
498
- }
499
-
500
- const filteredBizBot = WABinary_1.getBinaryFilteredBizBot(additionalNodes ? additionalNodes : [])
501
-
502
- if (filteredBizBot) {
503
- stanza.content.push(...additionalNodes)
504
- didPushAdditional = true
494
+ const content = (0, Utils_1.normalizeMessageContent)(message);
495
+ const contentType = (0, Utils_1.getContentType)(content);
496
+ if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && (contentType === 'interactiveMessage' ||
497
+ contentType === 'buttonsMessage' ||
498
+ contentType === 'listMessage')) {
499
+ const bizNode = { tag: 'biz', attrs: {} };
500
+ 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))) {
501
+ bizNode.content = [{
502
+ tag: 'interactive',
503
+ attrs: {
504
+ type: 'native_flow',
505
+ v: '1'
506
+ },
507
+ content: [{
508
+ tag: 'native_flow',
509
+ attrs: { v: '9', name: 'mixed' }
510
+ }]
511
+ }];
505
512
  }
506
-
507
- else {
508
- stanza.content.push(botNode)
513
+ else if (message === null || message === void 0 ? void 0 : message.listMessage) {
514
+ // list message only support in private chat
515
+ bizNode.content = [{
516
+ tag: 'list',
517
+ attrs: {
518
+ type: 'product_list',
519
+ v: '2'
520
+ }
521
+ }];
509
522
  }
510
- }
523
+ stanza.content.push(bizNode);
524
+ }
511
525
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
512
526
  await sendNode(stanza);
513
527
  });
514
528
  return msgId;
515
529
  };
516
530
  const getTypeMessage = (msg) => {
517
- const message = Utils_1.normalizeMessageContent(msg)
518
- if (message.reactionMessage) {
519
- return 'reaction'
520
- }
521
- else if (getMediaType(message)) {
522
- return 'media'
523
- }
531
+ if (msg.viewOnceMessage) {
532
+ return getTypeMessage(msg.viewOnceMessage.message);
533
+ }
534
+ else if (msg.viewOnceMessageV2) {
535
+ return getTypeMessage(msg.viewOnceMessageV2.message);
536
+ }
537
+ else if (msg.viewOnceMessageV2Extension) {
538
+ return getTypeMessage(msg.viewOnceMessageV2Extension.message);
539
+ }
540
+ else if (msg.ephemeralMessage) {
541
+ return getTypeMessage(msg.ephemeralMessage.message);
542
+ }
543
+ else if (msg.documentWithCaptionMessage) {
544
+ return getTypeMessage(msg.documentWithCaptionMessage.message);
545
+ }
546
+ else if (msg.reactionMessage) {
547
+ return 'reaction';
548
+ }
549
+ else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
550
+ return 'poll';
551
+ }
552
+ else if (getMediaType(msg)) {
553
+ return 'media';
554
+ }
524
555
  else {
525
- return 'text'
556
+ return 'text';
526
557
  }
527
- }
528
-
558
+ };
529
559
  const getMediaType = (message) => {
530
560
  if (message.imageMessage) {
531
- return 'image'
561
+ return 'image';
532
562
  }
533
563
  else if (message.videoMessage) {
534
- return message.videoMessage.gifPlayback ? 'gif' : 'video'
564
+ return message.videoMessage.gifPlayback ? 'gif' : 'video';
535
565
  }
536
566
  else if (message.audioMessage) {
537
- return message.audioMessage.ptt ? 'ptt' : 'audio'
567
+ return message.audioMessage.ptt ? 'ptt' : 'audio';
538
568
  }
539
569
  else if (message.contactMessage) {
540
- return 'vcard'
570
+ return 'vcard';
541
571
  }
542
572
  else if (message.documentMessage) {
543
- return 'document'
573
+ return 'document';
544
574
  }
545
575
  else if (message.contactsArrayMessage) {
546
- return 'contact_array'
576
+ return 'contact_array';
547
577
  }
548
578
  else if (message.liveLocationMessage) {
549
- return 'livelocation'
579
+ return 'livelocation';
550
580
  }
551
581
  else if (message.stickerMessage) {
552
- return 'sticker'
582
+ return 'sticker';
553
583
  }
554
584
  else if (message.listMessage) {
555
- return 'list'
585
+ return 'list';
556
586
  }
557
587
  else if (message.listResponseMessage) {
558
- return 'list_response'
588
+ return 'list_response';
559
589
  }
560
590
  else if (message.buttonsResponseMessage) {
561
- return 'buttons_response'
591
+ return 'buttons_response';
562
592
  }
563
593
  else if (message.orderMessage) {
564
- return 'order'
594
+ return 'order';
565
595
  }
566
596
  else if (message.productMessage) {
567
- return 'product'
597
+ return 'product';
568
598
  }
569
599
  else if (message.interactiveResponseMessage) {
570
- return 'native_flow_response'
600
+ return 'native_flow_response';
571
601
  }
572
602
  else if (message.groupInviteMessage) {
573
- return 'url'
574
- }
575
- else if (/https:\/\/wa\.me\/p\/\d+\/\d+/.test(message.extendedTextMessage?.text)) {
576
- return 'productlink'
603
+ return 'url';
577
604
  }
578
- }
579
- const getButtonType = (message) => {
580
- if (message.listMessage) {
581
- return 'list'
582
- }
583
- else if (message.buttonsMessage) {
584
- return 'buttons'
585
- }
586
- else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
587
- return 'interactive'
588
- }
589
- else if (message.interactiveMessage?.nativeFlowMessage) {
590
- return 'native_flow'
591
- }
592
- }
605
+ };
593
606
  const getPrivacyTokens = async (jids) => {
594
607
  const t = (0, Utils_1.unixTimestampSeconds)().toString();
595
608
  const result = await query({
@@ -615,32 +628,8 @@ const makeMessagesSocket = (config) => {
615
628
  ]
616
629
  });
617
630
  return result;
618
- }
619
-
620
- const sendPeerDataOperationMessage = async (pdoMessage) => {
621
- var _a;
622
- //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
623
- if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
624
- throw new boom_1.Boom('Not authenticated');
625
- }
626
- const protocolMessage = {
627
- protocolMessage: {
628
- peerDataOperationRequestMessage: pdoMessage,
629
- type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
630
- }
631
- };
632
- const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
633
- const msgId = await relayMessage(meJid, protocolMessage, {
634
- additionalAttributes: {
635
- category: 'peer',
636
- // eslint-disable-next-line camelcase
637
- push_priority: 'high_force',
638
- },
639
- });
640
- return msgId;
641
631
  };
642
632
  const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
643
- const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
644
633
  const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
645
634
  return {
646
635
  ...sock,
@@ -649,23 +638,22 @@ const makeMessagesSocket = (config) => {
649
638
  relayMessage,
650
639
  sendReceipt,
651
640
  sendReceipts,
652
- rahmi,
653
641
  readMessages,
654
642
  refreshMediaConn,
643
+ waUploadToServer,
644
+ fetchPrivacySettings,
655
645
  getUSyncDevices,
656
646
  createParticipantNodes,
657
- waUploadToServer,
658
647
  sendPeerDataOperationMessage,
659
- fetchPrivacySettings,
660
648
  updateMediaMessage: async (message) => {
661
649
  const content = (0, Utils_1.assertMediaContent)(message.message);
662
650
  const mediaKey = content.mediaKey;
663
651
  const meId = authState.creds.me.id;
664
- const node = (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
652
+ const node = await (0, Utils_1.encryptMediaRetryRequest)(message.key, mediaKey, meId);
665
653
  let error = undefined;
666
654
  await Promise.all([
667
655
  sendNode(node),
668
- waitForMsgMediaUpdate(update => {
656
+ waitForMsgMediaUpdate(async (update) => {
669
657
  const result = update.find(c => c.key.id === message.key.id);
670
658
  if (result) {
671
659
  if (result.error) {
@@ -673,7 +661,7 @@ const makeMessagesSocket = (config) => {
673
661
  }
674
662
  else {
675
663
  try {
676
- const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
664
+ const media = await (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
677
665
  if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
678
666
  const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
679
667
  throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
@@ -699,107 +687,186 @@ const makeMessagesSocket = (config) => {
699
687
  return message;
700
688
  },
701
689
  sendMessage: async (jid, content, options = {}) => {
690
+ var _a, _b, _c;
702
691
  const userJid = authState.creds.me.id;
703
- const { filter = false, quoted } = options;
704
- const getParticipantAttr = () => filter ? { participant: { jid } } : {};
705
- const messageType = rahmi.detectType(content);
706
-
707
- if (messageType) {
708
- switch(messageType) {
709
- case 'PAYMENT':
710
- const paymentContent = await rahmi.handlePayment(content, quoted);
711
- return await relayMessage(jid, paymentContent, {
712
- messageId: Utils_1.generateMessageID(),
713
- ...getParticipantAttr()
714
- });
715
-
716
- case 'PRODUCT':
717
- const productContent = await rahmi.handleProduct(content, jid, quoted);
718
- const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
719
- return await relayMessage(jid, productMsg.message, {
720
- messageId: productMsg.key.id,
721
- ...getParticipantAttr()
692
+ if (!options.ephemeralExpiration) {
693
+ if ((0, WABinary_1.isJidGroup)(jid)) {
694
+ const groups = await sock.groupQuery(jid, 'get', [{
695
+ tag: 'query',
696
+ attrs: {
697
+ request: 'interactive'
698
+ }
699
+ }]);
700
+ const metadata = (0, WABinary_1.getBinaryNodeChild)(groups, 'group');
701
+ 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;
702
+ options.ephemeralExpiration = expiration;
703
+ }
704
+ }
705
+ if (typeof content === 'object' &&
706
+ 'disappearingMessagesInChat' in content &&
707
+ typeof content['disappearingMessagesInChat'] !== 'undefined' &&
708
+ (0, WABinary_1.isJidGroup)(jid)) {
709
+ const { disappearingMessagesInChat } = content;
710
+ const value = typeof disappearingMessagesInChat === 'boolean' ?
711
+ (disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
712
+ disappearingMessagesInChat;
713
+ await groupToggleEphemeral(jid, value);
714
+ }
715
+ if (typeof content === 'object' && 'album' in content && content.album) {
716
+ const { album, caption } = content;
717
+ if (caption && !album[0].caption) {
718
+ album[0].caption = caption;
719
+ }
720
+ let mediaHandle;
721
+ let mediaMsg;
722
+ const albumMsg = (0, Utils_1.generateWAMessageFromContent)(jid, {
723
+ albumMessage: {
724
+ expectedImageCount: album.filter(item => 'image' in item).length,
725
+ expectedVideoCount: album.filter(item => 'video' in item).length
726
+ }
727
+ }, { userJid, ...options });
728
+ await relayMessage(jid, albumMsg.message, {
729
+ messageId: albumMsg.key.id
730
+ });
731
+ for (const i in album) {
732
+ const media = album[i];
733
+ if ('image' in media) {
734
+ mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
735
+ image: media.image,
736
+ ...(media.caption ? { caption: media.caption } : {}),
737
+ ...options
738
+ }, {
739
+ userJid,
740
+ upload: async (readStream, opts) => {
741
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
742
+ mediaHandle = up.handle;
743
+ return up;
744
+ },
745
+ ...options,
722
746
  });
723
-
724
- case 'INTERACTIVE':
725
- const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
726
- const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
727
- return await relayMessage(jid, interactiveMsg.message, {
728
- messageId: interactiveMsg.key.id,
729
- ...getParticipantAttr()
747
+ }
748
+ else if ('video' in media) {
749
+ mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
750
+ video: media.video,
751
+ ...(media.caption ? { caption: media.caption } : {}),
752
+ ...(media.gifPlayback !== undefined ? { gifPlayback: media.gifPlayback } : {}),
753
+ ...options
754
+ }, {
755
+ userJid,
756
+ upload: async (readStream, opts) => {
757
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
758
+ mediaHandle = up.handle;
759
+ return up;
760
+ },
761
+ ...options,
730
762
  });
731
- case 'ALBUM':
732
- const albumContent = await rahmi.handleAlbum(content, jid, quoted)
733
- return albumContent;
734
-
735
- case 'EVENT':
736
- return await rahmi.handleEvent(content, jid, quoted)
737
-
738
- case 'POLL_RESULT':
739
- return await rahmi.handlePollResult(content, jid, quoted)
763
+ }
764
+ if (mediaMsg) {
765
+ mediaMsg.message.messageContextInfo = {
766
+ messageSecret: (0, crypto_1.randomBytes)(32),
767
+ messageAssociation: {
768
+ associationType: 1,
769
+ parentMessageKey: albumMsg.key
770
+ }
771
+ };
772
+ }
773
+ await relayMessage(jid, mediaMsg.message, {
774
+ messageId: mediaMsg.key.id
775
+ });
776
+ await new Promise(resolve => setTimeout(resolve, 800));
740
777
  }
778
+ return albumMsg;
741
779
  }
742
- const fullMsg = await Utils_1.generateWAMessage(jid, content, {
743
- logger,
744
- userJid,
745
- quoted,
746
- getUrlInfo: text => link_preview_1.getUrlInfo(text, {
747
- thumbnailWidth: linkPreviewImageThumbnailWidth,
748
- fetchOpts: {
749
- timeout: 3000,
750
- ...axiosOptions || {}
751
- },
780
+ else {
781
+ let mediaHandle;
782
+ const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
752
783
  logger,
753
- uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
754
- }),
755
- upload: async (readStream, opts) => {
756
- const up = await waUploadToServer(readStream, {
757
- ...opts,
758
- newsletter: WABinary_1.isJidNewsLetter(jid)
759
- });
760
- return up;
761
- },
762
- mediaCache: config.mediaCache,
763
- options: config.options,
764
- ...options
765
- });
766
-
767
- const isDeleteMsg = 'delete' in content && !!content.delete;
768
- const isEditMsg = 'edit' in content && !!content.edit;
769
- const isAiMsg = 'ai' in content && !!content.ai;
770
-
771
- const additionalAttributes = {};
772
- const additionalNodes = [];
773
-
774
- if (isDeleteMsg) {
775
- const fromMe = content.delete?.fromMe;
776
- const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
777
- additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
778
- } else if (isEditMsg) {
779
- additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
780
- } else if (isAiMsg) {
781
- additionalNodes.push({
782
- attrs: {
783
- biz_bot: '1'
784
- }, tag: "bot"
785
- });
786
- }
787
-
788
- await relayMessage(jid, fullMsg.message, {
789
- messageId: fullMsg.key.id,
790
- cachedGroupMetadata: options.cachedGroupMetadata,
791
- additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
792
- additionalAttributes,
793
- statusJidList: options.statusJidList
794
- });
795
-
796
- if (config.emitOwnEvents) {
797
- process.nextTick(() => {
798
- processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
784
+ userJid,
785
+ getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
786
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
787
+ fetchOpts: {
788
+ timeout: 3000,
789
+ ...axiosOptions || {}
790
+ },
791
+ logger,
792
+ uploadImage: generateHighQualityLinkPreview
793
+ ? waUploadToServer
794
+ : undefined
795
+ }),
796
+ getProfilePicUrl: sock.profilePictureUrl,
797
+ upload: async (readStream, opts) => {
798
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
799
+ mediaHandle = up.handle;
800
+ return up;
801
+ },
802
+ mediaCache: config.mediaCache,
803
+ options: config.options,
804
+ messageId: (0, Utils_1.generateMessageIDV2)((_c = sock.user) === null || _c === void 0 ? void 0 : _c.id),
805
+ ...options,
799
806
  });
807
+ const isDeleteMsg = 'delete' in content && !!content.delete;
808
+ const isEditMsg = 'edit' in content && !!content.edit;
809
+ const isPinMsg = 'pin' in content && !!content.pin;
810
+ const isKeepMsg = 'keep' in content && content.keep;
811
+ const isPollMessage = 'poll' in content && !!content.poll;
812
+ const isAiMsg = 'ai' in content && !!content.ai;
813
+ const additionalAttributes = {};
814
+ const additionalNodes = [];
815
+ // required for delete
816
+ if (isDeleteMsg) {
817
+ // if the chat is a group, and I am not the author, then delete the message as an admin
818
+ if (((0, WABinary_1.isJidGroup)(content.delete.remoteJid) && !content.delete.fromMe) || (0, WABinary_1.isJidNewsletter)(jid)) {
819
+ additionalAttributes.edit = '8';
820
+ }
821
+ else {
822
+ additionalAttributes.edit = '7';
823
+ }
824
+ // required for edit message
825
+ }
826
+ else if (isEditMsg) {
827
+ additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
828
+ // required for pin message
829
+ }
830
+ else if (isPinMsg) {
831
+ additionalAttributes.edit = '2';
832
+ // required for keep message
833
+ }
834
+ else if (isKeepMsg) {
835
+ additionalAttributes.edit = '6';
836
+ // required for polling message
837
+ }
838
+ else if (isPollMessage) {
839
+ additionalNodes.push({
840
+ tag: 'meta',
841
+ attrs: {
842
+ polltype: 'creation'
843
+ },
844
+ });
845
+ // required to display AI icon on message
846
+ }
847
+ else if (isAiMsg) {
848
+ additionalNodes.push({
849
+ attrs: {
850
+ biz_bot: '1'
851
+ },
852
+ tag: "bot"
853
+ });
854
+ }
855
+ if (mediaHandle) {
856
+ additionalAttributes['media_id'] = mediaHandle;
857
+ }
858
+ if ('cachedGroupMetadata' in options) {
859
+ console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
860
+ }
861
+ await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
862
+ if (config.emitOwnEvents) {
863
+ process.nextTick(() => {
864
+ processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
865
+ });
866
+ }
867
+ return fullMsg;
800
868
  }
801
- return fullMsg;
802
869
  }
803
- }
870
+ };
804
871
  };
805
872
  exports.makeMessagesSocket = makeMessagesSocket;