keithbaileys 1.0.2 → 1.0.6

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.
@@ -135,6 +135,10 @@ const makeChatsSocket = (config) => {
135
135
  }
136
136
  ]
137
137
  });
138
+
139
+
140
+
141
+
138
142
  const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
139
143
  const botList = [];
140
144
  for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
@@ -149,6 +153,28 @@ const makeChatsSocket = (config) => {
149
153
  }
150
154
  return botList;
151
155
  };
156
+
157
+ const createCallLink = async (type, event, timeoutMs) => {
158
+ const result = await query({
159
+ tag: 'call',
160
+ attrs: {
161
+ id: generateMessageTag(),
162
+ to: '@call'
163
+ },
164
+ content: [
165
+ {
166
+ tag: 'link_create',
167
+ attrs: { media: type },
168
+ content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
169
+ }
170
+ ]
171
+ }, timeoutMs);
172
+
173
+ const child = (0, WABinary_1.getBinaryNodeChild)(result, 'link_create');
174
+ return child === null || child === void 0 ? void 0 : child.attrs.token;
175
+ };
176
+
177
+
152
178
  const onWhatsApp = async (...jids) => {
153
179
  const usyncQuery = new WAUSync_1.USyncQuery().withContactProtocol().withLIDProtocol();
154
180
  for (const jid of jids) {
@@ -737,6 +763,52 @@ const makeChatsSocket = (config) => {
737
763
  * queries need to be fired on connection open
738
764
  * help ensure parity with WA Web
739
765
  * */
766
+
767
+
768
+ /**
769
+ * Add or Edit Contact
770
+ */
771
+ const addOrEditContact = (jid, contact) => {
772
+ return chatModify({
773
+ contact
774
+ }, jid);
775
+ };
776
+
777
+ /**
778
+ * Remove Contact
779
+ */
780
+ const removeContact = (jid) => {
781
+ return chatModify({
782
+ contact: null
783
+ }, jid);
784
+ };
785
+
786
+ /**
787
+ * Add or Edit Quick Reply
788
+ */
789
+ const addOrEditQuickReply = (quickReply) => {
790
+ return chatModify({
791
+ quickReply
792
+ }, '');
793
+ };
794
+
795
+ /**
796
+ * Remove Quick Reply
797
+ */
798
+ const removeQuickReply = (timestamp) => {
799
+ return chatModify({
800
+ quickReply: { timestamp, deleted: true }
801
+ }, '');
802
+ };
803
+
804
+ /**
805
+ * Enable/Disable link preview privacy
806
+ */
807
+ const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
808
+ return chatModify({
809
+ disableLinkPreviews: { isPreviewsDisabled }
810
+ }, '');
811
+ };
740
812
  const executeInitQueries = async () => {
741
813
  await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
742
814
  };
@@ -840,6 +912,7 @@ const makeChatsSocket = (config) => {
840
912
  return {
841
913
  ...sock,
842
914
  getBotListV2,
915
+ createCallLink,
843
916
  processingMutex,
844
917
  fetchPrivacySettings,
845
918
  upsertMessage,
@@ -868,6 +941,11 @@ const makeChatsSocket = (config) => {
868
941
  getBusinessProfile,
869
942
  resyncAppState,
870
943
  chatModify,
944
+ addOrEditContact,
945
+ removeContact,
946
+ addOrEditQuickReply,
947
+ removeQuickReply,
948
+ updateDisableLinkPreviewsPrivacy,
871
949
  cleanDirtyBits,
872
950
  addLabel,
873
951
  addChatLabel,
@@ -15,6 +15,7 @@ const WAUSync_1 = require("../WAUSync");
15
15
  const groups_1 = require("./groups");
16
16
  const newsletter_1 = require("./newsletter");
17
17
  const GiftedStatus = require("./gcstatus");
18
+ const crypto_1 = require("crypto");
18
19
 
19
20
  const makeMessagesSocket = (config) => {
20
21
  const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata } = config;
@@ -529,6 +530,9 @@ const makeMessagesSocket = (config) => {
529
530
  else if (message.stickerMessage) {
530
531
  return 'sticker';
531
532
  }
533
+ else if (message.stickerPackMessage) {
534
+ return 'sticker_pack';
535
+ }
532
536
  else if (message.listMessage) {
533
537
  return 'list';
534
538
  }
@@ -604,6 +608,7 @@ const makeMessagesSocket = (config) => {
604
608
  readMessages,
605
609
  refreshMediaConn,
606
610
  waUploadToServer,
611
+ // sendStatusMentions,
607
612
  giftedStatus, // FIXED: Changed from xmdStatus to giftedStatus
608
613
  fetchPrivacySettings,
609
614
  sendPeerDataOperationMessage,
@@ -651,6 +656,158 @@ const makeMessagesSocket = (config) => {
651
656
  ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
652
657
  return message;
653
658
  },
659
+ sendStatusMentions: async (content, jids = []) => {
660
+ const userJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
661
+ let allUsers = new Set();
662
+ allUsers.add(userJid);
663
+
664
+ for (const id of jids) {
665
+ const isGroup = (0, WABinary_1.isJidGroup)(id);
666
+ const isPrivate = (0, WABinary_1.isJidUser)(id);
667
+
668
+ if (isGroup) {
669
+ try {
670
+ const metadata = await cachedGroupMetadata(id) || await groupMetadata(id);
671
+ const participants = metadata.participants.map(p => (0, WABinary_1.jidNormalizedUser)(p.id));
672
+ participants.forEach(jid => allUsers.add(jid));
673
+ } catch (error) {
674
+ logger.error(`Error getting metadata for group ${id}: ${error}`);
675
+ }
676
+ } else if (isPrivate) {
677
+ allUsers.add((0, WABinary_1.jidNormalizedUser)(id));
678
+ }
679
+ }
680
+
681
+ const uniqueUsers = Array.from(allUsers);
682
+ const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0");
683
+
684
+ const isMedia = content.image || content.video || content.audio;
685
+ const isAudio = !!content.audio;
686
+
687
+ const messageContent = { ...content };
688
+
689
+ if (isMedia && !isAudio) {
690
+ if (messageContent.text) {
691
+ messageContent.caption = messageContent.text;
692
+ delete messageContent.text;
693
+ }
694
+ delete messageContent.ptt;
695
+ delete messageContent.font;
696
+ delete messageContent.backgroundColor;
697
+ delete messageContent.textColor;
698
+ }
699
+
700
+ if (isAudio) {
701
+ delete messageContent.text;
702
+ delete messageContent.caption;
703
+ delete messageContent.font;
704
+ delete messageContent.textColor;
705
+ }
706
+
707
+ const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined;
708
+ const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined;
709
+ const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined;
710
+ const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined;
711
+
712
+ let msg;
713
+ let mediaHandle;
714
+ try {
715
+ msg = await (0, Utils_1.generateWAMessage)(WABinary_1.STORIES_JID, messageContent, {
716
+ logger,
717
+ userJid,
718
+ getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
719
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
720
+ fetchOpts: {
721
+ timeout: 3000,
722
+ ...(axiosOptions || {})
723
+ },
724
+ logger,
725
+ uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
726
+ }),
727
+ upload: async (encFilePath, opts) => {
728
+ const up = await waUploadToServer(encFilePath, { ...opts });
729
+ mediaHandle = up.handle;
730
+ return up;
731
+ },
732
+ mediaCache: config.mediaCache,
733
+ options: config.options,
734
+ font,
735
+ textColor,
736
+ backgroundColor,
737
+ ptt
738
+ });
739
+ } catch (error) {
740
+ logger.error(`Error generating message: ${error}`);
741
+ throw error;
742
+ }
743
+
744
+ await relayMessage(WABinary_1.STORIES_JID, msg.message, {
745
+ messageId: msg.key.id,
746
+ statusJidList: uniqueUsers,
747
+ additionalNodes: [
748
+ {
749
+ tag: 'meta',
750
+ attrs: {},
751
+ content: [
752
+ {
753
+ tag: 'mentioned_users',
754
+ attrs: {},
755
+ content: jids.map(jid => ({
756
+ tag: 'to',
757
+ attrs: { jid: (0, WABinary_1.jidNormalizedUser)(jid) }
758
+ }))
759
+ }
760
+ ]
761
+ }
762
+ ]
763
+ });
764
+
765
+ for (const id of jids) {
766
+ try {
767
+ const normalizedId = (0, WABinary_1.jidNormalizedUser)(id);
768
+ const isPrivate = (0, WABinary_1.isJidUser)(normalizedId);
769
+ const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage';
770
+
771
+ const protocolMessage = {
772
+ [type]: {
773
+ message: {
774
+ protocolMessage: {
775
+ key: msg.key,
776
+ type: 25
777
+ }
778
+ }
779
+ },
780
+ messageContextInfo: {
781
+ messageSecret: (0, crypto_1.randomBytes)(32)
782
+ }
783
+ };
784
+
785
+ const statusMsg = await (0, Utils_1.generateWAMessageFromContent)(normalizedId,
786
+ protocolMessage,
787
+ {}
788
+ );
789
+
790
+ await relayMessage(
791
+ normalizedId,
792
+ statusMsg.message,
793
+ {
794
+ additionalNodes: [{
795
+ tag: 'meta',
796
+ attrs: isPrivate ?
797
+ { is_status_mention: 'true' } :
798
+ { is_group_status_mention: 'true' }
799
+ }]
800
+ }
801
+ );
802
+
803
+ await (0, Utils_1.delay)(2000);
804
+ } catch (error) {
805
+ logger.error(`Error sending to ${id}: ${error}`);
806
+ }
807
+ }
808
+
809
+ return msg;
810
+ },
654
811
  sendMessage: async (jid, content, options = {}) => {
655
812
  var _a, _b, _c;
656
813
  const userJid = authState.creds.me.id;
@@ -670,6 +827,31 @@ const makeMessagesSocket = (config) => {
670
827
  else if (typeof content === 'object' && content.groupStatusMessage) {
671
828
  return await giftedStatus.handleGroupStory(content, jid, options.quoted);
672
829
  }
830
+
831
+ else if (typeof content === 'object' && 'album' in content && Array.isArray(content.album)) {
832
+ const albumMsg = await (0, Utils_1.prepareAlbumMessageContent)(jid, content.album, {
833
+ sock: {
834
+ relayMessage: relayMessage,
835
+ waUploadToServer: waUploadToServer
836
+ },
837
+ userJid: userJid,
838
+ ...options
839
+ });
840
+
841
+ for (const media of albumMsg) {
842
+ await (0, Utils_1.delay)(options.delay || 500);
843
+ await relayMessage(jid, media.message, {
844
+ messageId: media.key.id,
845
+ useCachedGroupMetadata: options.useCachedGroupMetadata,
846
+ additionalAttributes: {},
847
+ statusJidList: options.statusJidList,
848
+ additionalNodes: options.additionalNodes
849
+ });
850
+ }
851
+
852
+ return albumMsg;
853
+ }
854
+
673
855
  else {
674
856
  const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
675
857
  logger,
@@ -684,6 +866,7 @@ const makeMessagesSocket = (config) => {
684
866
  uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
685
867
  }),
686
868
  getProfilePicUrl: sock.profilePictureUrl,
869
+ getCallLink: sock.createCallLink,
687
870
  upload: waUploadToServer,
688
871
  mediaCache: config.mediaCache,
689
872
  options: config.options,
@@ -738,4 +921,4 @@ const makeMessagesSocket = (config) => {
738
921
  }
739
922
  };
740
923
  };
741
- exports.makeMessagesSocket = makeMessagesSocket;
924
+ exports.makeMessagesSocket = makeMessagesSocket;