@zetagoaurum-socket/decagramton 3.2.5 → 3.2.7

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 (92) hide show
  1. package/README.md +91 -91
  2. package/WAProto/index.js +56886 -17506
  3. package/engine-requirements.js +91 -0
  4. package/lib/Defaults/index.js +47 -2
  5. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  6. package/lib/Signal/Group/ciphertext-message.js +15 -0
  7. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  8. package/lib/Signal/Group/group-session-builder.js +64 -0
  9. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  10. package/lib/Signal/Group/group_cipher.js +96 -0
  11. package/lib/Signal/Group/index.d.ts +11 -0
  12. package/lib/Signal/Group/index.js +57 -0
  13. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  14. package/lib/Signal/Group/keyhelper.js +55 -0
  15. package/lib/Signal/Group/queue-job.d.ts +1 -0
  16. package/lib/Signal/Group/queue-job.js +57 -0
  17. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  18. package/lib/Signal/Group/sender-chain-key.js +34 -0
  19. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  20. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  21. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  22. package/lib/Signal/Group/sender-key-message.js +69 -0
  23. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  24. package/lib/Signal/Group/sender-key-name.js +51 -0
  25. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  26. package/lib/Signal/Group/sender-key-record.js +53 -0
  27. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  28. package/lib/Signal/Group/sender-key-state.js +99 -0
  29. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  30. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
  31. package/lib/Signal/libsignal.js +51 -29
  32. package/lib/Socket/business.d.ts +3 -2
  33. package/lib/Socket/chats.d.ts +215 -28
  34. package/lib/Socket/chats.js +166 -70
  35. package/lib/Socket/dugong.d.ts +254 -0
  36. package/lib/Socket/dugong.js +432 -141
  37. package/lib/Socket/groups.js +20 -23
  38. package/lib/Socket/index.js +2 -15
  39. package/lib/Socket/messages-recv.d.ts +56 -55
  40. package/lib/Socket/messages-recv.js +367 -131
  41. package/lib/Socket/messages-send.d.ts +3 -2
  42. package/lib/Socket/messages-send.js +423 -380
  43. package/lib/Socket/newsletter.js +147 -21
  44. package/lib/Socket/socket.js +156 -148
  45. package/lib/Socket/usync.d.ts +3 -3
  46. package/lib/Types/GroupMetadata.d.ts +1 -0
  47. package/lib/Types/Newsletter.d.ts +97 -86
  48. package/lib/Types/Newsletter.js +38 -32
  49. package/lib/Types/USync.d.ts +25 -0
  50. package/lib/Types/USync.js +2 -0
  51. package/lib/Utils/anti-crash.js +31 -0
  52. package/lib/Utils/chat-utils.js +6 -1
  53. package/lib/Utils/generics.js +66 -34
  54. package/lib/Utils/history.js +6 -1
  55. package/lib/Utils/index.js +0 -1
  56. package/lib/Utils/link-preview.js +1 -1
  57. package/lib/Utils/messages-media.js +145 -57
  58. package/lib/Utils/messages.js +92 -306
  59. package/lib/Utils/signal.js +48 -46
  60. package/lib/Utils/use-multi-file-auth-state.js +45 -6
  61. package/lib/Utils/validate-connection.js +89 -65
  62. package/lib/WABinary/constants.d.ts +27 -24
  63. package/lib/WABinary/encode.js +160 -123
  64. package/lib/WABinary/generic-utils.d.ts +2 -0
  65. package/lib/WABinary/generic-utils.js +124 -36
  66. package/lib/WABinary/jid-utils.js +5 -26
  67. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
  68. package/lib/index.d.ts +1 -0
  69. package/lib/index.js +56 -0
  70. package/package.json +107 -101
  71. package/LICENSE +0 -21
  72. package/WAProto/GenerateStatics.sh +0 -4
  73. package/WAProto/WAProto.proto +0 -3344
  74. package/WAProto/index.d.ts +0 -37016
  75. package/WASignalGroup/GroupProtocol.js +0 -1697
  76. package/WASignalGroup/ciphertext_message.js +0 -16
  77. package/WASignalGroup/group_cipher.js +0 -120
  78. package/WASignalGroup/group_session_builder.js +0 -46
  79. package/WASignalGroup/index.js +0 -5
  80. package/WASignalGroup/keyhelper.js +0 -21
  81. package/WASignalGroup/protobufs.js +0 -3
  82. package/WASignalGroup/queue_job.js +0 -69
  83. package/WASignalGroup/sender_chain_key.js +0 -50
  84. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  85. package/WASignalGroup/sender_key_message.js +0 -92
  86. package/WASignalGroup/sender_key_name.js +0 -70
  87. package/WASignalGroup/sender_key_record.js +0 -56
  88. package/WASignalGroup/sender_key_state.js +0 -129
  89. package/decagramton.jpg +0 -0
  90. package/lib/Utils/rate-limiter.js +0 -55
  91. package/lib/WAUSync/Fall +0 -1
  92. package/lib/WAUSync/Protocols/Fal +0 -1
@@ -1,22 +1,45 @@
1
- "use strict";
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
8
  const node_cache_1 = __importDefault(require("node-cache"));
9
9
  const WAProto_1 = require("../../WAProto");
10
10
  const Defaults_1 = require("../Defaults");
11
+ const axios_1 = require("axios")
12
+ const Types_1 = require("../Types")
11
13
  const Utils_1 = require("../Utils");
12
14
  const link_preview_1 = require("../Utils/link-preview");
13
15
  const WABinary_1 = require("../WABinary");
14
16
  const newsletter_1 = require("./newsletter");
17
+ const WAUSync_1 = require("../WAUSync")
18
+ const kikyy = require('./dugong');
15
19
  var ListType = WAProto_1.proto.Message.ListMessage.ListType;
16
20
  const makeMessagesSocket = (config) => {
17
- const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, } = config;
21
+ const {
22
+ logger,
23
+ linkPreviewImageThumbnailWidth,
24
+ generateHighQualityLinkPreview,
25
+ options: axiosOptions,
26
+ patchMessageBeforeSending
27
+ } = config;
18
28
  const sock = (0, newsletter_1.makeNewsletterSocket)(config);
19
- const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupToggleEphemeral } = sock;
29
+ const {
30
+ ev,
31
+ authState,
32
+ processingMutex,
33
+ signalRepository,
34
+ upsertMessage,
35
+ query,
36
+ fetchPrivacySettings,
37
+ generateMessageTag,
38
+ sendNode,
39
+ groupMetadata,
40
+ groupToggleEphemeral,
41
+ executeUSyncQuery
42
+ } = sock;
20
43
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
21
44
  stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
22
45
  useClones: false
@@ -35,9 +58,9 @@ const makeMessagesSocket = (config) => {
35
58
  },
36
59
  content: [{ tag: 'media_conn', attrs: {} }]
37
60
  });
38
- const mediaConnNode = (0, WABinary_1.getBinaryNodeChild)(result, 'media_conn');
61
+ const mediaConnNode = WABinary_1.getBinaryNodeChild(result, 'media_conn');
39
62
  const node = {
40
- hosts: (0, WABinary_1.getBinaryNodeChildren)(mediaConnNode, 'host').map(({ attrs }) => ({
63
+ hosts: WABinary_1.getBinaryNodeChildren(mediaConnNode, 'host').map(({ attrs }) => ({
41
64
  hostname: attrs.hostname,
42
65
  maxContentLengthBytes: +attrs.maxContentLengthBytes,
43
66
  })),
@@ -66,7 +89,7 @@ const makeMessagesSocket = (config) => {
66
89
  if (isReadReceipt) {
67
90
  node.attrs.t = (0, Utils_1.unixTimestampSeconds)().toString();
68
91
  }
69
- if (type === 'sender' && (0, WABinary_1.isJidUser)(jid)) {
92
+ if (type === 'sender' && WABinary_1.isJidUser(jid)) {
70
93
  node.attrs.recipient = jid;
71
94
  node.attrs.to = participant;
72
95
  }
@@ -77,7 +100,7 @@ const makeMessagesSocket = (config) => {
77
100
  }
78
101
  }
79
102
  if (type) {
80
- node.attrs.type = (0, WABinary_1.isJidNewsLetter)(jid) ? 'read-self' : type;
103
+ node.attrs.type = WABinary_1.isJidNewsLetter(jid) ? 'read-self' : type;
81
104
  }
82
105
  const remainingMessageIds = messageIds.slice(1);
83
106
  if (remainingMessageIds.length) {
@@ -111,74 +134,70 @@ const makeMessagesSocket = (config) => {
111
134
  };
112
135
  /** Fetch all the devices we've to send a message to */
113
136
  const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
114
- var _a;
115
- const deviceResults = [];
137
+ const deviceResults = []
138
+
116
139
  if (!useCache) {
117
- logger.debug('not using cache for devices');
140
+ logger.debug('not using cache for devices')
118
141
  }
119
- const users = [];
120
- jids = Array.from(new Set(jids));
142
+
143
+ const toFetch = []
144
+
145
+ jids = Array.from(new Set(jids))
146
+
121
147
  for (let jid of jids) {
122
- const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
123
- jid = (0, WABinary_1.jidNormalizedUser)(jid);
124
- const devices = userDevicesCache.get(user);
125
- if (devices && useCache) {
126
- deviceResults.push(...devices);
127
- logger.trace({ user }, 'using cache for devices');
148
+ const user = WABinary_1.jidDecode(jid)?.user
149
+
150
+ jid = WABinary_1.jidNormalizedUser(jid)
151
+
152
+ if (useCache) {
153
+ const devices = userDevicesCache.get(user)
154
+
155
+ if (devices) {
156
+ deviceResults.push(...devices)
157
+ logger.trace({ user }, 'using cache for devices')
158
+ }
159
+
160
+ else {
161
+ toFetch.push(jid)
162
+ }
128
163
  }
164
+
129
165
  else {
130
- users.push({ tag: 'user', attrs: { jid } });
166
+ toFetch.push(jid)
131
167
  }
132
168
  }
133
- if (!users.length) {
134
- return deviceResults;
169
+
170
+ if (!toFetch.length) {
171
+ return deviceResults
135
172
  }
136
- const iq = {
137
- tag: 'iq',
138
- attrs: {
139
- to: WABinary_1.S_WHATSAPP_NET,
140
- type: 'get',
141
- xmlns: 'usync',
142
- },
143
- content: [
144
- {
145
- tag: 'usync',
146
- attrs: {
147
- sid: generateMessageTag(),
148
- mode: 'query',
149
- last: 'true',
150
- index: '0',
151
- context: 'message',
152
- },
153
- content: [
154
- {
155
- tag: 'query',
156
- attrs: {},
157
- content: [
158
- {
159
- tag: 'devices',
160
- attrs: { version: '2' }
161
- }
162
- ]
163
- },
164
- { tag: 'list', attrs: {}, content: users }
165
- ]
166
- },
167
- ],
168
- };
169
- const result = await query(iq);
170
- const extracted = (0, Utils_1.extractDeviceJids)(result, authState.creds.me.id, ignoreZeroDevices);
171
- const deviceMap = {};
172
- for (const item of extracted) {
173
- deviceMap[item.user] = deviceMap[item.user] || [];
174
- deviceMap[item.user].push(item);
175
- deviceResults.push(item);
176
- }
177
- for (const key in deviceMap) {
178
- userDevicesCache.set(key, deviceMap[key]);
179
- }
180
- return deviceResults;
181
- };
173
+
174
+ const query = new WAUSync_1.USyncQuery()
175
+ .withContext('message')
176
+ .withDeviceProtocol()
177
+
178
+ for (const jid of toFetch) {
179
+ query.withUser(new WAUSync_1.USyncUser().withId(jid))
180
+ }
181
+
182
+ const result = await executeUSyncQuery(query)
183
+
184
+ if (result) {
185
+ const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
186
+ const deviceMap = {}
187
+
188
+ for (const item of extracted) {
189
+ deviceMap[item.user] = deviceMap[item.user] || []
190
+ deviceMap[item.user].push(item)
191
+ deviceResults.push(item)
192
+ }
193
+
194
+ for (const key in deviceMap) {
195
+ userDevicesCache.set(key, deviceMap[key])
196
+ }
197
+ }
198
+
199
+ return deviceResults
200
+ }
182
201
  const assertSessions = async (jids, force) => {
183
202
  let didFetchNewSession = false;
184
203
  let jidsRequiringFetch = [];
@@ -222,6 +241,29 @@ const makeMessagesSocket = (config) => {
222
241
  }
223
242
  return didFetchNewSession;
224
243
  };
244
+
245
+
246
+ const sendPeerDataOperationMessage = async (pdoMessage) => {
247
+ if (!authState.creds.me?.id) {
248
+ throw new boom_1.Boom('Not authenticated')
249
+ }
250
+
251
+ const protocolMessage = {
252
+ protocolMessage: {
253
+ peerDataOperationRequestMessage: pdoMessage,
254
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
255
+ }
256
+ };
257
+ const meJid = WABinary_1.jidNormalizedUser(authState.creds.me.id);
258
+ const msgId = await relayMessage(meJid, protocolMessage, {
259
+ additionalAttributes: {
260
+ category: 'peer',
261
+ // eslint-disable-next-line camelcase
262
+ push_priority: 'high_force',
263
+ },
264
+ });
265
+ return msgId;
266
+ };
225
267
  const createParticipantNodes = async (jids, message, extraAttrs) => {
226
268
  const patched = await patchMessageBeforeSending(message, jids);
227
269
  const bytes = (0, Utils_1.encodeWAMessage)(patched);
@@ -249,27 +291,35 @@ const makeMessagesSocket = (config) => {
249
291
  }));
250
292
  return { nodes, shouldIncludeDeviceIdentity };
251
293
  }; //apela
252
- const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }) => {
294
+ const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = true }) => {
253
295
  const meId = authState.creds.me.id;
254
296
  let shouldIncludeDeviceIdentity = false;
255
- const { user, server } = (0, WABinary_1.jidDecode)(jid);
297
+ let didPushAdditional = false
298
+ const { user, server } = WABinary_1.jidDecode(jid);
256
299
  const statusJid = 'status@broadcast';
257
300
  const isGroup = server === 'g.us';
258
301
  const isStatus = jid === statusJid;
259
302
  const isLid = server === 'lid';
303
+ const isPrivate = server === 's.whatsapp.net'
260
304
  const isNewsletter = server === 'newsletter';
261
305
  msgId = msgId || (0, Utils_1.generateMessageID)();
262
306
  useUserDevicesCache = useUserDevicesCache !== false;
307
+ useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus
263
308
  const participants = [];
264
- const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
309
+ const destinationJid = (!isStatus) ? WABinary_1.jidEncode(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
265
310
  const binaryNodeContent = [];
266
311
  const devices = [];
267
312
  const meMsg = {
268
313
  deviceSentMessage: {
269
314
  destinationJid,
270
- message
315
+ message,
316
+ phash: '2:1:a', // Fake enterprise phash
317
+ metaVerified: true // Fake Meta Verified attribute
271
318
  }
272
319
  };
320
+ const extraAttrs = {}
321
+ const messages = Utils_1.normalizeMessageContent(message)
322
+ const buttonType = getButtonType(messages);
273
323
  if (participant) {
274
324
  // when the retry request is not for a group
275
325
  // only send to the specific device that asked for a retry
@@ -277,51 +327,80 @@ const makeMessagesSocket = (config) => {
277
327
  if (!isGroup && !isStatus) {
278
328
  additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
279
329
  }
280
- const { user, device } = (0, WABinary_1.jidDecode)(participant.jid);
330
+ const { user, device } = WABinary_1.jidDecode(participant.jid);
281
331
  devices.push({ user, device });
282
332
  }
283
333
  await authState.keys.transaction(async () => {
284
- var _a, _b, _c, _d, _e, _f;
285
- const mediaType = getMediaType(message);
334
+ const mediaType = getMediaType(messages);
335
+
336
+ if (mediaType) {
337
+ extraAttrs['mediatype'] = mediaType
338
+ }
339
+
340
+ if (messages.pinInChatMessage || messages.keepInChatMessage || message.reactionMessage || message.protocolMessage?.editedMessage) {
341
+ extraAttrs['decrypt-fail'] = 'hide'
342
+ }
343
+
344
+ if (messages.interactiveResponseMessage?.nativeFlowResponseMessage) {
345
+ extraAttrs['native_flow_name'] = messages.interactiveResponseMessage?.nativeFlowResponseMessage.name
346
+ }
347
+
286
348
  if (isGroup || isStatus) {
287
349
  const [groupData, senderKeyMap] = await Promise.all([
288
350
  (async () => {
289
- let groupData = cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined;
351
+ let groupData = useCachedGroupMetadata && cachedGroupMetadata ? await cachedGroupMetadata(jid) : undefined
290
352
  if (groupData) {
291
353
  logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
292
354
  }
293
- if (!groupData && !isStatus) {
294
- groupData = await groupMetadata(jid);
355
+
356
+ else if (!isStatus) {
357
+ groupData = await groupMetadata(jid)
295
358
  }
359
+
296
360
  return groupData;
297
361
  })(),
298
362
  (async () => {
299
363
  if (!participant && !isStatus) {
300
- const result = await authState.keys.get('sender-key-memory', [jid]);
301
- return result[jid] || {};
364
+ const result = await authState.keys.get('sender-key-memory', [jid])
365
+ return result[jid] || {}
302
366
  }
303
- return {};
304
- })()
367
+
368
+ return {}
369
+
370
+ })()
305
371
  ]);
306
372
  if (!participant) {
307
- const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : [];
373
+ const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
374
+
308
375
  if (isStatus && statusJidList) {
309
- participantsList.push(...statusJidList);
376
+ participantsList.push(...statusJidList)
310
377
  }
311
- const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
312
- devices.push(...additionalDevices);
378
+
379
+ // if (!isStatus) {
380
+ // const expiration = await getEphemeralGroup(jid)
381
+ // additionalAttributes = {
382
+ // ...additionalAttributes,
383
+ // addressing_mode: 'pn',
384
+ // ...expiration ? { expiration: expiration.toString() } : null
385
+ // }
386
+ // }
387
+
388
+ const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
389
+ devices.push(...additionalDevices)
313
390
  }
314
- const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
315
- const bytes = (0, Utils_1.encodeWAMessage)(patched);
391
+
392
+ const patched = await patchMessageBeforeSending(message, devices.map(d => WABinary_1.jidEncode(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
393
+ const bytes = Utils_1.encodeWAMessage(patched);
394
+
316
395
  const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
317
396
  group: destinationJid,
318
397
  data: bytes,
319
398
  meId,
320
399
  });
321
400
  const senderKeyJids = [];
322
- // ensure a connection is established with every device
401
+
323
402
  for (const { user, device } of devices) {
324
- const jid = (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : 's.whatsapp.net', device);
403
+ const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
325
404
  if (!senderKeyMap[jid] || !!participant) {
326
405
  senderKeyJids.push(jid);
327
406
  // store that this person has had the sender keys sent to them
@@ -339,95 +418,115 @@ const makeMessagesSocket = (config) => {
339
418
  }
340
419
  };
341
420
  await assertSessions(senderKeyJids, false);
342
- const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, mediaType ? { mediatype: mediaType } : undefined);
421
+ const result = await createParticipantNodes(senderKeyJids, senderKeyMsg, extraAttrs)
343
422
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
344
423
  participants.push(...result.nodes);
345
424
  }
346
425
  binaryNodeContent.push({
347
426
  tag: 'enc',
348
- attrs: { v: '2', type: 'skmsg' },
427
+ attrs: { v: '2', type: 'skmsg', ...extraAttrs },
349
428
  content: ciphertext
350
429
  });
351
430
  await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
352
431
  }
353
432
  else if (isNewsletter) {
354
433
  // Message edit
355
- if ((_a = message.protocolMessage) === null || _a === void 0 ? void 0 : _a.editedMessage) {
356
- msgId = (_b = message.protocolMessage.key) === null || _b === void 0 ? void 0 : _b.id;
357
- message = message.protocolMessage.editedMessage;
434
+ if (message.protocolMessage?.editedMessage) {
435
+ msgId = message.protocolMessage.key?.id
436
+ message = message.protocolMessage.editedMessage
358
437
  }
438
+
359
439
  // Message delete
360
- if (((_c = message.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
361
- msgId = (_d = message.protocolMessage.key) === null || _d === void 0 ? void 0 : _d.id;
362
- message = {};
440
+ if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
441
+ msgId = message.protocolMessage.key?.id
442
+ message = {}
363
443
  }
364
- const patched = await patchMessageBeforeSending(message, []);
365
- const bytes = WAProto_1.proto.Message.encode(patched).finish();
444
+
445
+ const patched = await patchMessageBeforeSending(message, [])
446
+ const bytes = Utils_1.encodeNewsletterMessage(patched)
447
+
366
448
  binaryNodeContent.push({
367
449
  tag: 'plaintext',
368
- attrs: mediaType ? { mediatype: mediaType } : {},
450
+ attrs: extraAttrs ? extraAttrs : {},
369
451
  content: bytes
370
- });
452
+ })
371
453
  }
372
454
  else {
373
- const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
455
+ const { user: meUser } = WABinary_1.jidDecode(meId);
374
456
  if (!participant) {
375
- devices.push({ user });
376
- // do not send message to self if the device is 0 (mobile)
377
- if (meDevice !== undefined && meDevice !== 0) {
378
- devices.push({ user: meUser });
457
+ devices.push({ user })
458
+ if (user !== meUser) {
459
+ devices.push({ user: meUser })
460
+ }
461
+
462
+ if (additionalAttributes?.['category'] !== 'peer') {
463
+ const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
464
+
465
+ devices.push(...additionalDevices)
379
466
  }
380
- const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
381
- devices.push(...additionalDevices);
382
467
  }
383
468
  const allJids = [];
384
469
  const meJids = [];
385
470
  const otherJids = [];
386
471
  for (const { user, device } of devices) {
387
- const isMe = user === meUser;
388
- 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);
472
+ const isMe = user === meUser
473
+ const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
474
+
389
475
  if (isMe) {
390
- meJids.push(jid);
476
+ meJids.push(jid)
391
477
  }
478
+
392
479
  else {
393
- otherJids.push(jid);
480
+ otherJids.push(jid)
394
481
  }
395
- allJids.push(jid);
482
+
483
+ allJids.push(jid)
396
484
  }
397
485
  await assertSessions(allJids, false);
398
486
  const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
399
- createParticipantNodes(meJids, meMsg, mediaType ? { mediatype: mediaType } : undefined),
400
- createParticipantNodes(otherJids, message, mediaType ? { mediatype: mediaType } : undefined)
401
- ]);
487
+ createParticipantNodes(meJids, meMsg, extraAttrs),
488
+ createParticipantNodes(otherJids, message, extraAttrs)
489
+ ])
402
490
  participants.push(...meNodes);
403
491
  participants.push(...otherNodes);
404
492
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
405
493
  }
406
494
  if (participants.length) {
407
- binaryNodeContent.push({
408
- tag: 'participants',
409
- attrs: {},
410
- content: participants
411
- });
495
+ if (additionalAttributes?.['category'] === 'peer') {
496
+ const peerNode = participants[0]?.content?.[0]
497
+
498
+ if (peerNode) {
499
+ binaryNodeContent.push(peerNode) // push only enc
500
+ }
501
+ }
502
+
503
+ else {
504
+ binaryNodeContent.push({
505
+ tag: 'participants',
506
+ attrs: {},
507
+ content: participants
508
+ })
509
+ }
412
510
  }
511
+
413
512
  const stanza = {
414
513
  tag: 'message',
415
514
  attrs: {
416
515
  id: msgId,
417
- type: isNewsletter ? getTypeMessage(message) : 'text',
516
+ type: getTypeMessage(messages),
418
517
  ...(additionalAttributes || {})
419
518
  },
420
519
  content: binaryNodeContent
421
- };
520
+ }
422
521
  // if the participant to send to is explicitly specified (generally retry recp)
423
522
  // ensure the message is only sent to that person
424
523
  // if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
425
524
  if (participant) {
426
- if ((0, WABinary_1.isJidGroup)(destinationJid)) {
525
+ if (WABinary_1.isJidGroup(destinationJid)) {
427
526
  stanza.attrs.to = destinationJid;
428
527
  stanza.attrs.participant = participant.jid;
429
528
  }
430
- else if ((0, WABinary_1.areJidsSameUser)(participant.jid, meId)) {
529
+ else if (WABinary_1.areJidsSameUser(participant.jid, meId)) {
431
530
  stanza.attrs.to = participant.jid;
432
531
  stanza.attrs.recipient = destinationJid;
433
532
  }
@@ -446,46 +545,66 @@ const makeMessagesSocket = (config) => {
446
545
  });
447
546
  logger.debug({ jid }, 'adding device identity');
448
547
  }
449
- if (additionalNodes && additionalNodes.length > 0) {
450
- stanza.content.push(...additionalNodes);
451
- }
452
- else {
453
- if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && ((message === null || message === void 0 ? void 0 : message.viewOnceMessage) ? message === null || message === void 0 ? void 0 : message.viewOnceMessage : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2 : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension : (message === null || message === void 0 ? void 0 : message.ephemeralMessage) ? message === null || message === void 0 ? void 0 : message.ephemeralMessage : (message === null || message === void 0 ? void 0 : message.templateMessage) ? message === null || message === void 0 ? void 0 : message.templateMessage : (message === null || message === void 0 ? void 0 : message.interactiveMessage) ? message === null || message === void 0 ? void 0 : message.interactiveMessage : message === null || message === void 0 ? void 0 : message.buttonsMessage)) {
454
- stanza.content.push({
455
- tag: 'biz',
456
- attrs: {},
457
- content: [{
458
- tag: 'interactive',
459
- attrs: {
460
- type: 'native_flow',
461
- v: '1'
462
- },
463
- content: [{
464
- tag: 'native_flow',
465
- attrs: { v: '9', name: 'mixed' }
466
- }]
467
- }]
468
- });
548
+
549
+ if (AI && isPrivate) {
550
+ const botNode = {
551
+ tag: 'bot',
552
+ attrs: {
553
+ biz_bot: '1'
554
+ }
555
+ }
556
+
557
+ const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
558
+
559
+ if (filteredBizBot) {
560
+ stanza.content.push(...additionalNodes)
561
+ didPushAdditional = true
562
+ }
563
+
564
+ else {
565
+ stanza.content.push(botNode)
469
566
  }
470
567
  }
471
- const buttonType = getButtonType(message);
472
- if (buttonType) {
473
- stanza.content.push({
474
- tag: 'biz',
475
- attrs: {},
476
- content: [
477
- {
478
- tag: buttonType,
479
- attrs: getButtonArgs(message),
480
- }
481
- ]
482
- });
483
- logger.debug({ jid }, 'adding business node');
568
+
569
+ if(!isNewsletter && buttonType && !isStatus) {
570
+ const content = WABinary_1.getAdditionalNode(buttonType)
571
+ const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
572
+
573
+ if (filteredNode) {
574
+ didPushAdditional = true
575
+ stanza.content.push(...additionalNodes)
576
+ }
577
+ else {
578
+ stanza.content.push(...content)
579
+ }
580
+ logger.debug({ jid }, 'adding business node')
581
+ }
582
+
583
+ if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
584
+ stanza.content.push(...additionalNodes);
484
585
  }
586
+
485
587
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
486
588
  await sendNode(stanza);
487
589
  });
488
- return msgId;
590
+
591
+ message = Types_1.WAProto.Message.fromObject(message)
592
+
593
+ const messageJSON = {
594
+ key: {
595
+ remoteJid: jid,
596
+ fromMe: true,
597
+ id: msgId
598
+ },
599
+ message: message,
600
+ messageTimestamp: Utils_1.unixTimestampSeconds(new Date()),
601
+ messageStubParameters: [],
602
+ participant: WABinary_1.isJidGroup(jid) || WABinary_1.isJidStatusBroadcast(jid) ? meId : undefined,
603
+ status: Types_1.WAMessageStatus.PENDING
604
+ }
605
+
606
+ return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
607
+ // return msgId;
489
608
  };
490
609
  const getTypeMessage = (msg) => {
491
610
  const message = Utils_1.normalizeMessageContent(msg)
@@ -550,93 +669,38 @@ const makeMessagesSocket = (config) => {
550
669
  return 'productlink'
551
670
  }
552
671
  }
672
+
553
673
  const getButtonType = (message) => {
554
- if (message.listMessage) {
555
- return 'list'
556
- }
674
+ if (message.listMessage) {
675
+ return 'list'
676
+ }
557
677
  else if (message.buttonsMessage) {
558
678
  return 'buttons'
559
679
  }
560
- else if(message.interactiveMessage?.nativeFlowMessage) {
561
- return 'native_flow'
680
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_and_pay') {
681
+ return 'review_and_pay'
562
682
  }
563
- }
564
- const getButtonArgs = (message) => {
565
- if (message.interactiveMessage?.nativeFlowMessage && message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 && message.interactiveMessage.nativeFlowMessage.buttons[0].name === 'review_and_pay') {
566
- return {
567
- tag: 'biz',
568
- attrs: {
569
- native_flow_name: 'order_details'
570
- }
571
- }
572
- } else if (message.interactiveMessage?.nativeFlowMessage && message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 && message.interactiveMessage.nativeFlowMessage.buttons[0].name === 'payment_info') {
573
- return {
574
- tag: 'biz',
575
- attrs: {
576
- native_flow_name: 'payment_info'
577
- }
578
- }
579
- } else if (message.interactiveMessage?.nativeFlowMessage &&message.interactiveMessage.nativeFlowMessage?.buttons?.length > 0 &&
580
- ['mpm', 'cta_catalog', 'send_location', 'call_permission_request', 'wa_payment_transaction_details', 'automated_greeting_message_view_catalog']
581
- .includes(message.interactiveMessage.nativeFlowMessage.buttons[0].name)) {
582
- return {
583
- tag: 'biz',
584
- attrs: {},
585
- content: [{
586
- tag: 'interactive',
587
- attrs: {
588
- type: 'native_flow',
589
- v: '1'
590
- },
591
- content: [{
592
- tag: 'native_flow',
593
- attrs: {
594
- v: '2',
595
- name: message.interactiveMessage.nativeFlowMessage.buttons[0].name
596
- }
597
- }]
598
- }]
599
- }
600
- } else if (message.interactiveMessage?.nativeFlowMessage || message.buttonsMessage) {
601
- return {
602
- tag: 'biz',
603
- attrs: {},
604
- content: [{
605
- tag: 'interactive',
606
- attrs: {
607
- type: 'native_flow',
608
- v: '1'
609
- },
610
- content: [{
611
- tag: 'native_flow',
612
- attrs: {
613
- v: '9',
614
- name: 'mixed'
615
- }
616
- }]
617
- }]
618
- }
619
- } else if (message.listMessage) {
620
- return {
621
- tag: 'biz',
622
- attrs: {},
623
- content: [{
624
- tag: 'list',
625
- attrs: {
626
- v: '2',
627
- type: 'product_list'
628
- }
629
- }]
630
- }
631
- } else {
632
- return {
633
- tag: 'biz',
634
- attrs: {}
635
- }
683
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'review_order') {
684
+ return 'review_order'
685
+ }
686
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_info') {
687
+ return 'payment_info'
688
+ }
689
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_status') {
690
+ return 'payment_status'
691
+ }
692
+ else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
693
+ return 'payment_method'
694
+ }
695
+ else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
696
+ return 'interactive'
697
+ }
698
+ else if (message.interactiveMessage?.nativeFlowMessage) {
699
+ return 'native_flow'
636
700
  }
637
701
  }
638
702
  const getPrivacyTokens = async (jids) => {
639
- const t = (0, Utils_1.unixTimestampSeconds)().toString();
703
+ const t = Utils_1.unixTimestampSeconds().toString();
640
704
  const result = await query({
641
705
  tag: 'iq',
642
706
  attrs: {
@@ -651,7 +715,7 @@ const makeMessagesSocket = (config) => {
651
715
  content: jids.map(jid => ({
652
716
  tag: 'token',
653
717
  attrs: {
654
- jid: (0, WABinary_1.jidNormalizedUser)(jid),
718
+ jid: WABinary_1.jidNormalizedUser(jid),
655
719
  t,
656
720
  type: 'trusted_contact'
657
721
  }
@@ -660,8 +724,9 @@ const makeMessagesSocket = (config) => {
660
724
  ]
661
725
  });
662
726
  return result;
663
- };
727
+ }
664
728
  const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
729
+ const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
665
730
  const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
666
731
  return {
667
732
  ...sock,
@@ -670,12 +735,13 @@ const makeMessagesSocket = (config) => {
670
735
  relayMessage,
671
736
  sendReceipt,
672
737
  sendReceipts,
673
- getButtonArgs,
738
+ rahmi,
674
739
  readMessages,
675
740
  refreshMediaConn,
676
741
  getUSyncDevices,
677
742
  createParticipantNodes,
678
743
  waUploadToServer,
744
+ sendPeerDataOperationMessage,
679
745
  fetchPrivacySettings,
680
746
  updateMediaMessage: async (message) => {
681
747
  const content = (0, Utils_1.assertMediaContent)(message.message);
@@ -714,155 +780,132 @@ const makeMessagesSocket = (config) => {
714
780
  throw error;
715
781
  }
716
782
  ev.emit('messages.update', [
717
- { key: message.key, update: { message: message.message } }
783
+ {
784
+ key: message.key,
785
+ update: {
786
+ message: message.message
787
+ }
788
+ }
718
789
  ]);
719
790
  return message;
720
791
  },
721
792
  sendMessage: async (jid, content, options = {}) => {
722
793
  const userJid = authState.creds.me.id;
723
- const additionalAttributes = {};
724
- const additionalNodes = [];
725
-
726
- // ZetaGo-Aurum Enterprise Rate Limiter
727
- const { kikyy } = require("./dugong");
728
- const rahmi = new kikyy(sock);
729
- const { RateLimiter } = require("../Utils");
730
- // Singleton rate limiter for the socket instance (naively re-created here, should be in closure)
731
- // Ideally should be passed in config, but for now we create per-call to throttle BURSTS slightly
732
- // Real rate limiting should be at socket level.
733
- // Let's attach it to 'sock' if not exists or use a global one.
734
- if (!sock.rateLimiter) {
735
- sock.rateLimiter = new RateLimiter({ maxTokens: 5, refillRate: 2 });
794
+ delete options.ephemeralExpiration
795
+ const { filter = false, quoted } = options;
796
+ const getParticipantAttr = () => filter ? { participant: { jid } } : {};
797
+ const messageType = rahmi.detectType(content);
798
+ if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
799
+ typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
800
+ const { disappearingMessagesInChat } = content
801
+
802
+ const value = typeof disappearingMessagesInChat === 'boolean' ?
803
+ (disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
804
+ disappearingMessagesInChat
805
+
806
+ await groupToggleEphemeral(jid, value)
736
807
  }
737
- await sock.rateLimiter.consume(1);
738
-
739
- const messageType = Object.keys(content)[0];
740
- if (messageType) {
741
- switch (messageType) {
742
- case 'PAYMENT':
743
- const paymentContent = await rahmi.handlePayment(content, options.quoted);
744
- return await relayMessage(jid, paymentContent, {
745
- messageId: (0, Utils_1.generateMessageID)(),
746
- participants: options.participants,
747
- additionalAttributes: { ...additionalAttributes, ...options.additionalAttributes },
748
- additionalNodes: options.additionalNodes,
749
- AI: true
750
- });
751
-
752
- case 'PRODUCT':
753
- const productContent = await rahmi.handleProduct(content, jid, options.quoted);
754
- const productMsg = await (0, Utils_1.generateWAMessageFromContent)(jid, productContent, { quoted: options.quoted });
755
- return await relayMessage(jid, productMsg.message, {
756
- messageId: productMsg.key.id,
757
- participants: options.participants,
758
- additionalAttributes: { ...additionalAttributes, ...options.additionalAttributes },
759
- additionalNodes: options.additionalNodes,
760
- AI: true
761
- });
762
-
763
- case 'INTERACTIVE':
764
- const interactiveContent = await rahmi.handleInteractive(content, jid, options.quoted);
765
- const interactiveMsg = await (0, Utils_1.generateWAMessageFromContent)(jid, interactiveContent, { quoted: options.quoted });
766
- return await relayMessage(jid, interactiveMsg.message, {
767
- messageId: interactiveMsg.key.id,
768
- participants: options.participants,
769
- additionalAttributes: { ...additionalAttributes, ...options.additionalAttributes },
770
- additionalNodes: options.additionalNodes,
771
- AI: true
772
- });
773
- case 'ALBUM':
774
- return await rahmi.handleAlbum(content, jid, options.quoted)
775
- case 'EVENT':
776
- return await rahmi.handleEvent(content, jid, options.quoted)
777
- case 'POLL_RESULT':
778
- return await rahmi.handlePollResult(content, jid, options.quoted)
779
- case 'GROUP_STORY':
780
- return await rahmi.handleGroupStory(content, jid, options.quoted)
781
- }
782
- }
808
+
809
+ else {
810
+ let mediaHandle
783
811
 
784
- const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
785
- logger,
786
- userJid,
787
- getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
788
- thumbnailWidth: linkPreviewImageThumbnailWidth,
789
- fetchOpts: {
790
- timeout: 3000,
791
- ...axiosOptions || {}
792
- },
793
- logger,
794
- uploadImage: generateHighQualityLinkPreview
795
- ? waUploadToServer
796
- : undefined
797
- }),
798
- upload: async (readStream, opts) => {
799
- const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsLetter)(jid) });
800
- mediaHandle = up.handle;
801
- return up;
802
- },
803
- mediaCache: config.mediaCache,
804
- options: config.options,
805
- ...options,
806
- });
807
- const isDeleteMsg = 'delete' in content && !!content.delete;
808
- const isEditMsg = 'edit' in content && !!content.edit;
809
- const isAiMsg = 'ai' in content && !!content.ai;
812
+
813
+ if (messageType) {
814
+ switch(messageType) {
815
+ case 'PAYMENT':
816
+ const paymentContent = await rahmi.handlePayment(content, quoted);
817
+ return await relayMessage(jid, paymentContent, {
818
+ messageId: Utils_1.generateMessageID(),
819
+ ...getParticipantAttr()
820
+ });
810
821
 
811
- // required for delete
812
- if (isDeleteMsg) {
813
- // if the chat is a group, and I am not the author, then delete the message as an admin
814
- if (((0, WABinary_1.isJidGroup)(content.delete?.remoteJid) && !content.delete?.fromMe) || (0, WABinary_1.isJidNewsLetter)(jid)) {
815
- additionalAttributes.edit = '8';
816
- }
817
- else {
818
- additionalAttributes.edit = '7';
819
- }
820
- }
821
- else if (isEditMsg) {
822
- additionalAttributes.edit = (0, WABinary_1.isJidNewsLetter)(jid) ? '3' : '1';
823
- }
824
-
825
- // AI Logic (Hybrid)
826
- if (isAiMsg || options.AI) {
827
- // For Private Chats: Use biz_bot (standard)
828
- if ((0, WABinary_1.isJidUser)(jid)) {
829
- additionalNodes.push({
830
- attrs: {
831
- biz_bot: '1'
832
- },
833
- tag: "bot"
822
+ case 'PRODUCT':
823
+ const productContent = await rahmi.handleProduct(content, jid, quoted);
824
+ const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
825
+ return await relayMessage(jid, productMsg.message, {
826
+ messageId: productMsg.key.id,
827
+ ...getParticipantAttr()
834
828
  });
835
- }
836
- // For Group Chats: Use supportPayload (safer, no drop)
837
- else if ((0, WABinary_1.isJidGroup)(jid)) {
838
- const msgType = Object.keys(fullMsg.message)[0];
839
- if (msgType) {
840
- fullMsg.message[msgType].messageContextInfo = fullMsg.message[msgType].messageContextInfo || {};
841
- fullMsg.message[msgType].messageContextInfo.messageSecret = fullMsg.message[msgType].messageContextInfo.messageSecret || crypto.randomBytes(32);
842
- fullMsg.message[msgType].messageContextInfo.supportPayload = JSON.stringify({
843
- version: 1,
844
- is_ai_message: true,
845
- should_show_system_message: true,
846
- ticket_id: crypto.randomBytes(16).toString('hex')
847
- });
848
- }
849
- }
850
- }
851
-
852
- if (mediaHandle) {
853
- additionalAttributes['media_id'] = mediaHandle;
854
- }
855
- if ('cachedGroupMetadata' in options) {
856
- console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
829
+
830
+ case 'INTERACTIVE':
831
+ const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
832
+ const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
833
+ return await relayMessage(jid, interactiveMsg.message, {
834
+ messageId: interactiveMsg.key.id,
835
+ ...getParticipantAttr()
836
+ });
837
+ case 'ALBUM':
838
+ return await rahmi.handleAlbum(content, jid, quoted)
839
+ case 'EVENT':
840
+ return await rahmi.handleEvent(content, jid, quoted)
841
+ case 'POLL_RESULT':
842
+ return await rahmi.handlePollResult(content, jid, quoted)
843
+ case 'GROUP_STORY':
844
+ return await rahmi.handleGroupStory(content, jid, quoted)
857
845
  }
858
- await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, cachedGroupMetadata: options.cachedGroupMetadata, additionalNodes, additionalAttributes, statusJidList: options.statusJidList });
859
- if (config.emitOwnEvents) {
860
- process.nextTick(() => {
861
- processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
846
+ }
847
+ const fullMsg = await Utils_1.generateWAMessage(jid, content, {
848
+ logger,
849
+ userJid,
850
+ quoted,
851
+ getUrlInfo: text => link_preview_1.getUrlInfo(text, {
852
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
853
+ fetchOpts: {
854
+ timeout: 3000,
855
+ ...axiosOptions || {}
856
+ },
857
+ logger,
858
+ uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
859
+ }),
860
+ upload: async (readStream, opts) => {
861
+ const up = await waUploadToServer(readStream, {
862
+ ...opts,
863
+ newsletter: WABinary_1.isJidNewsLetter(jid)
862
864
  });
863
- }
864
- return fullMsg;
865
+ return up;
866
+ },
867
+ mediaCache: config.mediaCache,
868
+ options: config.options,
869
+ ...options
870
+ });
871
+
872
+ const isDeleteMsg = 'delete' in content && !!content.delete;
873
+ const isEditMsg = 'edit' in content && !!content.edit;
874
+ const isAiMsg = 'ai' in content && !!content.ai;
875
+
876
+ const additionalAttributes = {};
877
+ const additionalNodes = [];
878
+
879
+ if (isDeleteMsg) {
880
+ const fromMe = content.delete?.fromMe;
881
+ const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
882
+ additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
883
+ } else if (isEditMsg) {
884
+ additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
885
+ } else if (isAiMsg) {
886
+ additionalNodes.push({
887
+ attrs: {
888
+ biz_bot: '1'
889
+ }, tag: "bot"
890
+ });
891
+ }
892
+
893
+ await relayMessage(jid, fullMsg.message, {
894
+ messageId: fullMsg.key.id,
895
+ cachedGroupMetadata: options.cachedGroupMetadata,
896
+ additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
897
+ additionalAttributes,
898
+ statusJidList: options.statusJidList
899
+ });
900
+
901
+ if (config.emitOwnEvents) {
902
+ process.nextTick(() => {
903
+ processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
904
+ });
905
+ }
906
+ return fullMsg;
865
907
  }
866
908
  }
867
- };
909
+ }
910
+ };
868
911
  exports.makeMessagesSocket = makeMessagesSocket;