@dyyxyzz/baileys-mod 6.0.40 → 6.0.42

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.
@@ -8,6 +8,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")
11
12
  const Types_1 = require("../Types")
12
13
  const Utils_1 = require("../Utils");
13
14
  const link_preview_1 = require("../Utils/link-preview");
@@ -15,9 +16,7 @@ const WABinary_1 = require("../WABinary");
15
16
  const newsletter_1 = require("./newsletter");
16
17
  const WAUSync_1 = require("../WAUSync")
17
18
  const kikyy = require('./dugong');
18
-
19
19
  var ListType = WAProto_1.proto.Message.ListMessage.ListType;
20
-
21
20
  const makeMessagesSocket = (config) => {
22
21
  const {
23
22
  logger,
@@ -26,7 +25,6 @@ const makeMessagesSocket = (config) => {
26
25
  options: axiosOptions,
27
26
  patchMessageBeforeSending
28
27
  } = config;
29
-
30
28
  const sock = (0, newsletter_1.makeNewsletterSocket)(config);
31
29
  const {
32
30
  ev,
@@ -42,14 +40,11 @@ const makeMessagesSocket = (config) => {
42
40
  groupToggleEphemeral,
43
41
  executeUSyncQuery
44
42
  } = sock;
45
-
46
43
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
47
44
  stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
48
45
  useClones: false
49
46
  });
50
-
51
47
  let mediaConn;
52
-
53
48
  const refreshMediaConn = async (forceGet = false) => {
54
49
  const media = await mediaConn;
55
50
  if (!media || forceGet || (new Date().getTime() - media.fetchDate.getTime()) > media.ttl * 1000) {
@@ -79,7 +74,10 @@ const makeMessagesSocket = (config) => {
79
74
  }
80
75
  return mediaConn;
81
76
  };
82
-
77
+ /**
78
+ * generic send receipt function
79
+ * used for receipts of phone call, read, delivery etc.
80
+ * */
83
81
  const sendReceipt = async (jid, participant, messageIds, type) => {
84
82
  const node = {
85
83
  tag: 'receipt',
@@ -120,69 +118,86 @@ const makeMessagesSocket = (config) => {
120
118
  logger.debug({ attrs: node.attrs, messageIds }, 'sending receipt for messages');
121
119
  await sendNode(node);
122
120
  };
123
-
121
+ /** Correctly bulk send receipts to multiple chats, participants */
124
122
  const sendReceipts = async (keys, type) => {
125
123
  const recps = (0, Utils_1.aggregateMessageKeysNotFromMe)(keys);
126
124
  for (const { jid, participant, messageIds } of recps) {
127
125
  await sendReceipt(jid, participant, messageIds, type);
128
126
  }
129
127
  };
130
-
128
+ /** Bulk read messages. Keys can be from different chats & participants */
131
129
  const readMessages = async (keys) => {
132
130
  const privacySettings = await fetchPrivacySettings();
131
+ // based on privacy settings, we have to change the read type
133
132
  const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
134
133
  await sendReceipts(keys, readType);
135
134
  };
136
-
135
+ /** Fetch all the devices we've to send a message to */
137
136
  const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
138
137
  const deviceResults = []
138
+
139
139
  if (!useCache) {
140
140
  logger.debug('not using cache for devices')
141
141
  }
142
+
142
143
  const toFetch = []
144
+
143
145
  jids = Array.from(new Set(jids))
146
+
144
147
  for (let jid of jids) {
145
148
  const user = WABinary_1.jidDecode(jid)?.user
149
+
146
150
  jid = WABinary_1.jidNormalizedUser(jid)
151
+
147
152
  if (useCache) {
148
153
  const devices = userDevicesCache.get(user)
154
+
149
155
  if (devices) {
150
156
  deviceResults.push(...devices)
151
157
  logger.trace({ user }, 'using cache for devices')
152
158
  }
159
+
153
160
  else {
154
161
  toFetch.push(jid)
155
162
  }
156
163
  }
164
+
157
165
  else {
158
166
  toFetch.push(jid)
159
167
  }
160
168
  }
169
+
161
170
  if (!toFetch.length) {
162
171
  return deviceResults
163
172
  }
173
+
164
174
  const query = new WAUSync_1.USyncQuery()
165
175
  .withContext('message')
166
176
  .withDeviceProtocol()
177
+
167
178
  for (const jid of toFetch) {
168
179
  query.withUser(new WAUSync_1.USyncUser().withId(jid))
169
180
  }
181
+
170
182
  const result = await executeUSyncQuery(query)
183
+
171
184
  if (result) {
172
185
  const extracted = Utils_1.extractDeviceJids(result?.list, authState.creds.me.id, ignoreZeroDevices)
173
186
  const deviceMap = {}
187
+
174
188
  for (const item of extracted) {
175
189
  deviceMap[item.user] = deviceMap[item.user] || []
176
190
  deviceMap[item.user].push(item)
177
191
  deviceResults.push(item)
178
192
  }
193
+
179
194
  for (const key in deviceMap) {
180
195
  userDevicesCache.set(key, deviceMap[key])
181
196
  }
182
197
  }
198
+
183
199
  return deviceResults
184
200
  }
185
-
186
201
  const assertSessions = async (jids, force) => {
187
202
  let didFetchNewSession = false;
188
203
  let jidsRequiringFetch = [];
@@ -190,10 +205,12 @@ const makeMessagesSocket = (config) => {
190
205
  jidsRequiringFetch = jids;
191
206
  }
192
207
  else {
193
- const addrs = jids.map(jid => (signalRepository.jidToSignalProtocolAddress(jid)));
208
+ const addrs = jids.map(jid => (signalRepository
209
+ .jidToSignalProtocolAddress(jid)));
194
210
  const sessions = await authState.keys.get('session', addrs);
195
211
  for (const jid of jids) {
196
- const signalId = signalRepository.jidToSignalProtocolAddress(jid);
212
+ const signalId = signalRepository
213
+ .jidToSignalProtocolAddress(jid);
197
214
  if (!sessions[signalId]) {
198
215
  jidsRequiringFetch.push(jid);
199
216
  }
@@ -224,11 +241,13 @@ const makeMessagesSocket = (config) => {
224
241
  }
225
242
  return didFetchNewSession;
226
243
  };
227
-
244
+
245
+
228
246
  const sendPeerDataOperationMessage = async (pdoMessage) => {
229
247
  if (!authState.creds.me?.id) {
230
248
  throw new boom_1.Boom('Not authenticated')
231
249
  }
250
+
232
251
  const protocolMessage = {
233
252
  protocolMessage: {
234
253
  peerDataOperationRequestMessage: pdoMessage,
@@ -239,18 +258,19 @@ const makeMessagesSocket = (config) => {
239
258
  const msgId = await relayMessage(meJid, protocolMessage, {
240
259
  additionalAttributes: {
241
260
  category: 'peer',
261
+ // eslint-disable-next-line camelcase
242
262
  push_priority: 'high_force',
243
263
  },
244
264
  });
245
265
  return msgId;
246
266
  };
247
-
248
267
  const createParticipantNodes = async (jids, message, extraAttrs) => {
249
268
  const patched = await patchMessageBeforeSending(message, jids);
250
269
  const bytes = (0, Utils_1.encodeWAMessage)(patched);
251
270
  let shouldIncludeDeviceIdentity = false;
252
271
  const nodes = await Promise.all(jids.map(async (jid) => {
253
- const { type, ciphertext } = await signalRepository.encryptMessage({ jid, data: bytes });
272
+ const { type, ciphertext } = await signalRepository
273
+ .encryptMessage({ jid, data: bytes });
254
274
  if (type === 'pkmsg') {
255
275
  shouldIncludeDeviceIdentity = true;
256
276
  }
@@ -258,20 +278,19 @@ const makeMessagesSocket = (config) => {
258
278
  tag: 'to',
259
279
  attrs: { jid },
260
280
  content: [{
261
- tag: 'enc',
262
- attrs: {
263
- v: '2',
264
- type,
265
- ...extraAttrs || {}
266
- },
267
- content: ciphertext
268
- }]
281
+ tag: 'enc',
282
+ attrs: {
283
+ v: '2',
284
+ type,
285
+ ...extraAttrs || {}
286
+ },
287
+ content: ciphertext
288
+ }]
269
289
  };
270
290
  return node;
271
291
  }));
272
292
  return { nodes, shouldIncludeDeviceIdentity };
273
- };
274
-
293
+ }; //apela
275
294
  const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, useCachedGroupMetadata, statusJidList, AI = false }) => {
276
295
  const meId = authState.creds.me.id;
277
296
  let shouldIncludeDeviceIdentity = false;
@@ -299,15 +318,16 @@ const makeMessagesSocket = (config) => {
299
318
  const extraAttrs = {}
300
319
  const messages = Utils_1.normalizeMessageContent(message)
301
320
  const buttonType = getButtonType(messages);
302
-
303
321
  if (participant) {
322
+ // when the retry request is not for a group
323
+ // only send to the specific device that asked for a retry
324
+ // otherwise the message is sent out to every device that should be a recipient
304
325
  if (!isGroup && !isStatus) {
305
326
  additionalAttributes = { ...additionalAttributes, 'device_fanout': 'false' };
306
327
  }
307
328
  const { user, device } = WABinary_1.jidDecode(participant.jid);
308
329
  devices.push({ user, device });
309
330
  }
310
-
311
331
  await authState.keys.transaction(async () => {
312
332
  const mediaType = getMediaType(messages);
313
333
 
@@ -330,9 +350,11 @@ const makeMessagesSocket = (config) => {
330
350
  if (groupData) {
331
351
  logger.trace({ jid, participants: groupData.participants.length }, 'using cached group metadata');
332
352
  }
353
+
333
354
  else if (!isStatus) {
334
355
  groupData = await groupMetadata(jid)
335
356
  }
357
+
336
358
  return groupData;
337
359
  })(),
338
360
  (async () => {
@@ -340,15 +362,27 @@ const makeMessagesSocket = (config) => {
340
362
  const result = await authState.keys.get('sender-key-memory', [jid])
341
363
  return result[jid] || {}
342
364
  }
365
+
343
366
  return {}
367
+
344
368
  })()
345
369
  ]);
346
-
347
370
  if (!participant) {
348
371
  const participantsList = (groupData && !isStatus) ? groupData.participants.map(p => p.id) : []
372
+
349
373
  if (isStatus && statusJidList) {
350
374
  participantsList.push(...statusJidList)
351
375
  }
376
+
377
+ // if (!isStatus) {
378
+ // const expiration = await getEphemeralGroup(jid)
379
+ // additionalAttributes = {
380
+ // ...additionalAttributes,
381
+ // addressing_mode: 'pn',
382
+ // ...expiration ? { expiration: expiration.toString() } : null
383
+ // }
384
+ // }
385
+
352
386
  const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false)
353
387
  devices.push(...additionalDevices)
354
388
  }
@@ -361,16 +395,18 @@ const makeMessagesSocket = (config) => {
361
395
  data: bytes,
362
396
  meId,
363
397
  });
364
-
365
398
  const senderKeyJids = [];
399
+
366
400
  for (const { user, device } of devices) {
367
401
  const jid = WABinary_1.jidEncode(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
368
402
  if (!senderKeyMap[jid] || !!participant) {
369
403
  senderKeyJids.push(jid);
404
+ // store that this person has had the sender keys sent to them
370
405
  senderKeyMap[jid] = true;
371
406
  }
372
407
  }
373
-
408
+ // if there are some participants with whom the session has not been established
409
+ // if there are, we re-send the senderkey
374
410
  if (senderKeyJids.length) {
375
411
  logger.debug({ senderKeyJids }, 'sending new sender key');
376
412
  const senderKeyMsg = {
@@ -384,7 +420,6 @@ const makeMessagesSocket = (config) => {
384
420
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || result.shouldIncludeDeviceIdentity;
385
421
  participants.push(...result.nodes);
386
422
  }
387
-
388
423
  binaryNodeContent.push({
389
424
  tag: 'enc',
390
425
  attrs: { v: '2', type: 'skmsg', ...extraAttrs },
@@ -393,16 +428,21 @@ const makeMessagesSocket = (config) => {
393
428
  await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
394
429
  }
395
430
  else if (isNewsletter) {
431
+ // Message edit
396
432
  if (message.protocolMessage?.editedMessage) {
397
433
  msgId = message.protocolMessage.key?.id
398
434
  message = message.protocolMessage.editedMessage
399
435
  }
436
+
437
+ // Message delete
400
438
  if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
401
439
  msgId = message.protocolMessage.key?.id
402
440
  message = {}
403
441
  }
442
+
404
443
  const patched = await patchMessageBeforeSending(message, [])
405
444
  const bytes = Utils_1.encodeNewsletterMessage(patched)
445
+
406
446
  binaryNodeContent.push({
407
447
  tag: 'plaintext',
408
448
  attrs: extraAttrs ? extraAttrs : {},
@@ -416,27 +456,30 @@ const makeMessagesSocket = (config) => {
416
456
  if (user !== meUser) {
417
457
  devices.push({ user: meUser })
418
458
  }
459
+
419
460
  if (additionalAttributes?.['category'] !== 'peer') {
420
461
  const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
462
+
421
463
  devices.push(...additionalDevices)
422
464
  }
423
465
  }
424
-
425
466
  const allJids = [];
426
467
  const meJids = [];
427
468
  const otherJids = [];
428
469
  for (const { user, device } of devices) {
429
470
  const isMe = user === meUser
430
471
  const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
472
+
431
473
  if (isMe) {
432
474
  meJids.push(jid)
433
475
  }
476
+
434
477
  else {
435
478
  otherJids.push(jid)
436
479
  }
480
+
437
481
  allJids.push(jid)
438
482
  }
439
-
440
483
  await assertSessions(allJids, false);
441
484
  const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
442
485
  createParticipantNodes(meJids, meMsg, extraAttrs),
@@ -446,14 +489,15 @@ const makeMessagesSocket = (config) => {
446
489
  participants.push(...otherNodes);
447
490
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
448
491
  }
449
-
450
492
  if (participants.length) {
451
493
  if (additionalAttributes?.['category'] === 'peer') {
452
494
  const peerNode = participants[0]?.content?.[0]
495
+
453
496
  if (peerNode) {
454
- binaryNodeContent.push(peerNode)
497
+ binaryNodeContent.push(peerNode) // push only enc
455
498
  }
456
499
  }
500
+
457
501
  else {
458
502
  binaryNodeContent.push({
459
503
  tag: 'participants',
@@ -472,7 +516,9 @@ const makeMessagesSocket = (config) => {
472
516
  },
473
517
  content: binaryNodeContent
474
518
  }
475
-
519
+ // if the participant to send to is explicitly specified (generally retry recp)
520
+ // ensure the message is only sent to that person
521
+ // if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
476
522
  if (participant) {
477
523
  if (WABinary_1.isJidGroup(destinationJid)) {
478
524
  stanza.attrs.to = destinationJid;
@@ -489,7 +535,6 @@ const makeMessagesSocket = (config) => {
489
535
  else {
490
536
  stanza.attrs.to = destinationJid;
491
537
  }
492
-
493
538
  if (shouldIncludeDeviceIdentity) {
494
539
  stanza.content.push({
495
540
  tag: 'device-identity',
@@ -506,37 +551,31 @@ const makeMessagesSocket = (config) => {
506
551
  biz_bot: '1'
507
552
  }
508
553
  }
554
+
509
555
  const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
556
+
510
557
  if (filteredBizBot) {
511
558
  stanza.content.push(...additionalNodes)
512
559
  didPushAdditional = true
513
560
  }
561
+
514
562
  else {
515
563
  stanza.content.push(botNode)
516
564
  }
517
565
  }
518
566
 
519
- // 🔥 FIX UTAMA: Support button params untuk SEMUA tipe (termasuk channel/newsletter)
520
- if (!isStatus) {
521
- // Deteksi apakah ada button params dalam message
522
- const hasButtonParams = buttonType ||
523
- messages.interactiveMessage?.nativeFlowMessage ||
524
- messages.buttonsMessage ||
525
- messages.listMessage;
526
-
527
- if (hasButtonParams) {
528
- const content = WABinary_1.getAdditionalNode(buttonType || 'interactive')
529
- const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
530
-
531
- if (filteredNode) {
532
- didPushAdditional = true
533
- stanza.content.push(...additionalNodes)
534
- }
535
- else if (content && content.length > 0) {
536
- stanza.content.push(...content)
537
- }
538
- logger.debug({ jid, buttonType, isNewsletter }, 'adding business node for buttons')
567
+ if(!isNewsletter && buttonType && !isStatus) {
568
+ const content = WABinary_1.getAdditionalNode(buttonType)
569
+ const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
570
+
571
+ if (filteredNode) {
572
+ didPushAdditional = true
573
+ stanza.content.push(...additionalNodes)
574
+ }
575
+ else {
576
+ stanza.content.push(...content)
539
577
  }
578
+ logger.debug({ jid }, 'adding business node')
540
579
  }
541
580
 
542
581
  if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
@@ -563,10 +602,10 @@ const makeMessagesSocket = (config) => {
563
602
  }
564
603
 
565
604
  return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
605
+ // return msgId;
566
606
  };
567
-
568
607
  const getTypeMessage = (msg) => {
569
- const message = Utils_1.normalizeMessageContent(msg)
608
+ const message = Utils_1.normalizeMessageContent(msg)
570
609
  if (message.reactionMessage) {
571
610
  return 'reaction'
572
611
  }
@@ -651,14 +690,13 @@ const makeMessagesSocket = (config) => {
651
690
  else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
652
691
  return 'payment_method'
653
692
  }
693
+ else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
694
+ return 'interactive'
695
+ }
654
696
  else if (message.interactiveMessage?.nativeFlowMessage) {
655
697
  return 'native_flow'
656
698
  }
657
- else if (message.interactiveMessage) {
658
- return 'interactive'
659
- }
660
699
  }
661
-
662
700
  const getPrivacyTokens = async (jids) => {
663
701
  const t = Utils_1.unixTimestampSeconds().toString();
664
702
  const result = await query({
@@ -685,11 +723,9 @@ const makeMessagesSocket = (config) => {
685
723
  });
686
724
  return result;
687
725
  }
688
-
689
726
  const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
690
727
  const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
691
728
  const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
692
-
693
729
  return {
694
730
  ...sock,
695
731
  getPrivacyTokens,
@@ -757,120 +793,118 @@ const makeMessagesSocket = (config) => {
757
793
  const { filter = false, quoted } = options;
758
794
  const getParticipantAttr = () => filter ? { participant: { jid } } : {};
759
795
  const messageType = rahmi.detectType(content);
760
-
761
796
  if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
762
797
  typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
763
798
  const { disappearingMessagesInChat } = content
799
+
764
800
  const value = typeof disappearingMessagesInChat === 'boolean' ?
765
801
  (disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
766
802
  disappearingMessagesInChat
803
+
767
804
  await groupToggleEphemeral(jid, value)
768
805
  }
806
+
769
807
  else {
770
- if (messageType) {
771
- switch(messageType) {
772
- case 'PAYMENT':
773
- const paymentContent = await rahmi.handlePayment(content, quoted);
774
- return await relayMessage(jid, paymentContent, {
775
- messageId: Utils_1.generateMessageID(),
776
- ...getParticipantAttr()
777
- });
778
-
779
- case 'PRODUCT':
780
- const productContent = await rahmi.handleProduct(content, jid, quoted);
781
- const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
782
- return await relayMessage(jid, productMsg.message, {
783
- messageId: productMsg.key.id,
784
- ...getParticipantAttr()
785
- });
786
-
787
- case 'INTERACTIVE':
788
- const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
789
- const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
790
- return await relayMessage(jid, interactiveMsg.message, {
791
- messageId: interactiveMsg.key.id,
792
- ...getParticipantAttr()
793
- });
794
-
795
- case 'ALBUM':
796
- return await rahmi.handleAlbum(content, jid, quoted)
797
-
798
- case 'EVENT':
799
- return await rahmi.handleEvent(content, jid, quoted)
800
-
801
- case 'POLL_RESULT':
802
- return await rahmi.handlePollResult(content, jid, quoted)
803
-
804
- case 'GROUP_STORY':
805
- return await rahmi.handleGroupStory(content, jid, quoted)
806
- }
807
- }
808
-
809
- const fullMsg = await Utils_1.generateWAMessage(jid, content, {
810
- logger,
811
- userJid,
812
- quoted,
813
- getUrlInfo: text => link_preview_1.getUrlInfo(text, {
814
- thumbnailWidth: linkPreviewImageThumbnailWidth,
815
- fetchOpts: {
816
- timeout: 3000,
817
- ...axiosOptions || {}
818
- },
819
- logger,
820
- uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
821
- }),
822
- upload: async (readStream, opts) => {
823
- const up = await waUploadToServer(readStream, {
824
- ...opts,
825
- newsletter: WABinary_1.isJidNewsLetter(jid)
808
+ let mediaHandle
809
+
810
+
811
+ if (messageType) {
812
+ switch(messageType) {
813
+ case 'PAYMENT':
814
+ const paymentContent = await rahmi.handlePayment(content, quoted);
815
+ return await relayMessage(jid, paymentContent, {
816
+ messageId: Utils_1.generateMessageID(),
817
+ ...getParticipantAttr()
826
818
  });
827
- return up;
828
- },
829
- mediaCache: config.mediaCache,
830
- options: config.options,
831
- ...options
832
- });
833
819
 
834
- const isDeleteMsg = 'delete' in content && !!content.delete;
835
- const isEditMsg = 'edit' in content && !!content.edit;
836
- const isAiMsg = 'ai' in content && !!content.ai;
820
+ case 'PRODUCT':
821
+ const productContent = await rahmi.handleProduct(content, jid, quoted);
822
+ const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
823
+ return await relayMessage(jid, productMsg.message, {
824
+ messageId: productMsg.key.id,
825
+ ...getParticipantAttr()
826
+ });
837
827
 
838
- const additionalAttributes = {};
839
- const additionalNodes = [];
840
-
841
- if (isDeleteMsg) {
842
- const fromMe = content.delete?.fromMe;
843
- const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
844
- additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
845
- } else if (isEditMsg) {
846
- additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
847
- } else if (isAiMsg) {
848
- additionalNodes.push({
849
- attrs: {
850
- biz_bot: '1'
851
- },
852
- tag: "bot"
853
- });
828
+ case 'INTERACTIVE':
829
+ const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
830
+ const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
831
+ return await relayMessage(jid, interactiveMsg.message, {
832
+ messageId: interactiveMsg.key.id,
833
+ ...getParticipantAttr()
834
+ });
835
+ case 'ALBUM':
836
+ return await rahmi.handleAlbum(content, jid, quoted)
837
+ case 'EVENT':
838
+ return await rahmi.handleEvent(content, jid, quoted)
839
+ case 'POLL_RESULT':
840
+ return await rahmi.handlePollResult(content, jid, quoted)
841
+ case 'GROUP_STORY':
842
+ return await rahmi.handleGroupStory(content, jid, quoted)
854
843
  }
855
-
856
- await relayMessage(jid, fullMsg.message, {
857
- messageId: fullMsg.key.id,
858
- cachedGroupMetadata: options.cachedGroupMetadata,
859
- additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
860
- additionalAttributes,
861
- statusJidList: options.statusJidList,
862
- AI: isAiMsg
863
- });
864
-
865
- if (config.emitOwnEvents) {
866
- process.nextTick(() => {
867
- processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
844
+ }
845
+ const fullMsg = await Utils_1.generateWAMessage(jid, content, {
846
+ logger,
847
+ userJid,
848
+ quoted,
849
+ getUrlInfo: text => link_preview_1.getUrlInfo(text, {
850
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
851
+ fetchOpts: {
852
+ timeout: 3000,
853
+ ...axiosOptions || {}
854
+ },
855
+ logger,
856
+ uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
857
+ }),
858
+ upload: async (readStream, opts) => {
859
+ const up = await waUploadToServer(readStream, {
860
+ ...opts,
861
+ newsletter: WABinary_1.isJidNewsLetter(jid)
868
862
  });
869
- }
870
- return fullMsg;
863
+ return up;
864
+ },
865
+ mediaCache: config.mediaCache,
866
+ options: config.options,
867
+ ...options
868
+ });
869
+
870
+ const isDeleteMsg = 'delete' in content && !!content.delete;
871
+ const isEditMsg = 'edit' in content && !!content.edit;
872
+ const isAiMsg = 'ai' in content && !!content.ai;
873
+
874
+ const additionalAttributes = {};
875
+ const additionalNodes = [];
876
+
877
+ if (isDeleteMsg) {
878
+ const fromMe = content.delete?.fromMe;
879
+ const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
880
+ additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
881
+ } else if (isEditMsg) {
882
+ additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
883
+ } else if (isAiMsg) {
884
+ additionalNodes.push({
885
+ attrs: {
886
+ biz_bot: '1'
887
+ }, tag: "bot"
888
+ });
889
+ }
890
+
891
+ await relayMessage(jid, fullMsg.message, {
892
+ messageId: fullMsg.key.id,
893
+ cachedGroupMetadata: options.cachedGroupMetadata,
894
+ additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
895
+ additionalAttributes,
896
+ statusJidList: options.statusJidList
897
+ });
898
+
899
+ if (config.emitOwnEvents) {
900
+ process.nextTick(() => {
901
+ processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
902
+ });
903
+ }
904
+ return fullMsg;
871
905
  }
872
906
  }
873
- };
907
+ }
874
908
  };
875
-
876
909
  exports.makeMessagesSocket = makeMessagesSocket;
910
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyyxyzz/baileys-mod",
3
- "version": "6.0.40",
3
+ "version": "6.0.42",
4
4
  "description": "WhatsApp API Modification",
5
5
  "keywords": [
6
6
  "whatsapp",