@mrlegendbot/baileys 1.1.1 → 1.2.1

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) {
@@ -504,6 +504,46 @@ export const makeMessagesSocket = (config) => {
504
504
  await sendNode(stanza);
505
505
  return;
506
506
  }
507
+ if (normalizeMessageContent(message)?.richResponseMessage) {
508
+ const richMsg = normalizeMessageContent(message).richResponseMessage;
509
+ const stanza = {
510
+ tag: 'message',
511
+ attrs: {
512
+ to: jid,
513
+ id: msgId,
514
+ type: 'rich_response',
515
+ ...(additionalAttributes || {})
516
+ },
517
+ content: [{
518
+ tag: 'rich_response',
519
+ attrs: {},
520
+ content: [{
521
+ tag: 'unified_response',
522
+ attrs: {},
523
+ content: richMsg.unifiedResponse?.data || ''
524
+ }]
525
+ }]
526
+ };
527
+ if (richMsg.submessages) {
528
+ stanza.content[0].content.push({
529
+ tag: 'submessages',
530
+ attrs: {},
531
+ content: richMsg.submessages.map(sm => ({
532
+ tag: 'submessage',
533
+ attrs: {
534
+ type: sm.messageType?.toString() || '2'
535
+ },
536
+ content: sm.messageText || ''
537
+ }))
538
+ });
539
+ }
540
+ if (richMsg.contextInfo) {
541
+ stanza.content[0].attrs.contextInfo = JSON.stringify(richMsg.contextInfo);
542
+ }
543
+ logger.debug({ msgId }, `sending rich response message to ${jid}`);
544
+ await sendNode(stanza);
545
+ return;
546
+ }
507
547
  if (normalizeMessageContent(message)?.pinInChatMessage || normalizeMessageContent(message)?.reactionMessage) {
508
548
  extraAttrs['decrypt-fail'] = 'hide';
509
549
  }
@@ -763,7 +803,6 @@ export const makeMessagesSocket = (config) => {
763
803
  stanza.attrs.to = destinationJid;
764
804
  }
765
805
  if (shouldIncludeDeviceIdentity) {
766
- ;
767
806
  stanza.content.push({
768
807
  tag: 'device-identity',
769
808
  attrs: {},
@@ -785,7 +824,6 @@ export const makeMessagesSocket = (config) => {
785
824
  };
786
825
  const reportingNode = await getMessageReportingToken(encoded, reportingMessage, reportingKey);
787
826
  if (reportingNode) {
788
- ;
789
827
  stanza.content.push(reportingNode);
790
828
  logger.trace({ jid }, 'added reporting token to message');
791
829
  }
@@ -814,7 +852,6 @@ export const makeMessagesSocket = (config) => {
814
852
  }
815
853
  }
816
854
  if (tcTokenBuffer?.length && sock.serverProps.privacyTokenOn1to1) {
817
- ;
818
855
  stanza.content.push({
819
856
  tag: 'tctoken',
820
857
  attrs: {},
@@ -822,7 +859,6 @@ export const makeMessagesSocket = (config) => {
822
859
  });
823
860
  }
824
861
  if (additionalNodes && additionalNodes.length > 0) {
825
- ;
826
862
  stanza.content.push(...additionalNodes);
827
863
  }
828
864
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
@@ -893,6 +929,9 @@ export const makeMessagesSocket = (config) => {
893
929
  if (normalizedMessage.groupStatusMessage) {
894
930
  return 'group_status';
895
931
  }
932
+ if (normalizedMessage.richResponseMessage) {
933
+ return 'rich_response';
934
+ }
896
935
  if (getMediaType(normalizedMessage) !== '') {
897
936
  return 'media';
898
937
  }
@@ -945,6 +984,9 @@ export const makeMessagesSocket = (config) => {
945
984
  else if (message.groupInviteMessage) {
946
985
  return 'url';
947
986
  }
987
+ else if (message.richResponseMessage) {
988
+ return 'rich_response';
989
+ }
948
990
  else if (message.groupStatusMessage) {
949
991
  if (message.groupStatusMessage.image) return 'image';
950
992
  if (message.groupStatusMessage.video) return 'video';
@@ -1169,7 +1211,43 @@ export const makeMessagesSocket = (config) => {
1169
1211
  reply: btn.reply,
1170
1212
  url: btn.url,
1171
1213
  call: btn.call,
1172
- catalog: btn.catalog
1214
+ catalog: btn.catalog,
1215
+ copy: btn.copy,
1216
+ flow: btn.flow,
1217
+ optout: btn.optout,
1218
+ onetime: btn.onetime,
1219
+ auth: btn.auth,
1220
+ otp: btn.otp,
1221
+ payment: btn.payment,
1222
+ schedule: btn.schedule,
1223
+ feedback: btn.feedback,
1224
+ share: btn.share,
1225
+ download: btn.download,
1226
+ upload: btn.upload,
1227
+ verify: btn.verify,
1228
+ approve: btn.approve,
1229
+ reject: btn.reject,
1230
+ forward: btn.forward,
1231
+ mute: btn.mute,
1232
+ unmute: btn.unmute,
1233
+ archive: btn.archive,
1234
+ unarchive: btn.unarchive,
1235
+ pin: btn.pin,
1236
+ unpin: btn.unpin,
1237
+ bookmark: btn.bookmark,
1238
+ unbookmark: btn.unbookmark,
1239
+ flag: btn.flag,
1240
+ unflag: btn.unflag,
1241
+ lock: btn.lock,
1242
+ unlock: btn.unlock,
1243
+ address: btn.address,
1244
+ location: btn.location,
1245
+ voice: btn.voice,
1246
+ video: btn.video,
1247
+ image: btn.image,
1248
+ document: btn.document,
1249
+ audio: btn.audio,
1250
+ sticker: btn.sticker
1173
1251
  }))
1174
1252
  });
1175
1253
 
@@ -1193,6 +1271,13 @@ export const makeMessagesSocket = (config) => {
1193
1271
  }
1194
1272
  });
1195
1273
 
1274
+ const sendRichResponseMessage = async (jid, richResponseData, options = {}) => {
1275
+ const message = {
1276
+ richResponseMessage: richResponseData
1277
+ };
1278
+ return await sendMessage(jid, message, options);
1279
+ };
1280
+
1196
1281
  const sendMessage = async (jid, content, options = {}) => {
1197
1282
  if (content.groupStatusMessage || content.groupStatus) {
1198
1283
  const statusContent = content.groupStatusMessage || content.groupStatus;
@@ -1409,6 +1494,829 @@ export const makeMessagesSocket = (config) => {
1409
1494
  return await sendMessage(jid, message);
1410
1495
  };
1411
1496
 
1497
+ const createNativeFlowButton = (flowId, displayText, flowData) => ({
1498
+ type: 'flow',
1499
+ flow: {
1500
+ flowId: flowId,
1501
+ displayText: displayText || 'Continue',
1502
+ flowData: flowData || {}
1503
+ }
1504
+ });
1505
+
1506
+ const sendNativeFlow = async (jid, body, footer, flowId, displayText, flowData = {}, header = null) => {
1507
+ const action = {
1508
+ buttons: [{
1509
+ type: 'flow',
1510
+ flow: {
1511
+ flowId: flowId,
1512
+ displayText: displayText || 'Continue',
1513
+ flowData: flowData
1514
+ }
1515
+ }]
1516
+ };
1517
+ const message = createInteractiveMessage(body, footer, header, action);
1518
+ return await sendMessage(jid, message);
1519
+ };
1520
+
1521
+ const createCarouselCard = (cardId, title, subtitle, body, footer, buttons, media = null) => ({
1522
+ cardId: cardId || `card_${Date.now()}`,
1523
+ header: {
1524
+ title: title || '',
1525
+ subtitle: subtitle || '',
1526
+ hasMedia: !!media,
1527
+ media: media || null
1528
+ },
1529
+ body: { text: body || '' },
1530
+ footer: footer ? { text: footer } : undefined,
1531
+ buttons: buttons || []
1532
+ });
1533
+
1534
+ const sendCarousel = async (jid, body, footer, cards, header = null) => {
1535
+ const action = {
1536
+ carousel: {
1537
+ cards: cards.map(card => ({
1538
+ cardId: card.cardId,
1539
+ header: {
1540
+ title: card.header.title,
1541
+ subtitle: card.header.subtitle || '',
1542
+ hasMedia: card.header.hasMedia || false,
1543
+ media: card.header.media || null
1544
+ },
1545
+ body: { text: card.body.text },
1546
+ footer: card.footer || undefined,
1547
+ buttons: card.buttons || []
1548
+ }))
1549
+ }
1550
+ };
1551
+ const message = createInteractiveMessage(body, footer, header, action);
1552
+ return await sendMessage(jid, message);
1553
+ };
1554
+
1555
+ const sendMultiProductMessage = async (jid, businessOwnerJid, catalogId, products, body = 'Browse our products', footer = '', header = null) => {
1556
+ const action = {
1557
+ catalog: {
1558
+ businessOwnerJid: businessOwnerJid,
1559
+ catalogId: catalogId,
1560
+ products: products.map(p => ({
1561
+ productId: p.id,
1562
+ title: p.title,
1563
+ description: p.description || '',
1564
+ price: p.price || '0',
1565
+ currency: p.currency || 'PKR',
1566
+ image: p.image || null
1567
+ }))
1568
+ }
1569
+ };
1570
+ const message = createInteractiveMessage(body, footer, header, action);
1571
+ return await sendMessage(jid, message);
1572
+ };
1573
+
1574
+ const sendSingleProductMessage = async (jid, productId, businessOwnerJid, catalogId) => {
1575
+ const message = {
1576
+ productMessage: {
1577
+ productId: productId,
1578
+ businessOwnerJid: businessOwnerJid,
1579
+ catalogId: catalogId
1580
+ }
1581
+ };
1582
+ return await sendMessage(jid, message);
1583
+ };
1584
+
1585
+ const sendSectionList = async (jid, title, buttonText, sections, body = 'Choose an option', footer = '', header = null) => {
1586
+ const action = {
1587
+ sections: sections.map(section => ({
1588
+ title: section.title,
1589
+ rows: section.rows.map(row => ({
1590
+ id: row.id || `row_${Date.now()}`,
1591
+ title: row.title,
1592
+ description: row.description || ''
1593
+ }))
1594
+ })),
1595
+ button: buttonText || 'Select'
1596
+ };
1597
+ const message = createInteractiveMessage(body, footer, header, action);
1598
+ return await sendMessage(jid, message);
1599
+ };
1600
+
1601
+ const sendReplyButton = async (jid, text, buttonText, buttonId, footer = '', header = null) => {
1602
+ const action = {
1603
+ buttons: [{
1604
+ type: 'reply',
1605
+ reply: {
1606
+ id: buttonId || `reply_${Date.now()}`,
1607
+ title: buttonText
1608
+ }
1609
+ }]
1610
+ };
1611
+ const message = createInteractiveMessage(text, footer, header, action);
1612
+ return await sendMessage(jid, message);
1613
+ };
1614
+
1615
+ const sendCTAUrl = async (jid, text, displayText, url, footer = '', header = null) => {
1616
+ const action = {
1617
+ buttons: [{
1618
+ type: 'url',
1619
+ url: {
1620
+ displayText: displayText,
1621
+ url: url
1622
+ }
1623
+ }]
1624
+ };
1625
+ const message = createInteractiveMessage(text, footer, header, action);
1626
+ return await sendMessage(jid, message);
1627
+ };
1628
+
1629
+ const sendCTAPhone = async (jid, text, displayText, phoneNumber, footer = '', header = null) => {
1630
+ const action = {
1631
+ buttons: [{
1632
+ type: 'call',
1633
+ call: {
1634
+ displayText: displayText,
1635
+ phoneNumber: phoneNumber
1636
+ }
1637
+ }]
1638
+ };
1639
+ const message = createInteractiveMessage(text, footer, header, action);
1640
+ return await sendMessage(jid, message);
1641
+ };
1642
+
1643
+ const sendCopyCodeButton = async (jid, text, code, buttonText = 'Copy Code', footer = '', header = null) => {
1644
+ const action = {
1645
+ buttons: [{
1646
+ type: 'copy',
1647
+ copy: {
1648
+ displayText: buttonText,
1649
+ code: code
1650
+ }
1651
+ }]
1652
+ };
1653
+ const message = createInteractiveMessage(text, footer, header, action);
1654
+ return await sendMessage(jid, message);
1655
+ };
1656
+
1657
+ const sendFlowButton = async (jid, text, flowId, flowData = {}, buttonText = 'Continue', footer = '', header = null) => {
1658
+ const action = {
1659
+ buttons: [{
1660
+ type: 'flow',
1661
+ flow: {
1662
+ flowId: flowId,
1663
+ displayText: buttonText,
1664
+ flowData: flowData
1665
+ }
1666
+ }]
1667
+ };
1668
+ const message = createInteractiveMessage(text, footer, header, action);
1669
+ return await sendMessage(jid, message);
1670
+ };
1671
+
1672
+ const sendOptOutButton = async (jid, text, footer = '', header = null) => {
1673
+ const action = {
1674
+ buttons: [{
1675
+ type: 'optout',
1676
+ optout: {
1677
+ displayText: 'Unsubscribe'
1678
+ }
1679
+ }]
1680
+ };
1681
+ const message = createInteractiveMessage(text, footer, header, action);
1682
+ return await sendMessage(jid, message);
1683
+ };
1684
+
1685
+ const sendOneTapButton = async (jid, text, authCode, buttonText = 'Authenticate', footer = '', header = null) => {
1686
+ const action = {
1687
+ buttons: [{
1688
+ type: 'onetime',
1689
+ onetime: {
1690
+ displayText: buttonText,
1691
+ code: authCode
1692
+ }
1693
+ }]
1694
+ };
1695
+ const message = createInteractiveMessage(text, footer, header, action);
1696
+ return await sendMessage(jid, message);
1697
+ };
1698
+
1699
+ const sendZeroTapButton = async (jid, text, authToken, footer = '', header = null) => {
1700
+ const message = {
1701
+ protocolMessage: {
1702
+ type: proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE,
1703
+ peerDataOperationRequestMessage: {
1704
+ zeroTap: {
1705
+ displayText: text,
1706
+ token: authToken
1707
+ }
1708
+ }
1709
+ }
1710
+ };
1711
+ return await sendMessage(jid, message);
1712
+ };
1713
+
1714
+ const sendAuthButton = async (jid, text, authType, authData, buttonText = 'Authenticate', footer = '', header = null) => {
1715
+ const action = {
1716
+ buttons: [{
1717
+ type: 'auth',
1718
+ auth: {
1719
+ displayText: buttonText,
1720
+ authType: authType,
1721
+ authData: authData
1722
+ }
1723
+ }]
1724
+ };
1725
+ const message = createInteractiveMessage(text, footer, header, action);
1726
+ return await sendMessage(jid, message);
1727
+ };
1728
+
1729
+ const sendOTPButton = async (jid, text, otp, buttonText = 'Verify OTP', footer = '', header = null) => {
1730
+ const action = {
1731
+ buttons: [{
1732
+ type: 'otp',
1733
+ otp: {
1734
+ displayText: buttonText,
1735
+ otp: otp
1736
+ }
1737
+ }]
1738
+ };
1739
+ const message = createInteractiveMessage(text, footer, header, action);
1740
+ return await sendMessage(jid, message);
1741
+ };
1742
+
1743
+ const sendPaymentButton = async (jid, text, amount, currency = 'PKR', paymentId, buttonText = 'Pay Now', footer = '', header = null) => {
1744
+ const action = {
1745
+ buttons: [{
1746
+ type: 'payment',
1747
+ payment: {
1748
+ displayText: buttonText,
1749
+ amount: amount,
1750
+ currency: currency,
1751
+ paymentId: paymentId || `pay_${Date.now()}`
1752
+ }
1753
+ }]
1754
+ };
1755
+ const message = createInteractiveMessage(text, footer, header, action);
1756
+ return await sendMessage(jid, message);
1757
+ };
1758
+
1759
+ const sendScheduleButton = async (jid, text, scheduleId, startTime, endTime, buttonText = 'Schedule', footer = '', header = null) => {
1760
+ const action = {
1761
+ buttons: [{
1762
+ type: 'schedule',
1763
+ schedule: {
1764
+ displayText: buttonText,
1765
+ scheduleId: scheduleId || `sch_${Date.now()}`,
1766
+ startTime: startTime,
1767
+ endTime: endTime
1768
+ }
1769
+ }]
1770
+ };
1771
+ const message = createInteractiveMessage(text, footer, header, action);
1772
+ return await sendMessage(jid, message);
1773
+ };
1774
+
1775
+ const sendFeedbackButton = async (jid, text, feedbackId, ratingType = 'stars', buttonText = 'Give Feedback', footer = '', header = null) => {
1776
+ const action = {
1777
+ buttons: [{
1778
+ type: 'feedback',
1779
+ feedback: {
1780
+ displayText: buttonText,
1781
+ feedbackId: feedbackId || `fb_${Date.now()}`,
1782
+ ratingType: ratingType
1783
+ }
1784
+ }]
1785
+ };
1786
+ const message = createInteractiveMessage(text, footer, header, action);
1787
+ return await sendMessage(jid, message);
1788
+ };
1789
+
1790
+ const sendShareButton = async (jid, text, shareTarget, shareData, buttonText = 'Share', footer = '', header = null) => {
1791
+ const action = {
1792
+ buttons: [{
1793
+ type: 'share',
1794
+ share: {
1795
+ displayText: buttonText,
1796
+ shareTarget: shareTarget,
1797
+ shareData: shareData
1798
+ }
1799
+ }]
1800
+ };
1801
+ const message = createInteractiveMessage(text, footer, header, action);
1802
+ return await sendMessage(jid, message);
1803
+ };
1804
+
1805
+ const sendDownloadButton = async (jid, text, fileId, fileType, fileSize, buttonText = 'Download', footer = '', header = null) => {
1806
+ const action = {
1807
+ buttons: [{
1808
+ type: 'download',
1809
+ download: {
1810
+ displayText: buttonText,
1811
+ fileId: fileId || `dl_${Date.now()}`,
1812
+ fileType: fileType,
1813
+ fileSize: fileSize
1814
+ }
1815
+ }]
1816
+ };
1817
+ const message = createInteractiveMessage(text, footer, header, action);
1818
+ return await sendMessage(jid, message);
1819
+ };
1820
+
1821
+ const sendUploadButton = async (jid, text, uploadType, maxSize, acceptedFormats, buttonText = 'Upload', footer = '', header = null) => {
1822
+ const action = {
1823
+ buttons: [{
1824
+ type: 'upload',
1825
+ upload: {
1826
+ displayText: buttonText,
1827
+ uploadType: uploadType,
1828
+ maxSize: maxSize,
1829
+ acceptedFormats: acceptedFormats
1830
+ }
1831
+ }]
1832
+ };
1833
+ const message = createInteractiveMessage(text, footer, header, action);
1834
+ return await sendMessage(jid, message);
1835
+ };
1836
+
1837
+ const sendVerifyButton = async (jid, text, verifyType, verificationId, buttonText = 'Verify', footer = '', header = null) => {
1838
+ const action = {
1839
+ buttons: [{
1840
+ type: 'verify',
1841
+ verify: {
1842
+ displayText: buttonText,
1843
+ verifyType: verifyType,
1844
+ verificationId: verificationId || `vf_${Date.now()}`
1845
+ }
1846
+ }]
1847
+ };
1848
+ const message = createInteractiveMessage(text, footer, header, action);
1849
+ return await sendMessage(jid, message);
1850
+ };
1851
+
1852
+ const sendApproveRejectButton = async (jid, text, approvalId, approvalType, approveText = 'Approve', rejectText = 'Reject', footer = '', header = null) => {
1853
+ const action = {
1854
+ buttons: [
1855
+ {
1856
+ type: 'approve',
1857
+ approve: {
1858
+ displayText: approveText,
1859
+ approvalId: approvalId || `app_${Date.now()}`,
1860
+ approvalType: approvalType
1861
+ }
1862
+ },
1863
+ {
1864
+ type: 'reject',
1865
+ reject: {
1866
+ displayText: rejectText,
1867
+ approvalId: approvalId || `app_${Date.now()}`,
1868
+ reason: ''
1869
+ }
1870
+ }
1871
+ ]
1872
+ };
1873
+ const message = createInteractiveMessage(text, footer, header, action);
1874
+ return await sendMessage(jid, message);
1875
+ };
1876
+
1877
+ const sendForwardButton = async (jid, text, forwardId, forwardType, buttonText = 'Forward', footer = '', header = null) => {
1878
+ const action = {
1879
+ buttons: [{
1880
+ type: 'forward',
1881
+ forward: {
1882
+ displayText: buttonText,
1883
+ forwardId: forwardId || `fw_${Date.now()}`,
1884
+ forwardType: forwardType
1885
+ }
1886
+ }]
1887
+ };
1888
+ const message = createInteractiveMessage(text, footer, header, action);
1889
+ return await sendMessage(jid, message);
1890
+ };
1891
+
1892
+ const sendMuteUnmuteButton = async (jid, text, conversationId, muteText = 'Mute', unmuteText = 'Unmute', footer = '', header = null) => {
1893
+ const action = {
1894
+ buttons: [
1895
+ {
1896
+ type: 'mute',
1897
+ mute: {
1898
+ displayText: muteText,
1899
+ conversationId: conversationId || `conv_${Date.now()}`,
1900
+ duration: 3600
1901
+ }
1902
+ },
1903
+ {
1904
+ type: 'unmute',
1905
+ unmute: {
1906
+ displayText: unmuteText,
1907
+ conversationId: conversationId || `conv_${Date.now()}`
1908
+ }
1909
+ }
1910
+ ]
1911
+ };
1912
+ const message = createInteractiveMessage(text, footer, header, action);
1913
+ return await sendMessage(jid, message);
1914
+ };
1915
+
1916
+ const sendArchiveUnarchiveButton = async (jid, text, archiveId, archiveType, archiveText = 'Archive', unarchiveText = 'Unarchive', footer = '', header = null) => {
1917
+ const action = {
1918
+ buttons: [
1919
+ {
1920
+ type: 'archive',
1921
+ archive: {
1922
+ displayText: archiveText,
1923
+ archiveId: archiveId || `arch_${Date.now()}`,
1924
+ archiveType: archiveType
1925
+ }
1926
+ },
1927
+ {
1928
+ type: 'unarchive',
1929
+ unarchive: {
1930
+ displayText: unarchiveText,
1931
+ archiveId: archiveId || `arch_${Date.now()}`
1932
+ }
1933
+ }
1934
+ ]
1935
+ };
1936
+ const message = createInteractiveMessage(text, footer, header, action);
1937
+ return await sendMessage(jid, message);
1938
+ };
1939
+
1940
+ const sendPinUnpinButton = async (jid, text, pinId, pinType, pinText = 'Pin', unpinText = 'Unpin', duration = 86400, footer = '', header = null) => {
1941
+ const action = {
1942
+ buttons: [
1943
+ {
1944
+ type: 'pin',
1945
+ pin: {
1946
+ displayText: pinText,
1947
+ pinId: pinId || `pin_${Date.now()}`,
1948
+ pinType: pinType,
1949
+ duration: duration
1950
+ }
1951
+ },
1952
+ {
1953
+ type: 'unpin',
1954
+ unpin: {
1955
+ displayText: unpinText,
1956
+ pinId: pinId || `pin_${Date.now()}`
1957
+ }
1958
+ }
1959
+ ]
1960
+ };
1961
+ const message = createInteractiveMessage(text, footer, header, action);
1962
+ return await sendMessage(jid, message);
1963
+ };
1964
+
1965
+ const sendBookmarkButton = async (jid, text, bookmarkId, bookmarkCategory, bookmarkText = 'Bookmark', unbookmarkText = 'Remove', footer = '', header = null) => {
1966
+ const action = {
1967
+ buttons: [
1968
+ {
1969
+ type: 'bookmark',
1970
+ bookmark: {
1971
+ displayText: bookmarkText,
1972
+ bookmarkId: bookmarkId || `bm_${Date.now()}`,
1973
+ bookmarkCategory: bookmarkCategory
1974
+ }
1975
+ },
1976
+ {
1977
+ type: 'unbookmark',
1978
+ unbookmark: {
1979
+ displayText: unbookmarkText,
1980
+ bookmarkId: bookmarkId || `bm_${Date.now()}`
1981
+ }
1982
+ }
1983
+ ]
1984
+ };
1985
+ const message = createInteractiveMessage(text, footer, header, action);
1986
+ return await sendMessage(jid, message);
1987
+ };
1988
+
1989
+ const sendFlagUnflagButton = async (jid, text, flagId, flagCategory, flagText = 'Flag', unflagText = 'Unflag', priority = 'normal', footer = '', header = null) => {
1990
+ const action = {
1991
+ buttons: [
1992
+ {
1993
+ type: 'flag',
1994
+ flag: {
1995
+ displayText: flagText,
1996
+ flagId: flagId || `fl_${Date.now()}`,
1997
+ flagCategory: flagCategory,
1998
+ priority: priority
1999
+ }
2000
+ },
2001
+ {
2002
+ type: 'unflag',
2003
+ unflag: {
2004
+ displayText: unflagText,
2005
+ flagId: flagId || `fl_${Date.now()}`
2006
+ }
2007
+ }
2008
+ ]
2009
+ };
2010
+ const message = createInteractiveMessage(text, footer, header, action);
2011
+ return await sendMessage(jid, message);
2012
+ };
2013
+
2014
+ const sendLockUnlockButton = async (jid, text, lockId, lockType, lockText = 'Lock', unlockText = 'Unlock', duration = 3600, footer = '', header = null) => {
2015
+ const action = {
2016
+ buttons: [
2017
+ {
2018
+ type: 'lock',
2019
+ lock: {
2020
+ displayText: lockText,
2021
+ lockId: lockId || `lk_${Date.now()}`,
2022
+ lockType: lockType,
2023
+ duration: duration
2024
+ }
2025
+ },
2026
+ {
2027
+ type: 'unlock',
2028
+ unlock: {
2029
+ displayText: unlockText,
2030
+ lockId: lockId || `lk_${Date.now()}`
2031
+ }
2032
+ }
2033
+ ]
2034
+ };
2035
+ const message = createInteractiveMessage(text, footer, header, action);
2036
+ return await sendMessage(jid, message);
2037
+ };
2038
+
2039
+ const sendAddressRequestButton = async (jid, body, buttonText = 'Share Address', footer = '', header = null) => {
2040
+ const action = {
2041
+ buttons: [{
2042
+ type: 'address',
2043
+ address: {
2044
+ displayText: buttonText
2045
+ }
2046
+ }]
2047
+ };
2048
+ const message = createInteractiveMessage(body, footer, header, action);
2049
+ return await sendMessage(jid, message);
2050
+ };
2051
+
2052
+ const sendLocationRequestButton = async (jid, body, buttonText = 'Share Location', footer = '', header = null) => {
2053
+ const action = {
2054
+ buttons: [{
2055
+ type: 'location',
2056
+ location: {
2057
+ displayText: buttonText
2058
+ }
2059
+ }]
2060
+ };
2061
+ const message = createInteractiveMessage(body, footer, header, action);
2062
+ return await sendMessage(jid, message);
2063
+ };
2064
+
2065
+ const sendVoiceCallButton = async (jid, body, phoneNumber, buttonText = 'Voice Call', footer = '', header = null) => {
2066
+ const action = {
2067
+ buttons: [{
2068
+ type: 'voice',
2069
+ voice: {
2070
+ displayText: buttonText,
2071
+ phoneNumber: phoneNumber
2072
+ }
2073
+ }]
2074
+ };
2075
+ const message = createInteractiveMessage(body, footer, header, action);
2076
+ return await sendMessage(jid, message);
2077
+ };
2078
+
2079
+ const sendVideoCallButton = async (jid, body, phoneNumber, buttonText = 'Video Call', footer = '', header = null) => {
2080
+ const action = {
2081
+ buttons: [{
2082
+ type: 'video',
2083
+ video: {
2084
+ displayText: buttonText,
2085
+ phoneNumber: phoneNumber
2086
+ }
2087
+ }]
2088
+ };
2089
+ const message = createInteractiveMessage(body, footer, header, action);
2090
+ return await sendMessage(jid, message);
2091
+ };
2092
+
2093
+ const sendImageButton = async (jid, body, imageUrl, buttonText = 'View Image', footer = '', header = null) => {
2094
+ const action = {
2095
+ buttons: [{
2096
+ type: 'image',
2097
+ image: {
2098
+ displayText: buttonText,
2099
+ url: imageUrl
2100
+ }
2101
+ }]
2102
+ };
2103
+ const message = createInteractiveMessage(body, footer, header, action);
2104
+ return await sendMessage(jid, message);
2105
+ };
2106
+
2107
+ const sendDocumentButton = async (jid, body, documentUrl, fileName, buttonText = 'View Document', footer = '', header = null) => {
2108
+ const action = {
2109
+ buttons: [{
2110
+ type: 'document',
2111
+ document: {
2112
+ displayText: buttonText,
2113
+ url: documentUrl,
2114
+ fileName: fileName
2115
+ }
2116
+ }]
2117
+ };
2118
+ const message = createInteractiveMessage(body, footer, header, action);
2119
+ return await sendMessage(jid, message);
2120
+ };
2121
+
2122
+ const sendAudioButton = async (jid, body, audioUrl, buttonText = 'Play Audio', footer = '', header = null) => {
2123
+ const action = {
2124
+ buttons: [{
2125
+ type: 'audio',
2126
+ audio: {
2127
+ displayText: buttonText,
2128
+ url: audioUrl
2129
+ }
2130
+ }]
2131
+ };
2132
+ const message = createInteractiveMessage(body, footer, header, action);
2133
+ return await sendMessage(jid, message);
2134
+ };
2135
+
2136
+ const sendStickerButton = async (jid, body, stickerUrl, buttonText = 'View Sticker', footer = '', header = null) => {
2137
+ const action = {
2138
+ buttons: [{
2139
+ type: 'sticker',
2140
+ sticker: {
2141
+ displayText: buttonText,
2142
+ url: stickerUrl
2143
+ }
2144
+ }]
2145
+ };
2146
+ const message = createInteractiveMessage(body, footer, header, action);
2147
+ return await sendMessage(jid, message);
2148
+ };
2149
+
2150
+ const sendInteractiveNativeFlow = async (jid, body, footer, flowId, flowData = {}, buttonText = 'Continue', header = null) => {
2151
+ const action = {
2152
+ buttons: [{
2153
+ type: 'flow',
2154
+ flow: {
2155
+ flowId: flowId,
2156
+ displayText: buttonText,
2157
+ flowData: flowData
2158
+ }
2159
+ }]
2160
+ };
2161
+ const message = createInteractiveMessage(body, footer, header, action);
2162
+ return await sendMessage(jid, message);
2163
+ };
2164
+
2165
+ const sendCollectShoppingInterest = async (jid, productCategory, buttonText = 'I\'m Interested', footer = '', header = null) => {
2166
+ const action = {
2167
+ buttons: [{
2168
+ type: 'interest',
2169
+ interest: {
2170
+ displayText: buttonText,
2171
+ category: productCategory
2172
+ }
2173
+ }]
2174
+ };
2175
+ const message = createInteractiveMessage(`Are you interested in ${productCategory}?`, footer, header, action);
2176
+ return await sendMessage(jid, message);
2177
+ };
2178
+
2179
+ const sendGetFeedback = async (jid, feedbackType, buttonText = 'Give Feedback', footer = '', header = null) => {
2180
+ const action = {
2181
+ buttons: [{
2182
+ type: 'feedback',
2183
+ feedback: {
2184
+ displayText: buttonText,
2185
+ feedbackType: feedbackType
2186
+ }
2187
+ }]
2188
+ };
2189
+ const message = createInteractiveMessage(`Please provide your feedback on ${feedbackType}`, footer, header, action);
2190
+ return await sendMessage(jid, message);
2191
+ };
2192
+
2193
+ const sendSurveyButton = async (jid, surveyId, surveyQuestion, buttonText = 'Take Survey', footer = '', header = null) => {
2194
+ const action = {
2195
+ buttons: [{
2196
+ type: 'survey',
2197
+ survey: {
2198
+ displayText: buttonText,
2199
+ surveyId: surveyId || `sv_${Date.now()}`,
2200
+ question: surveyQuestion
2201
+ }
2202
+ }]
2203
+ };
2204
+ const message = createInteractiveMessage(surveyQuestion, footer, header, action);
2205
+ return await sendMessage(jid, message);
2206
+ };
2207
+
2208
+ const sendCustomerSupportButton = async (jid, supportTopic, buttonText = 'Contact Support', footer = '', header = null) => {
2209
+ const action = {
2210
+ buttons: [{
2211
+ type: 'support',
2212
+ support: {
2213
+ displayText: buttonText,
2214
+ topic: supportTopic
2215
+ }
2216
+ }]
2217
+ };
2218
+ const message = createInteractiveMessage(`Need help with ${supportTopic}?`, footer, header, action);
2219
+ return await sendMessage(jid, message);
2220
+ };
2221
+
2222
+ const sendReminderButton = async (jid, reminderText, buttonText = 'Set Reminder', footer = '', header = null) => {
2223
+ const action = {
2224
+ buttons: [{
2225
+ type: 'reminder',
2226
+ reminder: {
2227
+ displayText: buttonText,
2228
+ text: reminderText
2229
+ }
2230
+ }]
2231
+ };
2232
+ const message = createInteractiveMessage(`Reminder: ${reminderText}`, footer, header, action);
2233
+ return await sendMessage(jid, message);
2234
+ };
2235
+
2236
+ const sendConfirmButton = async (jid, actionText, buttonText = 'Confirm', footer = '', header = null) => {
2237
+ const action = {
2238
+ buttons: [{
2239
+ type: 'confirm',
2240
+ confirm: {
2241
+ displayText: buttonText,
2242
+ action: actionText
2243
+ }
2244
+ }]
2245
+ };
2246
+ const message = createInteractiveMessage(`Confirm: ${actionText}?`, footer, header, action);
2247
+ return await sendMessage(jid, message);
2248
+ };
2249
+
2250
+ const sendCancelButton = async (jid, actionText, buttonText = 'Cancel', footer = '', header = null) => {
2251
+ const action = {
2252
+ buttons: [{
2253
+ type: 'cancel',
2254
+ cancel: {
2255
+ displayText: buttonText,
2256
+ action: actionText
2257
+ }
2258
+ }]
2259
+ };
2260
+ const message = createInteractiveMessage(`Cancel: ${actionText}?`, footer, header, action);
2261
+ return await sendMessage(jid, message);
2262
+ };
2263
+
2264
+ const sendOrderStatusButton = async (jid, orderId, buttonText = 'Check Status', footer = '', header = null) => {
2265
+ const action = {
2266
+ buttons: [{
2267
+ type: 'orderstatus',
2268
+ orderstatus: {
2269
+ displayText: buttonText,
2270
+ orderId: orderId
2271
+ }
2272
+ }]
2273
+ };
2274
+ const message = createInteractiveMessage(`Check status for order #${orderId}`, footer, header, action);
2275
+ return await sendMessage(jid, message);
2276
+ };
2277
+
2278
+ const sendTrackOrderButton = async (jid, orderId, buttonText = 'Track Order', footer = '', header = null) => {
2279
+ const action = {
2280
+ buttons: [{
2281
+ type: 'track',
2282
+ track: {
2283
+ displayText: buttonText,
2284
+ orderId: orderId
2285
+ }
2286
+ }]
2287
+ };
2288
+ const message = createInteractiveMessage(`Track order #${orderId}`, footer, header, action);
2289
+ return await sendMessage(jid, message);
2290
+ };
2291
+
2292
+ const sendReOrderButton = async (jid, orderId, buttonText = 'Reorder', footer = '', header = null) => {
2293
+ const action = {
2294
+ buttons: [{
2295
+ type: 'reorder',
2296
+ reorder: {
2297
+ displayText: buttonText,
2298
+ orderId: orderId
2299
+ }
2300
+ }]
2301
+ };
2302
+ const message = createInteractiveMessage(`Reorder #${orderId}?`, footer, header, action);
2303
+ return await sendMessage(jid, message);
2304
+ };
2305
+
2306
+ const sendCancelOrderButton = async (jid, orderId, buttonText = 'Cancel Order', footer = '', header = null) => {
2307
+ const action = {
2308
+ buttons: [{
2309
+ type: 'cancelorder',
2310
+ cancelorder: {
2311
+ displayText: buttonText,
2312
+ orderId: orderId
2313
+ }
2314
+ }]
2315
+ };
2316
+ const message = createInteractiveMessage(`Cancel order #${orderId}?`, footer, header, action);
2317
+ return await sendMessage(jid, message);
2318
+ };
2319
+
1412
2320
  registerSocketEndHandler(() => {
1413
2321
  if (!config.userDevicesCache && userDevicesCache.close) {
1414
2322
  userDevicesCache.close();
@@ -1523,6 +2431,59 @@ export const makeMessagesSocket = (config) => {
1523
2431
  sendCatalogMessage,
1524
2432
  sendProductMessage,
1525
2433
  sendCollectionMessage,
1526
- sendMessage
2434
+ sendMessage,
2435
+ sendRichResponseMessage,
2436
+ createNativeFlowButton,
2437
+ sendNativeFlow,
2438
+ createCarouselCard,
2439
+ sendCarousel,
2440
+ sendMultiProductMessage,
2441
+ sendSingleProductMessage,
2442
+ sendSectionList,
2443
+ sendReplyButton,
2444
+ sendCTAUrl,
2445
+ sendCTAPhone,
2446
+ sendCopyCodeButton,
2447
+ sendFlowButton,
2448
+ sendOptOutButton,
2449
+ sendOneTapButton,
2450
+ sendZeroTapButton,
2451
+ sendAuthButton,
2452
+ sendOTPButton,
2453
+ sendPaymentButton,
2454
+ sendScheduleButton,
2455
+ sendFeedbackButton,
2456
+ sendShareButton,
2457
+ sendDownloadButton,
2458
+ sendUploadButton,
2459
+ sendVerifyButton,
2460
+ sendApproveRejectButton,
2461
+ sendForwardButton,
2462
+ sendMuteUnmuteButton,
2463
+ sendArchiveUnarchiveButton,
2464
+ sendPinUnpinButton,
2465
+ sendBookmarkButton,
2466
+ sendFlagUnflagButton,
2467
+ sendLockUnlockButton,
2468
+ sendAddressRequestButton,
2469
+ sendLocationRequestButton,
2470
+ sendVoiceCallButton,
2471
+ sendVideoCallButton,
2472
+ sendImageButton,
2473
+ sendDocumentButton,
2474
+ sendAudioButton,
2475
+ sendStickerButton,
2476
+ sendInteractiveNativeFlow,
2477
+ sendCollectShoppingInterest,
2478
+ sendGetFeedback,
2479
+ sendSurveyButton,
2480
+ sendCustomerSupportButton,
2481
+ sendReminderButton,
2482
+ sendConfirmButton,
2483
+ sendCancelButton,
2484
+ sendOrderStatusButton,
2485
+ sendTrackOrderButton,
2486
+ sendReOrderButton,
2487
+ sendCancelOrderButton
1527
2488
  };
1528
2489
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mrlegendbot/baileys",
3
3
  "type": "module",
4
- "version": "1.1.1",
4
+ "version": "1.2.1",
5
5
  "description": "A WebSockets library for interacting with WhatsApp Web",
6
6
  "keywords": [
7
7
  "whatsapp",