@dyyxyzz/baileys-mod 6.0.41 → 6.0.43

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,37 +428,60 @@ const makeMessagesSocket = (config) => {
393
428
  await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
394
429
  }
395
430
  else if (isNewsletter) {
396
- if (message.protocolMessage?.editedMessage) {
397
- msgId = message.protocolMessage.key?.id
398
- message = message.protocolMessage.editedMessage
399
- }
400
- if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
401
- msgId = message.protocolMessage.key?.id
402
- message = {}
403
- }
404
-
405
- // 🔥 FIX: Deteksi button di newsletter SEBELUM encoding
406
- const hasButtonParams = buttonType ||
407
- messages.interactiveMessage?.nativeFlowMessage ||
408
- messages.buttonsMessage ||
409
- messages.listMessage;
410
-
411
- // Patch message dengan button support
412
- const patched = await patchMessageBeforeSending(message, [])
413
- const bytes = Utils_1.encodeNewsletterMessage(patched)
414
-
415
- // Push plaintext content
416
- binaryNodeContent.push({
417
- tag: 'plaintext',
418
- attrs: extraAttrs ? extraAttrs : {},
419
- content: bytes
420
- })
421
-
422
- // 🔥 CRITICAL: Tambahin button node untuk newsletter
423
- if (hasButtonParams) {
424
- logger.debug({ jid, buttonType }, 'adding button node for newsletter')
425
- }
426
- }
431
+ // Message edit
432
+ if (message.protocolMessage?.editedMessage) {
433
+ msgId = message.protocolMessage.key?.id
434
+ message = message.protocolMessage.editedMessage
435
+ }
436
+
437
+ // Message delete
438
+ if (message.protocolMessage?.type === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
439
+ msgId = message.protocolMessage.key?.id
440
+ message = {}
441
+ }
442
+
443
+ const patched = await patchMessageBeforeSending(message, [])
444
+ const bytes = Utils_1.encodeNewsletterMessage(patched)
445
+
446
+ // Tambahkan logic untuk detect button type
447
+ const buttonType = getButtonType(patched)
448
+ const mediaType = getMediaType(patched)
449
+
450
+ // Set media type di extraAttrs kalo ada
451
+ if (mediaType) {
452
+ extraAttrs['mediatype'] = mediaType
453
+ }
454
+
455
+ // Set decrypt-fail untuk message tertentu
456
+ if (patched.pinInChatMessage || patched.keepInChatMessage ||
457
+ patched.reactionMessage || patched.protocolMessage?.editedMessage) {
458
+ extraAttrs['decrypt-fail'] = 'hide'
459
+ }
460
+
461
+ // Tambah native flow name kalo ada
462
+ if (patched.interactiveResponseMessage?.nativeFlowResponseMessage) {
463
+ extraAttrs['native_flow_name'] = patched.interactiveResponseMessage?.nativeFlowResponseMessage.name
464
+ }
465
+
466
+ binaryNodeContent.push({
467
+ tag: 'plaintext',
468
+ attrs: extraAttrs,
469
+ content: bytes
470
+ })
471
+
472
+ if (buttonType) {
473
+ const content = WABinary_1.getAdditionalNode(buttonType)
474
+ const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
475
+
476
+ if (filteredNode) {
477
+ didPushAdditional = true
478
+ stanza.content.push(...additionalNodes)
479
+ } else {
480
+ binaryNodeContent.push(...content)
481
+ }
482
+ logger.debug({ jid }, 'adding business node to newsletter')
483
+ }
484
+ }
427
485
  else {
428
486
  const { user: meUser } = WABinary_1.jidDecode(meId);
429
487
  if (!participant) {
@@ -431,27 +489,30 @@ const makeMessagesSocket = (config) => {
431
489
  if (user !== meUser) {
432
490
  devices.push({ user: meUser })
433
491
  }
492
+
434
493
  if (additionalAttributes?.['category'] !== 'peer') {
435
494
  const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true)
495
+
436
496
  devices.push(...additionalDevices)
437
497
  }
438
498
  }
439
-
440
499
  const allJids = [];
441
500
  const meJids = [];
442
501
  const otherJids = [];
443
502
  for (const { user, device } of devices) {
444
503
  const isMe = user === meUser
445
504
  const jid = WABinary_1.jidEncode(isMe && isLid ? authState.creds?.me?.lid?.split(':')[0] || user : user, isLid ? 'lid' : 's.whatsapp.net', device)
505
+
446
506
  if (isMe) {
447
507
  meJids.push(jid)
448
508
  }
509
+
449
510
  else {
450
511
  otherJids.push(jid)
451
512
  }
513
+
452
514
  allJids.push(jid)
453
515
  }
454
-
455
516
  await assertSessions(allJids, false);
456
517
  const [{ nodes: meNodes, shouldIncludeDeviceIdentity: s1 }, { nodes: otherNodes, shouldIncludeDeviceIdentity: s2 }] = await Promise.all([
457
518
  createParticipantNodes(meJids, meMsg, extraAttrs),
@@ -461,14 +522,15 @@ const makeMessagesSocket = (config) => {
461
522
  participants.push(...otherNodes);
462
523
  shouldIncludeDeviceIdentity = shouldIncludeDeviceIdentity || s1 || s2;
463
524
  }
464
-
465
525
  if (participants.length) {
466
526
  if (additionalAttributes?.['category'] === 'peer') {
467
527
  const peerNode = participants[0]?.content?.[0]
528
+
468
529
  if (peerNode) {
469
- binaryNodeContent.push(peerNode)
530
+ binaryNodeContent.push(peerNode) // push only enc
470
531
  }
471
532
  }
533
+
472
534
  else {
473
535
  binaryNodeContent.push({
474
536
  tag: 'participants',
@@ -487,7 +549,9 @@ const makeMessagesSocket = (config) => {
487
549
  },
488
550
  content: binaryNodeContent
489
551
  }
490
-
552
+ // if the participant to send to is explicitly specified (generally retry recp)
553
+ // ensure the message is only sent to that person
554
+ // if a retry receipt is sent to everyone -- it'll fail decryption for everyone else who received the msg
491
555
  if (participant) {
492
556
  if (WABinary_1.isJidGroup(destinationJid)) {
493
557
  stanza.attrs.to = destinationJid;
@@ -504,7 +568,6 @@ const makeMessagesSocket = (config) => {
504
568
  else {
505
569
  stanza.attrs.to = destinationJid;
506
570
  }
507
-
508
571
  if (shouldIncludeDeviceIdentity) {
509
572
  stanza.content.push({
510
573
  tag: 'device-identity',
@@ -521,39 +584,31 @@ const makeMessagesSocket = (config) => {
521
584
  biz_bot: '1'
522
585
  }
523
586
  }
587
+
524
588
  const filteredBizBot = WABinary_1.getBinaryNodeFilter(additionalNodes ? additionalNodes : [])
589
+
525
590
  if (filteredBizBot) {
526
591
  stanza.content.push(...additionalNodes)
527
592
  didPushAdditional = true
528
593
  }
594
+
529
595
  else {
530
596
  stanza.content.push(botNode)
531
597
  }
532
598
  }
533
599
 
534
- // 🔥 FIX UTAMA: Support button params untuk SEMUA tipe (termasuk channel/newsletter)
535
- if (!isStatus) {
536
- // Deteksi apakah ada button params dalam message
537
- const hasButtonParams = buttonType ||
538
- messages.interactiveMessage?.nativeFlowMessage ||
539
- messages.buttonsMessage ||
540
- messages.listMessage;
541
-
542
- if (hasButtonParams) {
543
- // 🔥 CRITICAL FIX: Newsletter butuh business node meskipun plaintext
544
- const content = WABinary_1.getAdditionalNode(buttonType || 'interactive')
545
- const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
546
-
547
- if (filteredNode) {
548
- didPushAdditional = true
549
- stanza.content.push(...additionalNodes)
550
- }
551
- else if (content && content.length > 0) {
552
- // Push business node bahkan untuk newsletter
553
- stanza.content.push(...content)
554
- logger.debug({ jid, buttonType, isNewsletter }, 'added business node for buttons')
555
- }
600
+ if(!isNewsletter && buttonType && !isStatus) {
601
+ const content = WABinary_1.getAdditionalNode(buttonType)
602
+ const filteredNode = WABinary_1.getBinaryNodeFilter(additionalNodes)
603
+
604
+ if (filteredNode) {
605
+ didPushAdditional = true
606
+ stanza.content.push(...additionalNodes)
607
+ }
608
+ else {
609
+ stanza.content.push(...content)
556
610
  }
611
+ logger.debug({ jid }, 'adding business node')
557
612
  }
558
613
 
559
614
  if (!didPushAdditional && additionalNodes && additionalNodes.length > 0) {
@@ -580,10 +635,10 @@ const makeMessagesSocket = (config) => {
580
635
  }
581
636
 
582
637
  return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON)
638
+ // return msgId;
583
639
  };
584
-
585
640
  const getTypeMessage = (msg) => {
586
- const message = Utils_1.normalizeMessageContent(msg)
641
+ const message = Utils_1.normalizeMessageContent(msg)
587
642
  if (message.reactionMessage) {
588
643
  return 'reaction'
589
644
  }
@@ -668,14 +723,13 @@ const makeMessagesSocket = (config) => {
668
723
  else if (message.interactiveMessage?.nativeFlowMessage?.buttons?.[0]?.name === 'payment_method') {
669
724
  return 'payment_method'
670
725
  }
726
+ else if (message.interactiveMessage && message.interactiveMessage?.nativeFlowMessage) {
727
+ return 'interactive'
728
+ }
671
729
  else if (message.interactiveMessage?.nativeFlowMessage) {
672
730
  return 'native_flow'
673
731
  }
674
- else if (message.interactiveMessage) {
675
- return 'interactive'
676
- }
677
732
  }
678
-
679
733
  const getPrivacyTokens = async (jids) => {
680
734
  const t = Utils_1.unixTimestampSeconds().toString();
681
735
  const result = await query({
@@ -702,11 +756,9 @@ const makeMessagesSocket = (config) => {
702
756
  });
703
757
  return result;
704
758
  }
705
-
706
759
  const waUploadToServer = (0, Utils_1.getWAUploadToServer)(config, refreshMediaConn);
707
760
  const rahmi = new kikyy(Utils_1, waUploadToServer, relayMessage);
708
761
  const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
709
-
710
762
  return {
711
763
  ...sock,
712
764
  getPrivacyTokens,
@@ -774,120 +826,118 @@ const makeMessagesSocket = (config) => {
774
826
  const { filter = false, quoted } = options;
775
827
  const getParticipantAttr = () => filter ? { participant: { jid } } : {};
776
828
  const messageType = rahmi.detectType(content);
777
-
778
829
  if (typeof content === 'object' && 'disappearingMessagesInChat' in content &&
779
830
  typeof content['disappearingMessagesInChat'] !== 'undefined' && WABinary_1.isJidGroup(jid)) {
780
831
  const { disappearingMessagesInChat } = content
832
+
781
833
  const value = typeof disappearingMessagesInChat === 'boolean' ?
782
834
  (disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
783
835
  disappearingMessagesInChat
836
+
784
837
  await groupToggleEphemeral(jid, value)
785
838
  }
839
+
786
840
  else {
787
- if (messageType) {
788
- switch(messageType) {
789
- case 'PAYMENT':
790
- const paymentContent = await rahmi.handlePayment(content, quoted);
791
- return await relayMessage(jid, paymentContent, {
792
- messageId: Utils_1.generateMessageID(),
793
- ...getParticipantAttr()
794
- });
795
-
796
- case 'PRODUCT':
797
- const productContent = await rahmi.handleProduct(content, jid, quoted);
798
- const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
799
- return await relayMessage(jid, productMsg.message, {
800
- messageId: productMsg.key.id,
801
- ...getParticipantAttr()
802
- });
803
-
804
- case 'INTERACTIVE':
805
- const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
806
- const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
807
- return await relayMessage(jid, interactiveMsg.message, {
808
- messageId: interactiveMsg.key.id,
809
- ...getParticipantAttr()
810
- });
811
-
812
- case 'ALBUM':
813
- return await rahmi.handleAlbum(content, jid, quoted)
814
-
815
- case 'EVENT':
816
- return await rahmi.handleEvent(content, jid, quoted)
817
-
818
- case 'POLL_RESULT':
819
- return await rahmi.handlePollResult(content, jid, quoted)
820
-
821
- case 'GROUP_STORY':
822
- return await rahmi.handleGroupStory(content, jid, quoted)
823
- }
824
- }
825
-
826
- const fullMsg = await Utils_1.generateWAMessage(jid, content, {
827
- logger,
828
- userJid,
829
- quoted,
830
- getUrlInfo: text => link_preview_1.getUrlInfo(text, {
831
- thumbnailWidth: linkPreviewImageThumbnailWidth,
832
- fetchOpts: {
833
- timeout: 3000,
834
- ...axiosOptions || {}
835
- },
836
- logger,
837
- uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
838
- }),
839
- upload: async (readStream, opts) => {
840
- const up = await waUploadToServer(readStream, {
841
- ...opts,
842
- newsletter: WABinary_1.isJidNewsLetter(jid)
841
+ let mediaHandle
842
+
843
+
844
+ if (messageType) {
845
+ switch(messageType) {
846
+ case 'PAYMENT':
847
+ const paymentContent = await rahmi.handlePayment(content, quoted);
848
+ return await relayMessage(jid, paymentContent, {
849
+ messageId: Utils_1.generateMessageID(),
850
+ ...getParticipantAttr()
843
851
  });
844
- return up;
845
- },
846
- mediaCache: config.mediaCache,
847
- options: config.options,
848
- ...options
849
- });
850
852
 
851
- const isDeleteMsg = 'delete' in content && !!content.delete;
852
- const isEditMsg = 'edit' in content && !!content.edit;
853
- const isAiMsg = 'ai' in content && !!content.ai;
853
+ case 'PRODUCT':
854
+ const productContent = await rahmi.handleProduct(content, jid, quoted);
855
+ const productMsg = await Utils_1.generateWAMessageFromContent(jid, productContent, { quoted });
856
+ return await relayMessage(jid, productMsg.message, {
857
+ messageId: productMsg.key.id,
858
+ ...getParticipantAttr()
859
+ });
854
860
 
855
- const additionalAttributes = {};
856
- const additionalNodes = [];
857
-
858
- if (isDeleteMsg) {
859
- const fromMe = content.delete?.fromMe;
860
- const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
861
- additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
862
- } else if (isEditMsg) {
863
- additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
864
- } else if (isAiMsg) {
865
- additionalNodes.push({
866
- attrs: {
867
- biz_bot: '1'
868
- },
869
- tag: "bot"
870
- });
861
+ case 'INTERACTIVE':
862
+ const interactiveContent = await rahmi.handleInteractive(content, jid, quoted);
863
+ const interactiveMsg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, { quoted });
864
+ return await relayMessage(jid, interactiveMsg.message, {
865
+ messageId: interactiveMsg.key.id,
866
+ ...getParticipantAttr()
867
+ });
868
+ case 'ALBUM':
869
+ return await rahmi.handleAlbum(content, jid, quoted)
870
+ case 'EVENT':
871
+ return await rahmi.handleEvent(content, jid, quoted)
872
+ case 'POLL_RESULT':
873
+ return await rahmi.handlePollResult(content, jid, quoted)
874
+ case 'GROUP_STORY':
875
+ return await rahmi.handleGroupStory(content, jid, quoted)
871
876
  }
872
-
873
- await relayMessage(jid, fullMsg.message, {
874
- messageId: fullMsg.key.id,
875
- cachedGroupMetadata: options.cachedGroupMetadata,
876
- additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
877
- additionalAttributes,
878
- statusJidList: options.statusJidList,
879
- AI: isAiMsg
880
- });
881
-
882
- if (config.emitOwnEvents) {
883
- process.nextTick(() => {
884
- processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
877
+ }
878
+ const fullMsg = await Utils_1.generateWAMessage(jid, content, {
879
+ logger,
880
+ userJid,
881
+ quoted,
882
+ getUrlInfo: text => link_preview_1.getUrlInfo(text, {
883
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
884
+ fetchOpts: {
885
+ timeout: 3000,
886
+ ...axiosOptions || {}
887
+ },
888
+ logger,
889
+ uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
890
+ }),
891
+ upload: async (readStream, opts) => {
892
+ const up = await waUploadToServer(readStream, {
893
+ ...opts,
894
+ newsletter: WABinary_1.isJidNewsLetter(jid)
885
895
  });
886
- }
887
- return fullMsg;
896
+ return up;
897
+ },
898
+ mediaCache: config.mediaCache,
899
+ options: config.options,
900
+ ...options
901
+ });
902
+
903
+ const isDeleteMsg = 'delete' in content && !!content.delete;
904
+ const isEditMsg = 'edit' in content && !!content.edit;
905
+ const isAiMsg = 'ai' in content && !!content.ai;
906
+
907
+ const additionalAttributes = {};
908
+ const additionalNodes = [];
909
+
910
+ if (isDeleteMsg) {
911
+ const fromMe = content.delete?.fromMe;
912
+ const isGroup = WABinary_1.isJidGroup(content.delete?.remoteJid);
913
+ additionalAttributes.edit = (isGroup && !fromMe) || WABinary_1.isJidNewsLetter(jid) ? '8' : '7';
914
+ } else if (isEditMsg) {
915
+ additionalAttributes.edit = WABinary_1.isJidNewsLetter(jid) ? '3' : '1';
916
+ } else if (isAiMsg) {
917
+ additionalNodes.push({
918
+ attrs: {
919
+ biz_bot: '1'
920
+ }, tag: "bot"
921
+ });
922
+ }
923
+
924
+ await relayMessage(jid, fullMsg.message, {
925
+ messageId: fullMsg.key.id,
926
+ cachedGroupMetadata: options.cachedGroupMetadata,
927
+ additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes,
928
+ additionalAttributes,
929
+ statusJidList: options.statusJidList
930
+ });
931
+
932
+ if (config.emitOwnEvents) {
933
+ process.nextTick(() => {
934
+ processingMutex.mutex(() => upsertMessage(fullMsg, 'append'));
935
+ });
936
+ }
937
+ return fullMsg;
888
938
  }
889
939
  }
890
- };
940
+ }
891
941
  };
892
-
893
942
  exports.makeMessagesSocket = makeMessagesSocket;
943
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyyxyzz/baileys-mod",
3
- "version": "6.0.41",
3
+ "version": "6.0.43",
4
4
  "description": "WhatsApp API Modification",
5
5
  "keywords": [
6
6
  "whatsapp",