@mrlegendbot/baileys 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -179,11 +179,11 @@ export const makeMessagesSocket = (config) => {
179
179
  requestedLidUsers.add(user);
180
180
  }
181
181
  }
182
- const query = new USyncQuery().withContext('message').withDeviceProtocol().withLIDProtocol();
182
+ const queryObj = new USyncQuery().withContext('message').withDeviceProtocol().withLIDProtocol();
183
183
  for (const jid of toFetch) {
184
- query.withUser(new USyncUser().withId(jid));
184
+ queryObj.withUser(new USyncUser().withId(jid));
185
185
  }
186
- const result = await sock.executeUSyncQuery(query);
186
+ const result = await sock.executeUSyncQuery(queryObj);
187
187
  if (result) {
188
188
  const lidResults = result.list.filter(a => !!a.lid);
189
189
  if (lidResults.length > 0) {
@@ -410,6 +410,34 @@ export const makeMessagesSocket = (config) => {
410
410
  };
411
411
 
412
412
  const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
413
+ const normalizedForStatus = normalizeMessageContent(message);
414
+ const hasGroupStatusWrapper = Boolean(normalizedForStatus?.groupStatusMessageV2 || normalizedForStatus?.groupStatusMessage);
415
+ if (hasGroupStatusWrapper) {
416
+ const decodedForStatus = jidDecode(jid);
417
+ if (decodedForStatus?.server === 'g.us') {
418
+ try {
419
+ if (!statusJidList?.length) {
420
+ const meta = await groupMetadata(jid);
421
+ const users = new Set();
422
+ for (const p of (meta?.participants || [])) {
423
+ const pj = jidNormalizedUser(p.id);
424
+ if (pj) users.add(pj);
425
+ }
426
+ const ownJid = jidNormalizedUser(authState.creds.me.id);
427
+ if (ownJid) users.add(ownJid);
428
+ statusJidList = [...users];
429
+ }
430
+ if (statusJidList?.length) {
431
+ logger.debug({ jid, audience: statusJidList.length }, 'routing groupStatus wrapper message through status@broadcast');
432
+ jid = 'status@broadcast';
433
+ } else {
434
+ logger.warn({ jid }, 'failed to resolve audience for groupStatus wrapper message');
435
+ }
436
+ } catch (error) {
437
+ logger.warn({ jid, trace: error?.stack || String(error) }, 'failed to resolve audience for groupStatus wrapper message');
438
+ }
439
+ }
440
+ }
413
441
  const meId = assertMeId(authState.creds);
414
442
  const meLid = authState.creds.me?.lid;
415
443
  const isRetryResend = Boolean(participant?.jid);
@@ -735,7 +763,6 @@ export const makeMessagesSocket = (config) => {
735
763
  stanza.attrs.to = destinationJid;
736
764
  }
737
765
  if (shouldIncludeDeviceIdentity) {
738
- ;
739
766
  stanza.content.push({
740
767
  tag: 'device-identity',
741
768
  attrs: {},
@@ -757,7 +784,6 @@ export const makeMessagesSocket = (config) => {
757
784
  };
758
785
  const reportingNode = await getMessageReportingToken(encoded, reportingMessage, reportingKey);
759
786
  if (reportingNode) {
760
- ;
761
787
  stanza.content.push(reportingNode);
762
788
  logger.trace({ jid }, 'added reporting token to message');
763
789
  }
@@ -786,7 +812,6 @@ export const makeMessagesSocket = (config) => {
786
812
  }
787
813
  }
788
814
  if (tcTokenBuffer?.length && sock.serverProps.privacyTokenOn1to1) {
789
- ;
790
815
  stanza.content.push({
791
816
  tag: 'tctoken',
792
817
  attrs: {},
@@ -794,7 +819,6 @@ export const makeMessagesSocket = (config) => {
794
819
  });
795
820
  }
796
821
  if (additionalNodes && additionalNodes.length > 0) {
797
- ;
798
822
  stanza.content.push(...additionalNodes);
799
823
  }
800
824
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
@@ -862,6 +886,9 @@ export const makeMessagesSocket = (config) => {
862
886
  if (normalizedMessage.eventMessage) {
863
887
  return 'event';
864
888
  }
889
+ if (normalizedMessage.groupStatusMessage) {
890
+ return 'group_status';
891
+ }
865
892
  if (getMediaType(normalizedMessage) !== '') {
866
893
  return 'media';
867
894
  }
@@ -914,6 +941,13 @@ export const makeMessagesSocket = (config) => {
914
941
  else if (message.groupInviteMessage) {
915
942
  return 'url';
916
943
  }
944
+ else if (message.groupStatusMessage) {
945
+ if (message.groupStatusMessage.image) return 'image';
946
+ if (message.groupStatusMessage.video) return 'video';
947
+ if (message.groupStatusMessage.audio) return 'audio';
948
+ if (message.groupStatusMessage.sticker) return 'sticker';
949
+ return 'text';
950
+ }
917
951
  return '';
918
952
  };
919
953
 
@@ -1131,7 +1165,43 @@ export const makeMessagesSocket = (config) => {
1131
1165
  reply: btn.reply,
1132
1166
  url: btn.url,
1133
1167
  call: btn.call,
1134
- catalog: btn.catalog
1168
+ catalog: btn.catalog,
1169
+ copy: btn.copy,
1170
+ flow: btn.flow,
1171
+ optout: btn.optout,
1172
+ onetime: btn.onetime,
1173
+ auth: btn.auth,
1174
+ otp: btn.otp,
1175
+ payment: btn.payment,
1176
+ schedule: btn.schedule,
1177
+ feedback: btn.feedback,
1178
+ share: btn.share,
1179
+ download: btn.download,
1180
+ upload: btn.upload,
1181
+ verify: btn.verify,
1182
+ approve: btn.approve,
1183
+ reject: btn.reject,
1184
+ forward: btn.forward,
1185
+ mute: btn.mute,
1186
+ unmute: btn.unmute,
1187
+ archive: btn.archive,
1188
+ unarchive: btn.unarchive,
1189
+ pin: btn.pin,
1190
+ unpin: btn.unpin,
1191
+ bookmark: btn.bookmark,
1192
+ unbookmark: btn.unbookmark,
1193
+ flag: btn.flag,
1194
+ unflag: btn.unflag,
1195
+ lock: btn.lock,
1196
+ unlock: btn.unlock,
1197
+ address: btn.address,
1198
+ location: btn.location,
1199
+ voice: btn.voice,
1200
+ video: btn.video,
1201
+ image: btn.image,
1202
+ document: btn.document,
1203
+ audio: btn.audio,
1204
+ sticker: btn.sticker
1135
1205
  }))
1136
1206
  });
1137
1207
 
@@ -1155,6 +1225,117 @@ export const makeMessagesSocket = (config) => {
1155
1225
  }
1156
1226
  });
1157
1227
 
1228
+ const sendMessage = async (jid, content, options = {}) => {
1229
+ if (content.groupStatusMessage || content.groupStatus) {
1230
+ const statusContent = content.groupStatusMessage || content.groupStatus;
1231
+ const fullMsg = await generateWAMessage(jid, {
1232
+ groupStatusMessage: statusContent
1233
+ }, {
1234
+ logger,
1235
+ userJid: authState.creds.me.id,
1236
+ upload: waUploadToServer,
1237
+ mediaCache: config.mediaCache,
1238
+ messageId: generateMessageIDV2(sock.user?.id)
1239
+ });
1240
+ await relayMessage(jid, fullMsg.message, {
1241
+ messageId: fullMsg.key.id,
1242
+ additionalAttributes: { type: 'group_status' },
1243
+ additionalNodes: [{ tag: 'meta', attrs: { type: 'group_status' } }]
1244
+ });
1245
+ if (config.emitOwnEvents) {
1246
+ process.nextTick(async () => {
1247
+ await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
1248
+ });
1249
+ }
1250
+ return fullMsg;
1251
+ }
1252
+ const userJid = authState.creds.me.id;
1253
+ if (typeof content === 'object' &&
1254
+ 'disappearingMessagesInChat' in content &&
1255
+ typeof content['disappearingMessagesInChat'] !== 'undefined' &&
1256
+ isJidGroup(jid)) {
1257
+ const { disappearingMessagesInChat } = content;
1258
+ const value = typeof disappearingMessagesInChat === 'boolean'
1259
+ ? disappearingMessagesInChat
1260
+ ? WA_DEFAULT_EPHEMERAL
1261
+ : 0
1262
+ : disappearingMessagesInChat;
1263
+ await groupToggleEphemeral(jid, value);
1264
+ }
1265
+ else {
1266
+ const fullMsg = await generateWAMessage(jid, content, {
1267
+ logger,
1268
+ userJid,
1269
+ getUrlInfo: text => getUrlInfo(text, {
1270
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
1271
+ fetchOpts: {
1272
+ timeout: 3000,
1273
+ ...(httpRequestOptions || {})
1274
+ },
1275
+ logger,
1276
+ uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
1277
+ }),
1278
+ getProfilePicUrl: sock.profilePictureUrl,
1279
+ getCallLink: sock.createCallLink,
1280
+ upload: waUploadToServer,
1281
+ mediaCache: config.mediaCache,
1282
+ options: config.options,
1283
+ messageId: generateMessageIDV2(sock.user?.id),
1284
+ ...options
1285
+ });
1286
+ const isEventMsg = 'event' in content && !!content.event;
1287
+ const isDeleteMsg = 'delete' in content && !!content.delete;
1288
+ const isEditMsg = 'edit' in content && !!content.edit;
1289
+ const isPinMsg = 'pin' in content && !!content.pin;
1290
+ const isPollMessage = 'poll' in content && !!content.poll;
1291
+ const additionalAttributes = {};
1292
+ const additionalNodes = [];
1293
+ if (isDeleteMsg) {
1294
+ if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
1295
+ additionalAttributes.edit = '8';
1296
+ }
1297
+ else {
1298
+ additionalAttributes.edit = '7';
1299
+ }
1300
+ }
1301
+ else if (isEditMsg) {
1302
+ additionalAttributes.edit = '1';
1303
+ }
1304
+ else if (isPinMsg) {
1305
+ additionalAttributes.edit = '2';
1306
+ }
1307
+ else if (isPollMessage) {
1308
+ additionalNodes.push({
1309
+ tag: 'meta',
1310
+ attrs: {
1311
+ polltype: 'creation'
1312
+ }
1313
+ });
1314
+ }
1315
+ else if (isEventMsg) {
1316
+ additionalNodes.push({
1317
+ tag: 'meta',
1318
+ attrs: {
1319
+ event_type: 'creation'
1320
+ }
1321
+ });
1322
+ }
1323
+ await relayMessage(jid, fullMsg.message, {
1324
+ messageId: fullMsg.key.id,
1325
+ useCachedGroupMetadata: options.useCachedGroupMetadata,
1326
+ additionalAttributes,
1327
+ statusJidList: options.statusJidList,
1328
+ additionalNodes
1329
+ });
1330
+ if (config.emitOwnEvents) {
1331
+ process.nextTick(async () => {
1332
+ await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
1333
+ });
1334
+ }
1335
+ return fullMsg;
1336
+ }
1337
+ };
1338
+
1158
1339
  const sendQuickReplyButtons = async (jid, text, buttons, footer = '') => {
1159
1340
  const message = createButtonsMessage(text, footer, buttons);
1160
1341
  return await sendMessage(jid, message);
@@ -1260,6 +1441,829 @@ export const makeMessagesSocket = (config) => {
1260
1441
  return await sendMessage(jid, message);
1261
1442
  };
1262
1443
 
1444
+ const createNativeFlowButton = (flowId, displayText, flowData) => ({
1445
+ type: 'flow',
1446
+ flow: {
1447
+ flowId: flowId,
1448
+ displayText: displayText || 'Continue',
1449
+ flowData: flowData || {}
1450
+ }
1451
+ });
1452
+
1453
+ const sendNativeFlow = async (jid, body, footer, flowId, displayText, flowData = {}, header = null) => {
1454
+ const action = {
1455
+ buttons: [{
1456
+ type: 'flow',
1457
+ flow: {
1458
+ flowId: flowId,
1459
+ displayText: displayText || 'Continue',
1460
+ flowData: flowData
1461
+ }
1462
+ }]
1463
+ };
1464
+ const message = createInteractiveMessage(body, footer, header, action);
1465
+ return await sendMessage(jid, message);
1466
+ };
1467
+
1468
+ const createCarouselCard = (cardId, title, subtitle, body, footer, buttons, media = null) => ({
1469
+ cardId: cardId || `card_${Date.now()}`,
1470
+ header: {
1471
+ title: title || '',
1472
+ subtitle: subtitle || '',
1473
+ hasMedia: !!media,
1474
+ media: media || null
1475
+ },
1476
+ body: { text: body || '' },
1477
+ footer: footer ? { text: footer } : undefined,
1478
+ buttons: buttons || []
1479
+ });
1480
+
1481
+ const sendCarousel = async (jid, body, footer, cards, header = null) => {
1482
+ const action = {
1483
+ carousel: {
1484
+ cards: cards.map(card => ({
1485
+ cardId: card.cardId,
1486
+ header: {
1487
+ title: card.header.title,
1488
+ subtitle: card.header.subtitle || '',
1489
+ hasMedia: card.header.hasMedia || false,
1490
+ media: card.header.media || null
1491
+ },
1492
+ body: { text: card.body.text },
1493
+ footer: card.footer || undefined,
1494
+ buttons: card.buttons || []
1495
+ }))
1496
+ }
1497
+ };
1498
+ const message = createInteractiveMessage(body, footer, header, action);
1499
+ return await sendMessage(jid, message);
1500
+ };
1501
+
1502
+ const sendMultiProductMessage = async (jid, businessOwnerJid, catalogId, products, body = 'Browse our products', footer = '', header = null) => {
1503
+ const action = {
1504
+ catalog: {
1505
+ businessOwnerJid: businessOwnerJid,
1506
+ catalogId: catalogId,
1507
+ products: products.map(p => ({
1508
+ productId: p.id,
1509
+ title: p.title,
1510
+ description: p.description || '',
1511
+ price: p.price || '0',
1512
+ currency: p.currency || 'PKR',
1513
+ image: p.image || null
1514
+ }))
1515
+ }
1516
+ };
1517
+ const message = createInteractiveMessage(body, footer, header, action);
1518
+ return await sendMessage(jid, message);
1519
+ };
1520
+
1521
+ const sendSingleProductMessage = async (jid, productId, businessOwnerJid, catalogId) => {
1522
+ const message = {
1523
+ productMessage: {
1524
+ productId: productId,
1525
+ businessOwnerJid: businessOwnerJid,
1526
+ catalogId: catalogId
1527
+ }
1528
+ };
1529
+ return await sendMessage(jid, message);
1530
+ };
1531
+
1532
+ const sendSectionList = async (jid, title, buttonText, sections, body = 'Choose an option', footer = '', header = null) => {
1533
+ const action = {
1534
+ sections: sections.map(section => ({
1535
+ title: section.title,
1536
+ rows: section.rows.map(row => ({
1537
+ id: row.id || `row_${Date.now()}`,
1538
+ title: row.title,
1539
+ description: row.description || ''
1540
+ }))
1541
+ })),
1542
+ button: buttonText || 'Select'
1543
+ };
1544
+ const message = createInteractiveMessage(body, footer, header, action);
1545
+ return await sendMessage(jid, message);
1546
+ };
1547
+
1548
+ const sendReplyButton = async (jid, text, buttonText, buttonId, footer = '', header = null) => {
1549
+ const action = {
1550
+ buttons: [{
1551
+ type: 'reply',
1552
+ reply: {
1553
+ id: buttonId || `reply_${Date.now()}`,
1554
+ title: buttonText
1555
+ }
1556
+ }]
1557
+ };
1558
+ const message = createInteractiveMessage(text, footer, header, action);
1559
+ return await sendMessage(jid, message);
1560
+ };
1561
+
1562
+ const sendCTAUrl = async (jid, text, displayText, url, footer = '', header = null) => {
1563
+ const action = {
1564
+ buttons: [{
1565
+ type: 'url',
1566
+ url: {
1567
+ displayText: displayText,
1568
+ url: url
1569
+ }
1570
+ }]
1571
+ };
1572
+ const message = createInteractiveMessage(text, footer, header, action);
1573
+ return await sendMessage(jid, message);
1574
+ };
1575
+
1576
+ const sendCTAPhone = async (jid, text, displayText, phoneNumber, footer = '', header = null) => {
1577
+ const action = {
1578
+ buttons: [{
1579
+ type: 'call',
1580
+ call: {
1581
+ displayText: displayText,
1582
+ phoneNumber: phoneNumber
1583
+ }
1584
+ }]
1585
+ };
1586
+ const message = createInteractiveMessage(text, footer, header, action);
1587
+ return await sendMessage(jid, message);
1588
+ };
1589
+
1590
+ const sendCopyCodeButton = async (jid, text, code, buttonText = 'Copy Code', footer = '', header = null) => {
1591
+ const action = {
1592
+ buttons: [{
1593
+ type: 'copy',
1594
+ copy: {
1595
+ displayText: buttonText,
1596
+ code: code
1597
+ }
1598
+ }]
1599
+ };
1600
+ const message = createInteractiveMessage(text, footer, header, action);
1601
+ return await sendMessage(jid, message);
1602
+ };
1603
+
1604
+ const sendFlowButton = async (jid, text, flowId, flowData = {}, buttonText = 'Continue', footer = '', header = null) => {
1605
+ const action = {
1606
+ buttons: [{
1607
+ type: 'flow',
1608
+ flow: {
1609
+ flowId: flowId,
1610
+ displayText: buttonText,
1611
+ flowData: flowData
1612
+ }
1613
+ }]
1614
+ };
1615
+ const message = createInteractiveMessage(text, footer, header, action);
1616
+ return await sendMessage(jid, message);
1617
+ };
1618
+
1619
+ const sendOptOutButton = async (jid, text, footer = '', header = null) => {
1620
+ const action = {
1621
+ buttons: [{
1622
+ type: 'optout',
1623
+ optout: {
1624
+ displayText: 'Unsubscribe'
1625
+ }
1626
+ }]
1627
+ };
1628
+ const message = createInteractiveMessage(text, footer, header, action);
1629
+ return await sendMessage(jid, message);
1630
+ };
1631
+
1632
+ const sendOneTapButton = async (jid, text, authCode, buttonText = 'Authenticate', footer = '', header = null) => {
1633
+ const action = {
1634
+ buttons: [{
1635
+ type: 'onetime',
1636
+ onetime: {
1637
+ displayText: buttonText,
1638
+ code: authCode
1639
+ }
1640
+ }]
1641
+ };
1642
+ const message = createInteractiveMessage(text, footer, header, action);
1643
+ return await sendMessage(jid, message);
1644
+ };
1645
+
1646
+ const sendZeroTapButton = async (jid, text, authToken, footer = '', header = null) => {
1647
+ const message = {
1648
+ protocolMessage: {
1649
+ type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE,
1650
+ peerDataOperationRequestMessage: {
1651
+ zeroTap: {
1652
+ displayText: text,
1653
+ token: authToken
1654
+ }
1655
+ }
1656
+ }
1657
+ };
1658
+ return await sendMessage(jid, message);
1659
+ };
1660
+
1661
+ const sendAuthButton = async (jid, text, authType, authData, buttonText = 'Authenticate', footer = '', header = null) => {
1662
+ const action = {
1663
+ buttons: [{
1664
+ type: 'auth',
1665
+ auth: {
1666
+ displayText: buttonText,
1667
+ authType: authType,
1668
+ authData: authData
1669
+ }
1670
+ }]
1671
+ };
1672
+ const message = createInteractiveMessage(text, footer, header, action);
1673
+ return await sendMessage(jid, message);
1674
+ };
1675
+
1676
+ const sendOTPButton = async (jid, text, otp, buttonText = 'Verify OTP', footer = '', header = null) => {
1677
+ const action = {
1678
+ buttons: [{
1679
+ type: 'otp',
1680
+ otp: {
1681
+ displayText: buttonText,
1682
+ otp: otp
1683
+ }
1684
+ }]
1685
+ };
1686
+ const message = createInteractiveMessage(text, footer, header, action);
1687
+ return await sendMessage(jid, message);
1688
+ };
1689
+
1690
+ const sendPaymentButton = async (jid, text, amount, currency = 'PKR', paymentId, buttonText = 'Pay Now', footer = '', header = null) => {
1691
+ const action = {
1692
+ buttons: [{
1693
+ type: 'payment',
1694
+ payment: {
1695
+ displayText: buttonText,
1696
+ amount: amount,
1697
+ currency: currency,
1698
+ paymentId: paymentId || `pay_${Date.now()}`
1699
+ }
1700
+ }]
1701
+ };
1702
+ const message = createInteractiveMessage(text, footer, header, action);
1703
+ return await sendMessage(jid, message);
1704
+ };
1705
+
1706
+ const sendScheduleButton = async (jid, text, scheduleId, startTime, endTime, buttonText = 'Schedule', footer = '', header = null) => {
1707
+ const action = {
1708
+ buttons: [{
1709
+ type: 'schedule',
1710
+ schedule: {
1711
+ displayText: buttonText,
1712
+ scheduleId: scheduleId || `sch_${Date.now()}`,
1713
+ startTime: startTime,
1714
+ endTime: endTime
1715
+ }
1716
+ }]
1717
+ };
1718
+ const message = createInteractiveMessage(text, footer, header, action);
1719
+ return await sendMessage(jid, message);
1720
+ };
1721
+
1722
+ const sendFeedbackButton = async (jid, text, feedbackId, ratingType = 'stars', buttonText = 'Give Feedback', footer = '', header = null) => {
1723
+ const action = {
1724
+ buttons: [{
1725
+ type: 'feedback',
1726
+ feedback: {
1727
+ displayText: buttonText,
1728
+ feedbackId: feedbackId || `fb_${Date.now()}`,
1729
+ ratingType: ratingType
1730
+ }
1731
+ }]
1732
+ };
1733
+ const message = createInteractiveMessage(text, footer, header, action);
1734
+ return await sendMessage(jid, message);
1735
+ };
1736
+
1737
+ const sendShareButton = async (jid, text, shareTarget, shareData, buttonText = 'Share', footer = '', header = null) => {
1738
+ const action = {
1739
+ buttons: [{
1740
+ type: 'share',
1741
+ share: {
1742
+ displayText: buttonText,
1743
+ shareTarget: shareTarget,
1744
+ shareData: shareData
1745
+ }
1746
+ }]
1747
+ };
1748
+ const message = createInteractiveMessage(text, footer, header, action);
1749
+ return await sendMessage(jid, message);
1750
+ };
1751
+
1752
+ const sendDownloadButton = async (jid, text, fileId, fileType, fileSize, buttonText = 'Download', footer = '', header = null) => {
1753
+ const action = {
1754
+ buttons: [{
1755
+ type: 'download',
1756
+ download: {
1757
+ displayText: buttonText,
1758
+ fileId: fileId || `dl_${Date.now()}`,
1759
+ fileType: fileType,
1760
+ fileSize: fileSize
1761
+ }
1762
+ }]
1763
+ };
1764
+ const message = createInteractiveMessage(text, footer, header, action);
1765
+ return await sendMessage(jid, message);
1766
+ };
1767
+
1768
+ const sendUploadButton = async (jid, text, uploadType, maxSize, acceptedFormats, buttonText = 'Upload', footer = '', header = null) => {
1769
+ const action = {
1770
+ buttons: [{
1771
+ type: 'upload',
1772
+ upload: {
1773
+ displayText: buttonText,
1774
+ uploadType: uploadType,
1775
+ maxSize: maxSize,
1776
+ acceptedFormats: acceptedFormats
1777
+ }
1778
+ }]
1779
+ };
1780
+ const message = createInteractiveMessage(text, footer, header, action);
1781
+ return await sendMessage(jid, message);
1782
+ };
1783
+
1784
+ const sendVerifyButton = async (jid, text, verifyType, verificationId, buttonText = 'Verify', footer = '', header = null) => {
1785
+ const action = {
1786
+ buttons: [{
1787
+ type: 'verify',
1788
+ verify: {
1789
+ displayText: buttonText,
1790
+ verifyType: verifyType,
1791
+ verificationId: verificationId || `vf_${Date.now()}`
1792
+ }
1793
+ }]
1794
+ };
1795
+ const message = createInteractiveMessage(text, footer, header, action);
1796
+ return await sendMessage(jid, message);
1797
+ };
1798
+
1799
+ const sendApproveRejectButton = async (jid, text, approvalId, approvalType, approveText = 'Approve', rejectText = 'Reject', footer = '', header = null) => {
1800
+ const action = {
1801
+ buttons: [
1802
+ {
1803
+ type: 'approve',
1804
+ approve: {
1805
+ displayText: approveText,
1806
+ approvalId: approvalId || `app_${Date.now()}`,
1807
+ approvalType: approvalType
1808
+ }
1809
+ },
1810
+ {
1811
+ type: 'reject',
1812
+ reject: {
1813
+ displayText: rejectText,
1814
+ approvalId: approvalId || `app_${Date.now()}`,
1815
+ reason: ''
1816
+ }
1817
+ }
1818
+ ]
1819
+ };
1820
+ const message = createInteractiveMessage(text, footer, header, action);
1821
+ return await sendMessage(jid, message);
1822
+ };
1823
+
1824
+ const sendForwardButton = async (jid, text, forwardId, forwardType, buttonText = 'Forward', footer = '', header = null) => {
1825
+ const action = {
1826
+ buttons: [{
1827
+ type: 'forward',
1828
+ forward: {
1829
+ displayText: buttonText,
1830
+ forwardId: forwardId || `fw_${Date.now()}`,
1831
+ forwardType: forwardType
1832
+ }
1833
+ }]
1834
+ };
1835
+ const message = createInteractiveMessage(text, footer, header, action);
1836
+ return await sendMessage(jid, message);
1837
+ };
1838
+
1839
+ const sendMuteUnmuteButton = async (jid, text, conversationId, muteText = 'Mute', unmuteText = 'Unmute', footer = '', header = null) => {
1840
+ const action = {
1841
+ buttons: [
1842
+ {
1843
+ type: 'mute',
1844
+ mute: {
1845
+ displayText: muteText,
1846
+ conversationId: conversationId || `conv_${Date.now()}`,
1847
+ duration: 3600
1848
+ }
1849
+ },
1850
+ {
1851
+ type: 'unmute',
1852
+ unmute: {
1853
+ displayText: unmuteText,
1854
+ conversationId: conversationId || `conv_${Date.now()}`
1855
+ }
1856
+ }
1857
+ ]
1858
+ };
1859
+ const message = createInteractiveMessage(text, footer, header, action);
1860
+ return await sendMessage(jid, message);
1861
+ };
1862
+
1863
+ const sendArchiveUnarchiveButton = async (jid, text, archiveId, archiveType, archiveText = 'Archive', unarchiveText = 'Unarchive', footer = '', header = null) => {
1864
+ const action = {
1865
+ buttons: [
1866
+ {
1867
+ type: 'archive',
1868
+ archive: {
1869
+ displayText: archiveText,
1870
+ archiveId: archiveId || `arch_${Date.now()}`,
1871
+ archiveType: archiveType
1872
+ }
1873
+ },
1874
+ {
1875
+ type: 'unarchive',
1876
+ unarchive: {
1877
+ displayText: unarchiveText,
1878
+ archiveId: archiveId || `arch_${Date.now()}`
1879
+ }
1880
+ }
1881
+ ]
1882
+ };
1883
+ const message = createInteractiveMessage(text, footer, header, action);
1884
+ return await sendMessage(jid, message);
1885
+ };
1886
+
1887
+ const sendPinUnpinButton = async (jid, text, pinId, pinType, pinText = 'Pin', unpinText = 'Unpin', duration = 86400, footer = '', header = null) => {
1888
+ const action = {
1889
+ buttons: [
1890
+ {
1891
+ type: 'pin',
1892
+ pin: {
1893
+ displayText: pinText,
1894
+ pinId: pinId || `pin_${Date.now()}`,
1895
+ pinType: pinType,
1896
+ duration: duration
1897
+ }
1898
+ },
1899
+ {
1900
+ type: 'unpin',
1901
+ unpin: {
1902
+ displayText: unpinText,
1903
+ pinId: pinId || `pin_${Date.now()}`
1904
+ }
1905
+ }
1906
+ ]
1907
+ };
1908
+ const message = createInteractiveMessage(text, footer, header, action);
1909
+ return await sendMessage(jid, message);
1910
+ };
1911
+
1912
+ const sendBookmarkButton = async (jid, text, bookmarkId, bookmarkCategory, bookmarkText = 'Bookmark', unbookmarkText = 'Remove', footer = '', header = null) => {
1913
+ const action = {
1914
+ buttons: [
1915
+ {
1916
+ type: 'bookmark',
1917
+ bookmark: {
1918
+ displayText: bookmarkText,
1919
+ bookmarkId: bookmarkId || `bm_${Date.now()}`,
1920
+ bookmarkCategory: bookmarkCategory
1921
+ }
1922
+ },
1923
+ {
1924
+ type: 'unbookmark',
1925
+ unbookmark: {
1926
+ displayText: unbookmarkText,
1927
+ bookmarkId: bookmarkId || `bm_${Date.now()}`
1928
+ }
1929
+ }
1930
+ ]
1931
+ };
1932
+ const message = createInteractiveMessage(text, footer, header, action);
1933
+ return await sendMessage(jid, message);
1934
+ };
1935
+
1936
+ const sendFlagUnflagButton = async (jid, text, flagId, flagCategory, flagText = 'Flag', unflagText = 'Unflag', priority = 'normal', footer = '', header = null) => {
1937
+ const action = {
1938
+ buttons: [
1939
+ {
1940
+ type: 'flag',
1941
+ flag: {
1942
+ displayText: flagText,
1943
+ flagId: flagId || `fl_${Date.now()}`,
1944
+ flagCategory: flagCategory,
1945
+ priority: priority
1946
+ }
1947
+ },
1948
+ {
1949
+ type: 'unflag',
1950
+ unflag: {
1951
+ displayText: unflagText,
1952
+ flagId: flagId || `fl_${Date.now()}`
1953
+ }
1954
+ }
1955
+ ]
1956
+ };
1957
+ const message = createInteractiveMessage(text, footer, header, action);
1958
+ return await sendMessage(jid, message);
1959
+ };
1960
+
1961
+ const sendLockUnlockButton = async (jid, text, lockId, lockType, lockText = 'Lock', unlockText = 'Unlock', duration = 3600, footer = '', header = null) => {
1962
+ const action = {
1963
+ buttons: [
1964
+ {
1965
+ type: 'lock',
1966
+ lock: {
1967
+ displayText: lockText,
1968
+ lockId: lockId || `lk_${Date.now()}`,
1969
+ lockType: lockType,
1970
+ duration: duration
1971
+ }
1972
+ },
1973
+ {
1974
+ type: 'unlock',
1975
+ unlock: {
1976
+ displayText: unlockText,
1977
+ lockId: lockId || `lk_${Date.now()}`
1978
+ }
1979
+ }
1980
+ ]
1981
+ };
1982
+ const message = createInteractiveMessage(text, footer, header, action);
1983
+ return await sendMessage(jid, message);
1984
+ };
1985
+
1986
+ const sendAddressRequestButton = async (jid, body, buttonText = 'Share Address', footer = '', header = null) => {
1987
+ const action = {
1988
+ buttons: [{
1989
+ type: 'address',
1990
+ address: {
1991
+ displayText: buttonText
1992
+ }
1993
+ }]
1994
+ };
1995
+ const message = createInteractiveMessage(body, footer, header, action);
1996
+ return await sendMessage(jid, message);
1997
+ };
1998
+
1999
+ const sendLocationRequestButton = async (jid, body, buttonText = 'Share Location', footer = '', header = null) => {
2000
+ const action = {
2001
+ buttons: [{
2002
+ type: 'location',
2003
+ location: {
2004
+ displayText: buttonText
2005
+ }
2006
+ }]
2007
+ };
2008
+ const message = createInteractiveMessage(body, footer, header, action);
2009
+ return await sendMessage(jid, message);
2010
+ };
2011
+
2012
+ const sendVoiceCallButton = async (jid, body, phoneNumber, buttonText = 'Voice Call', footer = '', header = null) => {
2013
+ const action = {
2014
+ buttons: [{
2015
+ type: 'voice',
2016
+ voice: {
2017
+ displayText: buttonText,
2018
+ phoneNumber: phoneNumber
2019
+ }
2020
+ }]
2021
+ };
2022
+ const message = createInteractiveMessage(body, footer, header, action);
2023
+ return await sendMessage(jid, message);
2024
+ };
2025
+
2026
+ const sendVideoCallButton = async (jid, body, phoneNumber, buttonText = 'Video Call', footer = '', header = null) => {
2027
+ const action = {
2028
+ buttons: [{
2029
+ type: 'video',
2030
+ video: {
2031
+ displayText: buttonText,
2032
+ phoneNumber: phoneNumber
2033
+ }
2034
+ }]
2035
+ };
2036
+ const message = createInteractiveMessage(body, footer, header, action);
2037
+ return await sendMessage(jid, message);
2038
+ };
2039
+
2040
+ const sendImageButton = async (jid, body, imageUrl, buttonText = 'View Image', footer = '', header = null) => {
2041
+ const action = {
2042
+ buttons: [{
2043
+ type: 'image',
2044
+ image: {
2045
+ displayText: buttonText,
2046
+ url: imageUrl
2047
+ }
2048
+ }]
2049
+ };
2050
+ const message = createInteractiveMessage(body, footer, header, action);
2051
+ return await sendMessage(jid, message);
2052
+ };
2053
+
2054
+ const sendDocumentButton = async (jid, body, documentUrl, fileName, buttonText = 'View Document', footer = '', header = null) => {
2055
+ const action = {
2056
+ buttons: [{
2057
+ type: 'document',
2058
+ document: {
2059
+ displayText: buttonText,
2060
+ url: documentUrl,
2061
+ fileName: fileName
2062
+ }
2063
+ }]
2064
+ };
2065
+ const message = createInteractiveMessage(body, footer, header, action);
2066
+ return await sendMessage(jid, message);
2067
+ };
2068
+
2069
+ const sendAudioButton = async (jid, body, audioUrl, buttonText = 'Play Audio', footer = '', header = null) => {
2070
+ const action = {
2071
+ buttons: [{
2072
+ type: 'audio',
2073
+ audio: {
2074
+ displayText: buttonText,
2075
+ url: audioUrl
2076
+ }
2077
+ }]
2078
+ };
2079
+ const message = createInteractiveMessage(body, footer, header, action);
2080
+ return await sendMessage(jid, message);
2081
+ };
2082
+
2083
+ const sendStickerButton = async (jid, body, stickerUrl, buttonText = 'View Sticker', footer = '', header = null) => {
2084
+ const action = {
2085
+ buttons: [{
2086
+ type: 'sticker',
2087
+ sticker: {
2088
+ displayText: buttonText,
2089
+ url: stickerUrl
2090
+ }
2091
+ }]
2092
+ };
2093
+ const message = createInteractiveMessage(body, footer, header, action);
2094
+ return await sendMessage(jid, message);
2095
+ };
2096
+
2097
+ const sendInteractiveNativeFlow = async (jid, body, footer, flowId, flowData = {}, buttonText = 'Continue', header = null) => {
2098
+ const action = {
2099
+ buttons: [{
2100
+ type: 'flow',
2101
+ flow: {
2102
+ flowId: flowId,
2103
+ displayText: buttonText,
2104
+ flowData: flowData
2105
+ }
2106
+ }]
2107
+ };
2108
+ const message = createInteractiveMessage(body, footer, header, action);
2109
+ return await sendMessage(jid, message);
2110
+ };
2111
+
2112
+ const sendCollectShoppingInterest = async (jid, productCategory, buttonText = 'I\'m Interested', footer = '', header = null) => {
2113
+ const action = {
2114
+ buttons: [{
2115
+ type: 'interest',
2116
+ interest: {
2117
+ displayText: buttonText,
2118
+ category: productCategory
2119
+ }
2120
+ }]
2121
+ };
2122
+ const message = createInteractiveMessage(`Are you interested in ${productCategory}?`, footer, header, action);
2123
+ return await sendMessage(jid, message);
2124
+ };
2125
+
2126
+ const sendGetFeedback = async (jid, feedbackType, buttonText = 'Give Feedback', footer = '', header = null) => {
2127
+ const action = {
2128
+ buttons: [{
2129
+ type: 'feedback',
2130
+ feedback: {
2131
+ displayText: buttonText,
2132
+ feedbackType: feedbackType
2133
+ }
2134
+ }]
2135
+ };
2136
+ const message = createInteractiveMessage(`Please provide your feedback on ${feedbackType}`, footer, header, action);
2137
+ return await sendMessage(jid, message);
2138
+ };
2139
+
2140
+ const sendSurveyButton = async (jid, surveyId, surveyQuestion, buttonText = 'Take Survey', footer = '', header = null) => {
2141
+ const action = {
2142
+ buttons: [{
2143
+ type: 'survey',
2144
+ survey: {
2145
+ displayText: buttonText,
2146
+ surveyId: surveyId || `sv_${Date.now()}`,
2147
+ question: surveyQuestion
2148
+ }
2149
+ }]
2150
+ };
2151
+ const message = createInteractiveMessage(surveyQuestion, footer, header, action);
2152
+ return await sendMessage(jid, message);
2153
+ };
2154
+
2155
+ const sendCustomerSupportButton = async (jid, supportTopic, buttonText = 'Contact Support', footer = '', header = null) => {
2156
+ const action = {
2157
+ buttons: [{
2158
+ type: 'support',
2159
+ support: {
2160
+ displayText: buttonText,
2161
+ topic: supportTopic
2162
+ }
2163
+ }]
2164
+ };
2165
+ const message = createInteractiveMessage(`Need help with ${supportTopic}?`, footer, header, action);
2166
+ return await sendMessage(jid, message);
2167
+ };
2168
+
2169
+ const sendReminderButton = async (jid, reminderText, buttonText = 'Set Reminder', footer = '', header = null) => {
2170
+ const action = {
2171
+ buttons: [{
2172
+ type: 'reminder',
2173
+ reminder: {
2174
+ displayText: buttonText,
2175
+ text: reminderText
2176
+ }
2177
+ }]
2178
+ };
2179
+ const message = createInteractiveMessage(`Reminder: ${reminderText}`, footer, header, action);
2180
+ return await sendMessage(jid, message);
2181
+ };
2182
+
2183
+ const sendConfirmButton = async (jid, actionText, buttonText = 'Confirm', footer = '', header = null) => {
2184
+ const action = {
2185
+ buttons: [{
2186
+ type: 'confirm',
2187
+ confirm: {
2188
+ displayText: buttonText,
2189
+ action: actionText
2190
+ }
2191
+ }]
2192
+ };
2193
+ const message = createInteractiveMessage(`Confirm: ${actionText}?`, footer, header, action);
2194
+ return await sendMessage(jid, message);
2195
+ };
2196
+
2197
+ const sendCancelButton = async (jid, actionText, buttonText = 'Cancel', footer = '', header = null) => {
2198
+ const action = {
2199
+ buttons: [{
2200
+ type: 'cancel',
2201
+ cancel: {
2202
+ displayText: buttonText,
2203
+ action: actionText
2204
+ }
2205
+ }]
2206
+ };
2207
+ const message = createInteractiveMessage(`Cancel: ${actionText}?`, footer, header, action);
2208
+ return await sendMessage(jid, message);
2209
+ };
2210
+
2211
+ const sendOrderStatusButton = async (jid, orderId, buttonText = 'Check Status', footer = '', header = null) => {
2212
+ const action = {
2213
+ buttons: [{
2214
+ type: 'orderstatus',
2215
+ orderstatus: {
2216
+ displayText: buttonText,
2217
+ orderId: orderId
2218
+ }
2219
+ }]
2220
+ };
2221
+ const message = createInteractiveMessage(`Check status for order #${orderId}`, footer, header, action);
2222
+ return await sendMessage(jid, message);
2223
+ };
2224
+
2225
+ const sendTrackOrderButton = async (jid, orderId, buttonText = 'Track Order', footer = '', header = null) => {
2226
+ const action = {
2227
+ buttons: [{
2228
+ type: 'track',
2229
+ track: {
2230
+ displayText: buttonText,
2231
+ orderId: orderId
2232
+ }
2233
+ }]
2234
+ };
2235
+ const message = createInteractiveMessage(`Track order #${orderId}`, footer, header, action);
2236
+ return await sendMessage(jid, message);
2237
+ };
2238
+
2239
+ const sendReOrderButton = async (jid, orderId, buttonText = 'Reorder', footer = '', header = null) => {
2240
+ const action = {
2241
+ buttons: [{
2242
+ type: 'reorder',
2243
+ reorder: {
2244
+ displayText: buttonText,
2245
+ orderId: orderId
2246
+ }
2247
+ }]
2248
+ };
2249
+ const message = createInteractiveMessage(`Reorder #${orderId}?`, footer, header, action);
2250
+ return await sendMessage(jid, message);
2251
+ };
2252
+
2253
+ const sendCancelOrderButton = async (jid, orderId, buttonText = 'Cancel Order', footer = '', header = null) => {
2254
+ const action = {
2255
+ buttons: [{
2256
+ type: 'cancelorder',
2257
+ cancelorder: {
2258
+ displayText: buttonText,
2259
+ orderId: orderId
2260
+ }
2261
+ }]
2262
+ };
2263
+ const message = createInteractiveMessage(`Cancel order #${orderId}?`, footer, header, action);
2264
+ return await sendMessage(jid, message);
2265
+ };
2266
+
1263
2267
  registerSocketEndHandler(() => {
1264
2268
  if (!config.userDevicesCache && userDevicesCache.close) {
1265
2269
  userDevicesCache.close();
@@ -1374,92 +2378,58 @@ export const makeMessagesSocket = (config) => {
1374
2378
  sendCatalogMessage,
1375
2379
  sendProductMessage,
1376
2380
  sendCollectionMessage,
1377
- sendMessage: async (jid, content, options = {}) => {
1378
- const userJid = authState.creds.me.id;
1379
- if (typeof content === 'object' &&
1380
- 'disappearingMessagesInChat' in content &&
1381
- typeof content['disappearingMessagesInChat'] !== 'undefined' &&
1382
- isJidGroup(jid)) {
1383
- const { disappearingMessagesInChat } = content;
1384
- const value = typeof disappearingMessagesInChat === 'boolean'
1385
- ? disappearingMessagesInChat
1386
- ? WA_DEFAULT_EPHEMERAL
1387
- : 0
1388
- : disappearingMessagesInChat;
1389
- await groupToggleEphemeral(jid, value);
1390
- }
1391
- else {
1392
- const fullMsg = await generateWAMessage(jid, content, {
1393
- logger,
1394
- userJid,
1395
- getUrlInfo: text => getUrlInfo(text, {
1396
- thumbnailWidth: linkPreviewImageThumbnailWidth,
1397
- fetchOpts: {
1398
- timeout: 3000,
1399
- ...(httpRequestOptions || {})
1400
- },
1401
- logger,
1402
- uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
1403
- }),
1404
- getProfilePicUrl: sock.profilePictureUrl,
1405
- getCallLink: sock.createCallLink,
1406
- upload: waUploadToServer,
1407
- mediaCache: config.mediaCache,
1408
- options: config.options,
1409
- messageId: generateMessageIDV2(sock.user?.id),
1410
- ...options
1411
- });
1412
- const isEventMsg = 'event' in content && !!content.event;
1413
- const isDeleteMsg = 'delete' in content && !!content.delete;
1414
- const isEditMsg = 'edit' in content && !!content.edit;
1415
- const isPinMsg = 'pin' in content && !!content.pin;
1416
- const isPollMessage = 'poll' in content && !!content.poll;
1417
- const additionalAttributes = {};
1418
- const additionalNodes = [];
1419
- if (isDeleteMsg) {
1420
- if (isJidGroup(content.delete?.remoteJid) && !content.delete?.fromMe) {
1421
- additionalAttributes.edit = '8';
1422
- }
1423
- else {
1424
- additionalAttributes.edit = '7';
1425
- }
1426
- }
1427
- else if (isEditMsg) {
1428
- additionalAttributes.edit = '1';
1429
- }
1430
- else if (isPinMsg) {
1431
- additionalAttributes.edit = '2';
1432
- }
1433
- else if (isPollMessage) {
1434
- additionalNodes.push({
1435
- tag: 'meta',
1436
- attrs: {
1437
- polltype: 'creation'
1438
- }
1439
- });
1440
- }
1441
- else if (isEventMsg) {
1442
- additionalNodes.push({
1443
- tag: 'meta',
1444
- attrs: {
1445
- event_type: 'creation'
1446
- }
1447
- });
1448
- }
1449
- await relayMessage(jid, fullMsg.message, {
1450
- messageId: fullMsg.key.id,
1451
- useCachedGroupMetadata: options.useCachedGroupMetadata,
1452
- additionalAttributes,
1453
- statusJidList: options.statusJidList,
1454
- additionalNodes
1455
- });
1456
- if (config.emitOwnEvents) {
1457
- process.nextTick(async () => {
1458
- await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
1459
- });
1460
- }
1461
- return fullMsg;
1462
- }
1463
- }
2381
+ sendMessage,
2382
+ createNativeFlowButton,
2383
+ sendNativeFlow,
2384
+ createCarouselCard,
2385
+ sendCarousel,
2386
+ sendMultiProductMessage,
2387
+ sendSingleProductMessage,
2388
+ sendSectionList,
2389
+ sendReplyButton,
2390
+ sendCTAUrl,
2391
+ sendCTAPhone,
2392
+ sendCopyCodeButton,
2393
+ sendFlowButton,
2394
+ sendOptOutButton,
2395
+ sendOneTapButton,
2396
+ sendZeroTapButton,
2397
+ sendAuthButton,
2398
+ sendOTPButton,
2399
+ sendPaymentButton,
2400
+ sendScheduleButton,
2401
+ sendFeedbackButton,
2402
+ sendShareButton,
2403
+ sendDownloadButton,
2404
+ sendUploadButton,
2405
+ sendVerifyButton,
2406
+ sendApproveRejectButton,
2407
+ sendForwardButton,
2408
+ sendMuteUnmuteButton,
2409
+ sendArchiveUnarchiveButton,
2410
+ sendPinUnpinButton,
2411
+ sendBookmarkButton,
2412
+ sendFlagUnflagButton,
2413
+ sendLockUnlockButton,
2414
+ sendAddressRequestButton,
2415
+ sendLocationRequestButton,
2416
+ sendVoiceCallButton,
2417
+ sendVideoCallButton,
2418
+ sendImageButton,
2419
+ sendDocumentButton,
2420
+ sendAudioButton,
2421
+ sendStickerButton,
2422
+ sendInteractiveNativeFlow,
2423
+ sendCollectShoppingInterest,
2424
+ sendGetFeedback,
2425
+ sendSurveyButton,
2426
+ sendCustomerSupportButton,
2427
+ sendReminderButton,
2428
+ sendConfirmButton,
2429
+ sendCancelButton,
2430
+ sendOrderStatusButton,
2431
+ sendTrackOrderButton,
2432
+ sendReOrderButton,
2433
+ sendCancelOrderButton
1464
2434
  };
1465
2435
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mrlegendbot/baileys",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "description": "A WebSockets library for interacting with WhatsApp Web",
6
6
  "keywords": [
7
7
  "whatsapp",