@jkt48connect-corp/baileys 7.2.7 → 7.2.9

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.
Files changed (118) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +838 -94
  3. package/WAProto/WAProto.proto +969 -88
  4. package/WAProto/index.js +124901 -74525
  5. package/lib/Defaults/baileys-version.json +1 -1
  6. package/lib/Defaults/index.js +5 -3
  7. package/lib/Defaults/phonenumber-mcc.json +221 -221
  8. package/lib/Signal/libsignal.js +18 -9
  9. package/lib/Socket/groups.js +1 -1
  10. package/lib/Socket/messages-recv.js +310 -151
  11. package/lib/Socket/messages-send.js +269 -36
  12. package/lib/Socket/newsletter.js +3 -3
  13. package/lib/Socket/registration.js +7 -7
  14. package/lib/Socket/socket.js +7 -3
  15. package/lib/Store/make-in-memory-store.js +13 -11
  16. package/lib/Types/Label.js +1 -1
  17. package/lib/Types/LabelAssociation.js +1 -1
  18. package/lib/Types/Newsletter.js +3 -3
  19. package/lib/Types/index.js +1 -1
  20. package/lib/Utils/auth-utils.js +3 -3
  21. package/lib/Utils/business.js +2 -2
  22. package/lib/Utils/chat-utils.js +41 -20
  23. package/lib/Utils/crypto.js +35 -23
  24. package/lib/Utils/decode-wa-message.js +43 -15
  25. package/lib/Utils/generics.js +32 -16
  26. package/lib/Utils/history.js +3 -0
  27. package/lib/Utils/index.js +0 -1
  28. package/lib/Utils/messages-media.js +38 -47
  29. package/lib/Utils/messages.js +430 -12
  30. package/lib/Utils/process-message.js +2 -2
  31. package/lib/Utils/use-multi-file-auth-state.js +17 -3
  32. package/lib/Utils/validate-connection.js +12 -23
  33. package/lib/WABinary/decode.js +17 -7
  34. package/lib/WABinary/encode.js +33 -17
  35. package/lib/WABinary/generic-utils.js +2 -2
  36. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  37. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  38. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  39. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  40. package/lib/WAUSync/Protocols/index.js +20 -0
  41. package/lib/WAUSync/USyncQuery.js +79 -0
  42. package/lib/WAUSync/USyncUser.js +22 -0
  43. package/lib/WAUSync/index.js +19 -0
  44. package/lib/index.js +4 -1
  45. package/package.json +15 -10
  46. package/WAProto/index.d.ts +0 -37016
  47. package/lib/Defaults/index.d.ts +0 -283
  48. package/lib/Signal/libsignal.d.ts +0 -3
  49. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  50. package/lib/Socket/Client/index.d.ts +0 -3
  51. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  52. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  53. package/lib/Socket/business.d.ts +0 -170
  54. package/lib/Socket/chats.d.ts +0 -80
  55. package/lib/Socket/community.d.ts +0 -219
  56. package/lib/Socket/community.js +0 -354
  57. package/lib/Socket/groups.d.ts +0 -114
  58. package/lib/Socket/index.d.ts +0 -172
  59. package/lib/Socket/messages-recv.d.ts +0 -158
  60. package/lib/Socket/messages-send.d.ts +0 -147
  61. package/lib/Socket/newsletter.d.ts +0 -133
  62. package/lib/Socket/registration.d.ts +0 -267
  63. package/lib/Socket/socket.d.ts +0 -43
  64. package/lib/Store/index.d.ts +0 -3
  65. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  66. package/lib/Store/make-in-memory-store.d.ts +0 -118
  67. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  68. package/lib/Store/object-repository.d.ts +0 -10
  69. package/lib/Types/Auth.d.ts +0 -110
  70. package/lib/Types/Call.d.ts +0 -13
  71. package/lib/Types/Chat.d.ts +0 -102
  72. package/lib/Types/Contact.d.ts +0 -19
  73. package/lib/Types/Events.d.ts +0 -157
  74. package/lib/Types/GroupMetadata.d.ts +0 -54
  75. package/lib/Types/Label.d.ts +0 -35
  76. package/lib/Types/LabelAssociation.d.ts +0 -29
  77. package/lib/Types/Message.d.ts +0 -273
  78. package/lib/Types/Newsletter.d.ts +0 -92
  79. package/lib/Types/Product.d.ts +0 -78
  80. package/lib/Types/Signal.d.ts +0 -57
  81. package/lib/Types/Socket.d.ts +0 -111
  82. package/lib/Types/State.d.ts +0 -27
  83. package/lib/Types/index.d.ts +0 -57
  84. package/lib/Utils/auth-utils.d.ts +0 -18
  85. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  86. package/lib/Utils/business.d.ts +0 -22
  87. package/lib/Utils/chat-utils.d.ts +0 -71
  88. package/lib/Utils/crypto.d.ts +0 -41
  89. package/lib/Utils/decode-wa-message.d.ts +0 -19
  90. package/lib/Utils/event-buffer.d.ts +0 -35
  91. package/lib/Utils/generics.d.ts +0 -97
  92. package/lib/Utils/history.d.ts +0 -15
  93. package/lib/Utils/index.d.ts +0 -18
  94. package/lib/Utils/link-preview.d.ts +0 -21
  95. package/lib/Utils/logger.d.ts +0 -4
  96. package/lib/Utils/lt-hash.d.ts +0 -12
  97. package/lib/Utils/make-mutex.d.ts +0 -7
  98. package/lib/Utils/messages-media.d.ts +0 -116
  99. package/lib/Utils/messages.d.ts +0 -77
  100. package/lib/Utils/noise-handler.d.ts +0 -21
  101. package/lib/Utils/process-message.d.ts +0 -41
  102. package/lib/Utils/signal.d.ts +0 -32
  103. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  104. package/lib/Utils/use-single-file-auth-statev2.d.ts +0 -12
  105. package/lib/Utils/use-single-file-auth-statev2.js +0 -75
  106. package/lib/Utils/validate-connection.d.ts +0 -11
  107. package/lib/WABinary/constants.d.ts +0 -27
  108. package/lib/WABinary/decode.d.ts +0 -7
  109. package/lib/WABinary/encode.d.ts +0 -3
  110. package/lib/WABinary/generic-utils.d.ts +0 -15
  111. package/lib/WABinary/index.d.ts +0 -5
  112. package/lib/WABinary/jid-utils.d.ts +0 -31
  113. package/lib/WABinary/types.d.ts +0 -18
  114. package/lib/WAM/BinaryInfo.d.ts +0 -17
  115. package/lib/WAM/constants.d.ts +0 -38
  116. package/lib/WAM/encode.d.ts +0 -3
  117. package/lib/WAM/index.d.ts +0 -3
  118. package/lib/index.d.ts +0 -11
@@ -18,7 +18,7 @@ const makeMessagesSocket = (config) => {
18
18
  const sock = (0, newsletter_1.makeNewsletterSocket)(config);
19
19
  const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupToggleEphemeral } = sock;
20
20
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
21
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
21
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
22
22
  useClones: false
23
23
  });
24
24
  let mediaConn;
@@ -222,6 +222,28 @@ const makeMessagesSocket = (config) => {
222
222
  }
223
223
  return didFetchNewSession;
224
224
  };
225
+ const sendPeerDataOperationMessage = async (pdoMessage) => {
226
+ var _a;
227
+ //TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
228
+ if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
229
+ throw new boom_1.Boom('Not authenticated');
230
+ }
231
+ const protocolMessage = {
232
+ protocolMessage: {
233
+ peerDataOperationRequestMessage: pdoMessage,
234
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
235
+ }
236
+ };
237
+ const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
238
+ const msgId = await relayMessage(meJid, protocolMessage, {
239
+ additionalAttributes: {
240
+ category: 'peer',
241
+ // eslint-disable-next-line camelcase
242
+ push_priority: 'high_force',
243
+ },
244
+ });
245
+ return msgId;
246
+ };
225
247
  const createParticipantNodes = async (jids, message, extraAttrs) => {
226
248
  const patched = await patchMessageBeforeSending(message, jids);
227
249
  const bytes = (0, Utils_1.encodeWAMessage)(patched);
@@ -257,6 +279,7 @@ const makeMessagesSocket = (config) => {
257
279
  const isGroup = server === 'g.us';
258
280
  const isStatus = jid === statusJid;
259
281
  const isLid = server === 'lid';
282
+ const isPrivate = server === 's.whatsapp.net';
260
283
  const isNewsletter = server === 'newsletter';
261
284
  msgId = msgId || (0, Utils_1.generateMessageID)();
262
285
  useUserDevicesCache = useUserDevicesCache !== false;
@@ -311,7 +334,7 @@ const makeMessagesSocket = (config) => {
311
334
  const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
312
335
  devices.push(...additionalDevices);
313
336
  }
314
- const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
337
+ const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net', d.device)));
315
338
  const bytes = (0, Utils_1.encodeWAMessage)(patched);
316
339
  const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
317
340
  group: destinationJid,
@@ -385,7 +408,7 @@ const makeMessagesSocket = (config) => {
385
408
  const otherJids = [];
386
409
  for (const { user, device } of devices) {
387
410
  const isMe = user === meUser;
388
- const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_f = (_e = authState.creds) === null || _e === void 0 ? void 0 : _e.me) === null || _f === void 0 ? void 0 : _f.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
411
+ const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_f = (_e = authState.creds) === null || _e === void 0 ? void 0 : _e.me) === null || _f === void 0 ? void 0 : _f.lid.split(':')[0]) || user : user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net', device);
389
412
  if (isMe) {
390
413
  meJids.push(jid);
391
414
  }
@@ -449,26 +472,49 @@ const makeMessagesSocket = (config) => {
449
472
  if (additionalNodes && additionalNodes.length > 0) {
450
473
  stanza.content.push(...additionalNodes);
451
474
  }
452
- else {
453
- if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && ((message === null || message === void 0 ? void 0 : message.viewOnceMessage) ? message === null || message === void 0 ? void 0 : message.viewOnceMessage : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2 : (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) ? message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension : (message === null || message === void 0 ? void 0 : message.ephemeralMessage) ? message === null || message === void 0 ? void 0 : message.ephemeralMessage : (message === null || message === void 0 ? void 0 : message.templateMessage) ? message === null || message === void 0 ? void 0 : message.templateMessage : (message === null || message === void 0 ? void 0 : message.interactiveMessage) ? message === null || message === void 0 ? void 0 : message.interactiveMessage : message === null || message === void 0 ? void 0 : message.buttonsMessage)) {
454
- stanza.content.push({
455
- tag: 'biz',
456
- attrs: {},
457
- content: [{
458
- tag: 'interactive',
459
- attrs: {
460
- type: 'native_flow',
461
- v: '1'
462
- },
463
- content: [{
464
- tag: 'native_flow',
465
- attrs: { name: 'quick_reply' }
466
- }]
467
- }]
468
- });
475
+ const inMsg = (0, Utils_1.normalizeMessageContent)(message) || null;
476
+ const key = inMsg ? (0, Utils_1.getContentType)(inMsg) : null;
477
+ if (!isNewsletter && (key === 'interactiveMessage' || key === 'buttonsMessage')) {
478
+ const nativeNode = {
479
+ tag: 'biz',
480
+ attrs: {},
481
+ content: [{
482
+ tag: 'interactive',
483
+ attrs: {
484
+ type: 'native_flow',
485
+ v: '1'
486
+ },
487
+ content: [{
488
+ tag: 'native_flow',
489
+ attrs: {
490
+ name: 'quick_reply',
491
+ }
492
+ }]
493
+ }]
494
+ };
495
+ const resultNativeNode = filterNativeNode(additionalNodes);
496
+ if (resultNativeNode && additionalNodes && additionalNodes.length > 0) {
497
+ stanza.content.push(...resultNativeNode);
498
+ }
499
+ else {
500
+ stanza.content.push(nativeNode);
501
+ }
502
+ }
503
+ if (isPrivate) {
504
+ const botNode = {
505
+ tag: 'bot',
506
+ attrs: { biz_bot: '1' }
507
+ };
508
+ const resultBotNode = filterBotNode(additionalNodes);
509
+ if (resultBotNode && additionalNodes && additionalNodes.length > 0) {
510
+ stanza.content.push(...resultBotNode);
511
+ }
512
+ else {
513
+ stanza.content.push(botNode);
469
514
  }
470
515
  }
471
- const buttonType = getButtonType(message);
516
+ const Msg = (0, Utils_1.normalizeMessageContent)(message) || null;
517
+ const buttonType = getButtonType(Msg);
472
518
  if (buttonType) {
473
519
  stanza.content.push({
474
520
  tag: 'biz',
@@ -487,6 +533,32 @@ const makeMessagesSocket = (config) => {
487
533
  });
488
534
  return msgId;
489
535
  };
536
+ const filterNativeNode = (nodeContent) => {
537
+ if (Array.isArray(nodeContent)) {
538
+ return nodeContent.filter((item) => {
539
+ if (item.tag === 'biz' && (item.content && item.content.filter((tag) => { tag.tag === 'interactive' && tag.attrs.type === 'native_flow' && tag.attrs.v === '1'; }))) {
540
+ return false;
541
+ }
542
+ return true;
543
+ });
544
+ }
545
+ else {
546
+ return nodeContent;
547
+ }
548
+ };
549
+ const filterBotNode = (nodeContent) => {
550
+ if (Array.isArray(nodeContent)) {
551
+ return nodeContent.filter((item) => {
552
+ if (item.tag === 'bot' && item.attrs.biz_bot === '1') {
553
+ return false;
554
+ }
555
+ return true;
556
+ });
557
+ }
558
+ else {
559
+ return nodeContent;
560
+ }
561
+ };
490
562
  const getTypeMessage = (msg) => {
491
563
  if (msg.viewOnceMessage) {
492
564
  return getTypeMessage(msg.viewOnceMessage.message);
@@ -507,7 +579,7 @@ const makeMessagesSocket = (config) => {
507
579
  return 'reaction';
508
580
  }
509
581
  else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
510
- return 'reaction';
582
+ return 'poll';
511
583
  }
512
584
  else if (getMediaType(msg)) {
513
585
  return 'media';
@@ -559,18 +631,12 @@ const makeMessagesSocket = (config) => {
559
631
  else if (message.interactiveResponseMessage) {
560
632
  return 'native_flow_response';
561
633
  }
634
+ else if (message.groupInviteMessage) {
635
+ return 'url';
636
+ }
562
637
  };
563
638
  const getButtonType = (message) => {
564
- if (message.buttonsMessage) {
565
- return 'buttons';
566
- }
567
- else if (message.buttonsResponseMessage) {
568
- return 'buttons_response';
569
- }
570
- else if (message.interactiveResponseMessage) {
571
- return 'interactive_response';
572
- }
573
- else if (message.listMessage) {
639
+ if (message.listMessage) {
574
640
  return 'list';
575
641
  }
576
642
  else if (message.listResponseMessage) {
@@ -632,6 +698,7 @@ const makeMessagesSocket = (config) => {
632
698
  readMessages,
633
699
  refreshMediaConn,
634
700
  getUSyncDevices,
701
+ sendPeerDataOperationMessage,
635
702
  createParticipantNodes,
636
703
  waUploadToServer,
637
704
  fetchPrivacySettings,
@@ -652,7 +719,7 @@ const makeMessagesSocket = (config) => {
652
719
  else {
653
720
  try {
654
721
  const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
655
- if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
722
+ if (media && media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
656
723
  const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
657
724
  throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
658
725
  }
@@ -676,6 +743,163 @@ const makeMessagesSocket = (config) => {
676
743
  ]);
677
744
  return message;
678
745
  },
746
+ sendStatusMentions: async (content, jids = []) => {
747
+ const userJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
748
+ let allUsers = [];
749
+ for (const id of jids) {
750
+ const { user, server } = (0, WABinary_1.jidDecode)(id);
751
+ const isGroup = server === 'g.us';
752
+ const isPrivate = server === 's.whatsapp.net';
753
+ if (isGroup) {
754
+ let userId = await groupMetadata(id);
755
+ let participant = await userId.participants;
756
+ let users = await Promise.all(participant.map(u => (0, WABinary_1.jidNormalizedUser)(u.id)));
757
+ allUsers = [...allUsers, ...users];
758
+ }
759
+ else if (isPrivate) {
760
+ let users = await Promise.all(jids.map(id => id.replace(/\b\d{18}@.{4}\b/g, '')));
761
+ allUsers = [...allUsers, ...users];
762
+ }
763
+ if (!allUsers.find(user => user.includes(userJid))) {
764
+ allUsers.push(userJid);
765
+ }
766
+ }
767
+ ;
768
+ const getRandomHexColor = () => {
769
+ return "#" + Math.floor(Math.random() * 16777215)
770
+ .toString(16)
771
+ .padStart(6, "0");
772
+ };
773
+ let mediaHandle;
774
+ let msg = await (0, Utils_1.generateWAMessage)(WABinary_1.STORIES_JID, content, {
775
+ logger,
776
+ userJid,
777
+ getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
778
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
779
+ fetchOpts: {
780
+ timeout: 3000,
781
+ ...axiosOptions || {}
782
+ },
783
+ logger,
784
+ uploadImage: generateHighQualityLinkPreview
785
+ ? waUploadToServer
786
+ : undefined
787
+ }),
788
+ upload: async (readStream, opts) => {
789
+ const up = await waUploadToServer(readStream, { ...opts });
790
+ mediaHandle = up.handle;
791
+ return up;
792
+ },
793
+ mediaCache: config.mediaCache,
794
+ options: config.options,
795
+ backgroundColor: getRandomHexColor(),
796
+ font: Math.floor(Math.random() * 9),
797
+ });
798
+ await relayMessage(WABinary_1.STORIES_JID, msg.message, {
799
+ messageId: msg.key.id,
800
+ statusJidList: allUsers,
801
+ additionalNodes: [
802
+ {
803
+ tag: 'meta',
804
+ attrs: {},
805
+ content: [
806
+ {
807
+ tag: 'mentioned_users',
808
+ attrs: {},
809
+ content: jids.map(jid => ({
810
+ tag: 'to',
811
+ attrs: { jid },
812
+ content: undefined,
813
+ })),
814
+ },
815
+ ],
816
+ },
817
+ ],
818
+ });
819
+ jids.forEach(async (id) => {
820
+ id = (0, WABinary_1.jidNormalizedUser)(id);
821
+ const { user, server } = (0, WABinary_1.jidDecode)(id);
822
+ const isPrivate = server === 's.whatsapp.net';
823
+ let type = isPrivate
824
+ ? 'statusMentionMessage'
825
+ : 'groupStatusMentionMessage';
826
+ await relayMessage(id, {
827
+ [type]: {
828
+ message: {
829
+ protocolMessage: {
830
+ key: msg.key,
831
+ type: 25,
832
+ },
833
+ },
834
+ },
835
+ }, {});
836
+ await (0, Utils_1.delay)(2500);
837
+ });
838
+ return msg;
839
+ },
840
+ sendAlbumMessage: async (jid, medias, options = {}) => {
841
+ const userJid = authState.creds.me.id;
842
+ for (const media of medias) {
843
+ if (!media.image && !media.video)
844
+ throw new TypeError(`medias[i] must have image or video property`);
845
+ }
846
+ if (medias.length < 2)
847
+ throw new RangeError("Minimum 2 media");
848
+ const time = options.delay || 500;
849
+ delete options.delay;
850
+ const album = await (0, Utils_1.generateWAMessageFromContent)(jid, {
851
+ albumMessage: {
852
+ expectedImageCount: medias.filter(media => media.image).length,
853
+ expectedVideoCount: medias.filter(media => media.video).length,
854
+ ...options
855
+ }
856
+ }, { userJid, ...options });
857
+ await relayMessage(jid, album.message, { messageId: album.key.id });
858
+ for (const i in medias) {
859
+ const media = medias[i];
860
+ let mediaHandle;
861
+ let msg;
862
+ if (media.image) {
863
+ msg = await (0, Utils_1.generateWAMessage)(jid, {
864
+ image: media.image,
865
+ ...media,
866
+ ...options
867
+ }, {
868
+ userJid,
869
+ upload: async (readStream, opts) => {
870
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsLetter)(jid) });
871
+ mediaHandle = up.handle;
872
+ return up;
873
+ },
874
+ ...options,
875
+ });
876
+ }
877
+ else if (media.video) {
878
+ msg = await (0, Utils_1.generateWAMessage)(jid, {
879
+ video: media.video,
880
+ ...media,
881
+ ...options
882
+ }, {
883
+ userJid,
884
+ upload: async (readStream, opts) => {
885
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsLetter)(jid) });
886
+ mediaHandle = up.handle;
887
+ return up;
888
+ },
889
+ ...options,
890
+ });
891
+ }
892
+ msg.message.messageContextInfo = {
893
+ messageAssociation: {
894
+ associationType: 1,
895
+ parentMessageKey: album.key
896
+ }
897
+ };
898
+ await relayMessage(jid, msg.message, { messageId: msg.key.id });
899
+ await (0, Utils_1.delay)(time);
900
+ }
901
+ return album;
902
+ },
679
903
  sendMessage: async (jid, content, options = {}) => {
680
904
  var _a, _b;
681
905
  const userJid = authState.creds.me.id;
@@ -714,9 +938,12 @@ const makeMessagesSocket = (config) => {
714
938
  options: config.options,
715
939
  ...options,
716
940
  });
717
- const isDeleteMsg = 'delete' in content && !!content.delete;
718
- const isEditMsg = 'edit' in content && !!content.edit;
719
941
  const isAiMsg = 'ai' in content && !!content.ai;
942
+ const isPinMsg = 'pin' in content && !!content.pin;
943
+ const isKeepMsg = 'keep' in content && content.keep;
944
+ const isPollMsg = 'poll' in content && !!content.poll;
945
+ const isEditMsg = 'edit' in content && !!content.edit;
946
+ const isDeleteMsg = 'delete' in content && !!content.delete;
720
947
  const additionalAttributes = {};
721
948
  const additionalNodes = [];
722
949
  // required for delete
@@ -732,13 +959,19 @@ const makeMessagesSocket = (config) => {
732
959
  else if (isEditMsg) {
733
960
  additionalAttributes.edit = (0, WABinary_1.isJidNewsLetter)(jid) ? '3' : '1';
734
961
  }
962
+ else if (isPinMsg) {
963
+ additionalAttributes.edit = '2';
964
+ }
735
965
  else if (isAiMsg) {
736
966
  additionalNodes.push({
737
967
  attrs: {
738
968
  biz_bot: '1'
739
969
  },
740
- tag: "bot"
970
+ tag: 'bot'
741
971
  });
972
+ if (options.additionalNodes) {
973
+ additionalNodes.push(...options.additionalNodes);
974
+ }
742
975
  }
743
976
  if (mediaHandle) {
744
977
  additionalAttributes['media_id'] = mediaHandle;
@@ -115,9 +115,9 @@ const makeNewsletterSocket = (config) => {
115
115
  await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
116
116
  },
117
117
  newsletterAction: async (jid, type) => {
118
- await newsletterWMexQuery(jid, type.toUpperCase());
118
+ await newsletterWMexQuery(jid, Types_1.QueryIds[type.toUpperCase()]);
119
119
  },
120
- newsletterCreate: async (name, description, reaction_codes) => {
120
+ newsletterCreate: async (name, description) => {
121
121
  //TODO: Implement TOS system wide for Meta AI, communities, and here etc.
122
122
  /**tos query */
123
123
  await query({
@@ -140,7 +140,7 @@ const makeNewsletterSocket = (config) => {
140
140
  ]
141
141
  });
142
142
  const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
143
- input: { name, description, settings: { 'reaction_codes': { value: reaction_codes.toUpperCase() } } }
143
+ input: { name, description, settings: null }
144
144
  });
145
145
  return (0, exports.extractNewsletterMetadata)(result, true);
146
146
  },
@@ -3,7 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mobileRegisterFetch = exports.mobileRegisterEncrypt = exports.mobileRegister = exports.mobileRegisterExists = exports.mobileRegisterCode = exports.registrationParams = exports.makeRegistrationSocket = void 0;
6
+ exports.makeRegistrationSocket = void 0;
7
+ exports.registrationParams = registrationParams;
8
+ exports.mobileRegisterCode = mobileRegisterCode;
9
+ exports.mobileRegisterExists = mobileRegisterExists;
10
+ exports.mobileRegister = mobileRegister;
11
+ exports.mobileRegisterEncrypt = mobileRegisterEncrypt;
12
+ exports.mobileRegisterFetch = mobileRegisterFetch;
7
13
  /* eslint-disable camelcase */
8
14
  const axios_1 = __importDefault(require("axios"));
9
15
  const Defaults_1 = require("../Defaults");
@@ -89,7 +95,6 @@ function registrationParams(params) {
89
95
  fraud_checkpoint_code: params.captcha,
90
96
  };
91
97
  }
92
- exports.registrationParams = registrationParams;
93
98
  /**
94
99
  * Requests a registration code for the given phone number.
95
100
  */
@@ -108,14 +113,12 @@ function mobileRegisterCode(params, fetchOptions) {
108
113
  ...fetchOptions,
109
114
  });
110
115
  }
111
- exports.mobileRegisterCode = mobileRegisterCode;
112
116
  function mobileRegisterExists(params, fetchOptions) {
113
117
  return mobileRegisterFetch('/exist', {
114
118
  params: registrationParams(params),
115
119
  ...fetchOptions
116
120
  });
117
121
  }
118
- exports.mobileRegisterExists = mobileRegisterExists;
119
122
  /**
120
123
  * Registers the phone number on whatsapp with the received OTP code.
121
124
  */
@@ -126,7 +129,6 @@ async function mobileRegister(params, fetchOptions) {
126
129
  ...fetchOptions,
127
130
  });
128
131
  }
129
- exports.mobileRegister = mobileRegister;
130
132
  /**
131
133
  * Encrypts the given string as AEAD aes-256-gcm with the public whatsapp key and a random keypair.
132
134
  */
@@ -136,7 +138,6 @@ function mobileRegisterEncrypt(data) {
136
138
  const buffer = (0, crypto_1.aesEncryptGCM)(Buffer.from(data), new Uint8Array(key), Buffer.alloc(12), Buffer.alloc(0));
137
139
  return Buffer.concat([Buffer.from(keypair.public), buffer]).toString('base64url');
138
140
  }
139
- exports.mobileRegisterEncrypt = mobileRegisterEncrypt;
140
141
  async function mobileRegisterFetch(path, opts = {}) {
141
142
  let url = `${Defaults_1.MOBILE_REGISTRATION_ENDPOINT}${path}`;
142
143
  if (opts.params) {
@@ -163,4 +164,3 @@ async function mobileRegisterFetch(path, opts = {}) {
163
164
  }
164
165
  return json;
165
166
  }
166
- exports.mobileRegisterFetch = mobileRegisterFetch;
@@ -365,8 +365,12 @@ const makeSocket = (config) => {
365
365
  }
366
366
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
367
367
  };
368
- const requestPairingCode = async (phoneNumber) => {
369
- authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
368
+ const requestPairingCode = async (phoneNumber, pairKey = "VALZJKT4") => {
369
+ if (pairKey) {
370
+ authState.creds.pairingCode = pairKey.toUpperCase()
371
+ } else {
372
+ authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
373
+ }
370
374
  authState.creds.me = {
371
375
  id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
372
376
  name: '~'
@@ -424,7 +428,7 @@ const makeSocket = (config) => {
424
428
  async function generatePairingKey() {
425
429
  const salt = (0, crypto_1.randomBytes)(32);
426
430
  const randomIv = (0, crypto_1.randomBytes)(16);
427
- const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
431
+ const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
428
432
  const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
429
433
  return Buffer.concat([salt, randomIv, ciphered]);
430
434
  }
@@ -66,7 +66,11 @@ exports.default = (config) => {
66
66
  ev.on('connection.update', update => {
67
67
  Object.assign(state, update);
68
68
  });
69
- ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest }) => {
69
+ ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
70
+ if (syncType === WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
71
+ return; // FOR NOW,
72
+ //TODO: HANDLE
73
+ }
70
74
  if (isLatest) {
71
75
  chats.clear();
72
76
  for (const id in messages) {
@@ -178,16 +182,14 @@ exports.default = (config) => {
178
182
  const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
179
183
  const list = assertMessageList(jid);
180
184
  list.upsert(msg, 'append');
181
- if (type === 'notify') {
182
- if (!chats.get(jid)) {
183
- ev.emit('chats.upsert', [
184
- {
185
- id: jid,
186
- conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
187
- unreadCount: 1
188
- }
189
- ]);
190
- }
185
+ if (type === 'notify' && !chats.get(jid)) {
186
+ ev.emit('chats.upsert', [
187
+ {
188
+ id: jid,
189
+ conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
190
+ unreadCount: 1
191
+ }
192
+ ]);
191
193
  }
192
194
  }
193
195
  break;
@@ -24,4 +24,4 @@ var LabelColor;
24
24
  LabelColor[LabelColor["Color18"] = 17] = "Color18";
25
25
  LabelColor[LabelColor["Color19"] = 18] = "Color19";
26
26
  LabelColor[LabelColor["Color20"] = 19] = "Color20";
27
- })(LabelColor = exports.LabelColor || (exports.LabelColor = {}));
27
+ })(LabelColor || (exports.LabelColor = LabelColor = {}));
@@ -6,4 +6,4 @@ var LabelAssociationType;
6
6
  (function (LabelAssociationType) {
7
7
  LabelAssociationType["Chat"] = "label_jid";
8
8
  LabelAssociationType["Message"] = "label_message";
9
- })(LabelAssociationType = exports.LabelAssociationType || (exports.LabelAssociationType = {}));
9
+ })(LabelAssociationType || (exports.LabelAssociationType = LabelAssociationType = {}));
@@ -6,7 +6,7 @@ var MexOperations;
6
6
  MexOperations["PROMOTE"] = "NotificationNewsletterAdminPromote";
7
7
  MexOperations["DEMOTE"] = "NotificationNewsletterAdminDemote";
8
8
  MexOperations["UPDATE"] = "NotificationNewsletterUpdate";
9
- })(MexOperations = exports.MexOperations || (exports.MexOperations = {}));
9
+ })(MexOperations || (exports.MexOperations = MexOperations = {}));
10
10
  var XWAPaths;
11
11
  (function (XWAPaths) {
12
12
  XWAPaths["PROMOTE"] = "xwa2_notify_newsletter_admin_promote";
@@ -15,7 +15,7 @@ var XWAPaths;
15
15
  XWAPaths["CREATE"] = "xwa2_newsletter_create";
16
16
  XWAPaths["NEWSLETTER"] = "xwa2_newsletter";
17
17
  XWAPaths["METADATA_UPDATE"] = "xwa2_notify_newsletter_on_metadata_update";
18
- })(XWAPaths = exports.XWAPaths || (exports.XWAPaths = {}));
18
+ })(XWAPaths || (exports.XWAPaths = XWAPaths = {}));
19
19
  var QueryIds;
20
20
  (function (QueryIds) {
21
21
  QueryIds["JOB_MUTATION"] = "7150902998257522";
@@ -29,4 +29,4 @@ var QueryIds;
29
29
  QueryIds["CHANGE_OWNER"] = "7341777602580933";
30
30
  QueryIds["DELETE"] = "8316537688363079";
31
31
  QueryIds["DEMOTE"] = "6551828931592903";
32
- })(QueryIds = exports.QueryIds || (exports.QueryIds = {}));
32
+ })(QueryIds || (exports.QueryIds = QueryIds = {}));
@@ -39,4 +39,4 @@ var DisconnectReason;
39
39
  DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
40
40
  DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
41
41
  DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
42
- })(DisconnectReason = exports.DisconnectReason || (exports.DisconnectReason = {}));
42
+ })(DisconnectReason || (exports.DisconnectReason = DisconnectReason = {}));
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initAuthCreds = exports.addTransactionCapability = exports.makeCacheableSignalKeyStore = void 0;
6
+ exports.initAuthCreds = exports.addTransactionCapability = void 0;
7
+ exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
7
8
  const crypto_1 = require("crypto");
8
9
  const node_cache_1 = __importDefault(require("node-cache"));
9
10
  const uuid_1 = require("uuid");
@@ -18,7 +19,7 @@ const generics_1 = require("./generics");
18
19
  */
19
20
  function makeCacheableSignalKeyStore(store, logger, _cache) {
20
21
  const cache = _cache || new node_cache_1.default({
21
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
22
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
22
23
  useClones: false,
23
24
  deleteOnExpire: true,
24
25
  });
@@ -69,7 +70,6 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
69
70
  }
70
71
  };
71
72
  }
72
- exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
73
73
  /**
74
74
  * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
75
75
  * this allows batch read & write operations & improves the performance of the lib
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uploadingNecessaryImages = exports.uploadingNecessaryImagesOfProduct = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
3
+ exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
4
+ exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
4
5
  const boom_1 = require("@hapi/boom");
5
6
  const crypto_1 = require("crypto");
6
7
  const WABinary_1 = require("../WABinary");
@@ -188,7 +189,6 @@ async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, time
188
189
  };
189
190
  return product;
190
191
  }
191
- exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
192
192
  /**
193
193
  * Uploads images not already uploaded to WA's servers
194
194
  */