@alannxd/baileys 6.1.7 → 6.2.8

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 (45) hide show
  1. package/README.md +440 -203
  2. package/lib/Defaults/index.js +2 -2
  3. package/lib/Socket/Client/websocket.js +35 -5
  4. package/lib/Socket/chats.js +0 -5
  5. package/lib/Socket/index.js +1 -9
  6. package/lib/Socket/luxu.js +4 -5
  7. package/lib/Socket/messages-recv.js +1 -1
  8. package/lib/Socket/messages-send.js +56 -114
  9. package/lib/Socket/mex.js +38 -51
  10. package/lib/Socket/newsletter.js +276 -745
  11. package/lib/Socket/socket.js +27 -161
  12. package/lib/Socket/username.js +204 -206
  13. package/lib/Store/make-in-memory-store.js +1 -47
  14. package/lib/Types/Mex.js +2 -76
  15. package/lib/Utils/browser-utils.js +1 -0
  16. package/lib/Utils/generics.js +2 -2
  17. package/lib/Utils/index.js +0 -1
  18. package/lib/Utils/messages-media.js +0 -82
  19. package/lib/Utils/messages.js +2 -136
  20. package/lib/WAUSync/Protocols/USyncContactProtocol.js +50 -52
  21. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +52 -55
  22. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -28
  23. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -37
  24. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -25
  25. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  26. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  27. package/lib/WAUSync/Protocols/index.js +6 -12
  28. package/lib/WAUSync/USyncQuery.js +96 -149
  29. package/lib/WAUSync/USyncUser.js +29 -54
  30. package/lib/WAUSync/index.js +4 -3
  31. package/lib/index.js +5 -2
  32. package/package.json +14 -13
  33. package/lib/Socket/graphql.js +0 -716
  34. package/lib/Socket/interop.js +0 -463
  35. package/lib/Socket/message-builder.js +0 -475
  36. package/lib/Socket/privacy.js +0 -318
  37. package/lib/Utils/sticker.js +0 -133
  38. package/lib/Utils/use-sqlite-auth-state.js +0 -162
  39. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -53
  40. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -43
  41. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -58
  42. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -30
  43. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
  44. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -28
  45. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
@@ -1,4 +1,3 @@
1
- import fs from "fs";
2
1
  import * as WAProto_1 from "../../WAProto/index.js";
3
2
  import * as Defaults_1 from "../Defaults/index.js";
4
3
  import { LabelAssociationType } from "../Types/LabelAssociation.js";
@@ -182,48 +181,6 @@ export default function makeInMemoryStore(config) {
182
181
  const loadMessage = async (jid, id) => {
183
182
  return messages[jid]?.get(id)
184
183
  }
185
-
186
- /**
187
- * Persist the whole store to a JSON file on disk (synchronous, atomic write).
188
- * Writes to a temp file first then renames, so a crash mid-write can't
189
- * corrupt the existing store file.
190
- */
191
- const writeToFile = (path) => {
192
- try {
193
- const tmpPath = `${path}.tmp`;
194
- fs.writeFileSync(tmpPath, JSON.stringify(toJSON()));
195
- fs.renameSync(tmpPath, path);
196
- } catch (err) {
197
- logger.error({ err }, "failed to write store to file");
198
- }
199
- };
200
-
201
- /**
202
- * Load store state from a JSON file on disk, if it exists.
203
- * Safe to call even if the file was never created yet.
204
- */
205
- const readFromFile = (path) => {
206
- if (!fs.existsSync(path)) return;
207
- try {
208
- const jsonStr = fs.readFileSync(path, { encoding: "utf-8" });
209
- const json = JSON.parse(jsonStr);
210
- fromJSON(json);
211
- } catch (err) {
212
- logger.error({ err }, "failed to read store from file");
213
- }
214
- };
215
-
216
- /**
217
- * Convenience helper: load once from `path` (if present), then keep
218
- * saving to the same file every `intervalMs` (default 10s).
219
- * Returns a function to stop the auto-save interval.
220
- */
221
- const writeToFileInterval = (path, intervalMs = 10_000) => {
222
- readFromFile(path);
223
- const interval = setInterval(() => writeToFile(path), intervalMs);
224
- return () => clearInterval(interval);
225
- };
226
-
227
184
  return {
228
185
  chats,
229
186
  contacts,
@@ -236,9 +193,6 @@ export default function makeInMemoryStore(config) {
236
193
  bind,
237
194
  toJSON,
238
195
  fromJSON,
239
- loadMessage,
240
- writeToFile,
241
- readFromFile,
242
- writeToFileInterval
196
+ loadMessage
243
197
  };
244
198
  }
package/lib/Types/Mex.js CHANGED
@@ -16,48 +16,12 @@ export var XWAPaths;
16
16
  XWAPaths["xwa2_newsletter_delete_v2"] = "xwa2_newsletter_delete_v2";
17
17
  XWAPaths["xwa2_fetch_account_reachout_timelock"] = "xwa2_fetch_account_reachout_timelock";
18
18
  XWAPaths["xwa2_message_capping_info"] = "xwa2_message_capping_info";
19
- XWAPaths["xwa2_newsletter_subscribed"] = "xwa2_newsletter_subscribed";
20
- XWAPaths["xwa2_newsletter_update"] = "xwa2_newsletter_update";
21
- XWAPaths["xwa2_newsletter_admin"] = "xwa2_newsletter_admin";
22
- XWAPaths["xwa2_newsletter_admin_invite_create"] = "xwa2_newsletter_admin_invite_create";
23
- XWAPaths["xwa2_newsletter_admin_invite_revoke"] = "xwa2_newsletter_admin_invite_revoke";
24
- XWAPaths["xwa2_newsletter_admin_invite_accept"] = "xwa2_newsletter_admin_invite_accept";
25
- XWAPaths["xwa2_newsletter_admin_profile_update"] = "xwa2_newsletter_admin_profile_update";
26
- XWAPaths["xwa2_newsletter_admin_insights"] = "xwa2_newsletter_admin_insights";
27
- XWAPaths["xwa2_newsletter_following"] = "xwa2_newsletter_following";
28
- XWAPaths["xwa2_newsletter_create_verified"] = "xwa2_newsletter_create_verified";
29
- XWAPaths["xwa2_newsletter_enforcements"] = "xwa2_newsletter_enforcements";
30
- XWAPaths["xwa2_newsletter_user_reports"] = "xwa2_newsletter_user_reports";
31
- XWAPaths["xwa2_newsletter_create_report_appeal"] = "xwa2_newsletter_create_report_appeal";
32
- XWAPaths["xwa2_newsletter_link_preview_check"] = "xwa2_newsletter_link_preview_check";
33
- XWAPaths["xwa2_newsletter_update_verification"] = "xwa2_newsletter_update_verification";
34
- XWAPaths["xwa2_newsletter_label_paid_partnership"] = "xwa2_newsletter_label_paid_partnership";
35
- XWAPaths["xwa2_newsletter_log_exposures"] = "xwa2_newsletter_log_exposures";
36
- XWAPaths["xwa2_newsletter_update_user_setting"] = "xwa2_newsletter_update_user_setting";
37
- XWAPaths["xwa2_newsletter_ranking_features"] = "xwa2_newsletter_ranking_features";
38
- XWAPaths["xwa2_newsletter_block_user"] = "xwa2_newsletter_block_user";
39
- XWAPaths["xwa2_newsletters_directory_list"] = "xwa2_newsletters_directory_list";
40
- XWAPaths["xwa2_newsletters_directory_search"] = "xwa2_newsletters_directory_search";
41
- XWAPaths["xwa2_newsletters_directory_category_preview"] = "xwa2_newsletters_directory_category_preview";
42
- XWAPaths["xwa2_newsletters_search"] = "xwa2_newsletters_search";
43
- XWAPaths["xwa2_newsletters_recommended"] = "xwa2_newsletters_recommended";
44
- XWAPaths["xwa2_newsletters_similar"] = "xwa2_newsletters_similar";
45
- XWAPaths["xwa2_newsletters_poll_voter_list"] = "xwa2_newsletters_poll_voter_list";
46
- XWAPaths["xwa2_newsletters_reaction_sender_list"] = "xwa2_newsletters_reaction_sender_list";
47
- XWAPaths["xwa2_wamo_afs_age_collection"] = "xwa2_wamo_afs_age_collection";
48
- XWAPaths["xwa2_wamo_asset_collection"] = "xwa2_wamo_asset_collection";
49
- XWAPaths["xwa2_wamo_fetch_adhoc_notice_by_id"] = "xwa2_wamo_fetch_adhoc_notice_by_id";
50
- XWAPaths["xwa2_wamo_fetch_identity_token"] = "xwa2_wamo_fetch_identity_token";
51
- XWAPaths["xwa2_wamo_sub_get_compliance_info"] = "xwa2_wamo_sub_get_compliance_info";
52
- XWAPaths["xwa2_wamo_user_id_version"] = "xwa2_wamo_user_id_version";
53
- XWAPaths["xwa2_wamo_set_user_id_version"] = "xwa2_wamo_set_user_id_version";
54
19
  })(XWAPaths || (XWAPaths = {}));
55
-
56
20
  export var QueryIds;
57
21
  (function (QueryIds) {
58
22
  QueryIds["CREATE"] = "8823471724422422";
59
- QueryIds["METADATA"] = "26099060629688646";
60
- QueryIds["UPDATE_METADATA"] = "25976052865358570";
23
+ QueryIds["UPDATE_METADATA"] = "24250201037901610";
24
+ QueryIds["METADATA"] = "6563316087068696";
61
25
  QueryIds["SUBSCRIBERS"] = "9783111038412085";
62
26
  QueryIds["FOLLOW"] = "24404358912487870";
63
27
  QueryIds["UNFOLLOW"] = "9767147403369991";
@@ -69,43 +33,5 @@ export var QueryIds;
69
33
  QueryIds["DELETE"] = "30062808666639665";
70
34
  QueryIds["REACHOUT_TIMELOCK"] = "23983697327930364";
71
35
  QueryIds["MESSAGE_CAPPING_INFO"] = "24503548349331633";
72
- QueryIds["FETCH_SUBSCRIBE"] = "6388546374527196";
73
- QueryIds["LEAVE"] = "9784043202933196";
74
- QueryIds["ADMIN_INVITE"] = "7148599488585196";
75
- QueryIds["ADMIN_INVITE_REVOKE"] = "6345824195482235";
76
- QueryIds["ADMIN_INVITE_ACCEPT"] = "6345824195482236";
77
- QueryIds["ADMIN_METADATA"] = "6895563180530100";
78
- QueryIds["ADMIN_PROFILE_UPDATE"] = "6895563180530101";
79
- QueryIds["INSIGHTS"] = "6243647912368353";
80
- QueryIds["FOLLOWING_LIST"] = "6388546374527197";
81
- QueryIds["CREATE_VERIFIED"] = "8823471724422423";
82
- QueryIds["ENFORCEMENTS"] = "7130823597031707";
83
- QueryIds["USER_REPORTS"] = "9783111038412086";
84
- QueryIds["CREATE_REPORT_APPEAL"] = "6551828931592904";
85
- QueryIds["LINK_PREVIEW_CHECK"] = "24404358912487871";
86
- QueryIds["UPDATE_VERIFICATION"] = "25976052865358571";
87
- QueryIds["LABEL_PAID_PARTNERSHIP"] = "7341777602580934";
88
- QueryIds["LOG_EXPOSURES"] = "9864994326891138";
89
- QueryIds["UPDATE_USER_SETTING"] = "29766401636284407";
90
- QueryIds["RANKING_FEATURES"] = "7130823597031708";
91
- QueryIds["BLOCK_USER"] = "6345824195482237";
92
- QueryIds["DIRECTORY_LIST"] = "6388546374527198";
93
- QueryIds["DIRECTORY_SEARCH"] = "6388546374527199";
94
- QueryIds["DIRECTORY_CATEGORY_PREVIEW"] = "6388546374527200";
95
- QueryIds["SEARCH"] = "26099060629688647";
96
- QueryIds["RECOMMENDED"] = "26099060629688648";
97
- QueryIds["SIMILAR"] = "26099060629688649";
98
- QueryIds["POLL_VOTER_LIST"] = "9783111038412087";
99
- QueryIds["REACTION_SENDERS_LIST"] = "9783111038412088";
100
- QueryIds["WAMO_ENABLE_SUB"] = "7148599488585197";
101
- QueryIds["WAMO_DISABLE_SUB"] = "7148599488585198";
102
- QueryIds["WAMO_CHANGE_SUB"] = "7148599488585199";
103
- QueryIds["WAMO_AFS_AGE_COLLECTION"] = "6895563180530102";
104
- QueryIds["WAMO_ASSET_COLLECTION"] = "6895563180530103";
105
- QueryIds["WAMO_FETCH_ADHOC_NOTICE"] = "6895563180530104";
106
- QueryIds["WAMO_FETCH_IDENTITY_TOKEN"] = "6895563180530105";
107
- QueryIds["WAMO_SUB_COMPLIANCE_INFO"] = "6895563180530106";
108
- QueryIds["WAMO_USER_ID_VERSION"] = "6895563180530107";
109
- QueryIds["WAMO_SET_USER_ID_VERSION"] = "6895563180530108";
110
36
  })(QueryIds || (QueryIds = {}));
111
37
  //# sourceMappingURL=Mex.js.map
@@ -30,6 +30,7 @@ export const Browsers = {
30
30
  ubuntu: browser => ['Ubuntu', getBrowserN(browser), '22.04.4'],
31
31
  macOS: browser => ['Mac OS', getBrowserN(browser), '14.4.1'],
32
32
  baileys: browser => ['Baileys', getBrowserN(browser), '6.5.0'],
33
+ poucode: browser => ['PouCode', getBrowserN(browser), '1.0.0'],
33
34
  windows: browser => ['Windows', getBrowserN(browser), '10.0.22631'],
34
35
  iOS: browser => ['iOS', getBrowserN(browser), '18.2'],
35
36
  android: browser => ['Android', getBrowserN(browser), '14.0.0'],
@@ -173,7 +173,7 @@ export function bindWaitForEvent(ev, event) {
173
173
  }
174
174
  export const generateIOSMessageID = () => {
175
175
  const prefix = '3A';
176
- const random = randomBytes(9.5); // 19 hex chars = 9.5 bytes
176
+ const random = randomBytes(10); // 20 hex chars, trimmed to 19
177
177
  return (prefix + random.toString('hex')).toUpperCase().substring(0, 21);
178
178
  };
179
179
  export const generateAndroMessageID = () => {
@@ -400,4 +400,4 @@ export function bytesToCrockford(buffer) {
400
400
  export function encodeNewsletterMessage(message) {
401
401
  return proto.Message.encode(message).finish();
402
402
  }
403
- //# sourceMappingURL=generics.js.map
403
+ //# sourceMappingURL=generics.js.map
@@ -11,7 +11,6 @@ export * from './chat-utils.js';
11
11
  export * from './lt-hash.js';
12
12
  export * from './auth-utils.js';
13
13
  export * from './use-multi-file-auth-state.js';
14
- export * from './use-sqlite-auth-state.js';
15
14
  export * from './link-preview.js';
16
15
  export * from './event-buffer.js';
17
16
  export * from './process-message.js';
@@ -778,88 +778,6 @@ export const decryptMediaRetryData = ({ ciphertext, iv }, mediaKey, msgId) => {
778
778
  const plaintext = aesDecryptGCM(ciphertext, retryKey, iv, Buffer.from(msgId));
779
779
  return proto.MediaRetryNotification.decode(plaintext);
780
780
  };
781
- const CRC_TABLE = (() => {
782
- const table = new Uint32Array(256);
783
- for (let n = 0; n < 256; n++) {
784
- let c = n;
785
- for (let k = 0; k < 8; k++) {
786
- c = c & 1 ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1);
787
- }
788
- table[n] = c >>> 0;
789
- }
790
- return table;
791
- })();
792
- export const crc32 = (buf) => {
793
- let crc = 0xffffffff;
794
- for (let i = 0; i < buf.length; i++) {
795
- crc = CRC_TABLE[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
796
- }
797
- return (crc ^ 0xffffffff) >>> 0;
798
- };
799
- export const buildZipArchive = (files) => {
800
- const localChunks = [];
801
- const centralChunks = [];
802
- let offset = 0;
803
- for (const { name, data } of files) {
804
- const nameBuf = Buffer.from(name, 'utf8');
805
- const crc = crc32(data);
806
- const dosTime = 0;
807
- const dosDate = 0x21;
808
- const localHeader = Buffer.alloc(30);
809
- localHeader.writeUInt32LE(0x04034b50, 0);
810
- localHeader.writeUInt16LE(20, 4);
811
- localHeader.writeUInt16LE(0, 6);
812
- localHeader.writeUInt16LE(0, 8);
813
- localHeader.writeUInt16LE(dosTime, 10);
814
- localHeader.writeUInt16LE(dosDate, 12);
815
- localHeader.writeUInt32LE(crc, 14);
816
- localHeader.writeUInt32LE(data.length, 18);
817
- localHeader.writeUInt32LE(data.length, 22);
818
- localHeader.writeUInt16LE(nameBuf.length, 26);
819
- localHeader.writeUInt16LE(0, 28);
820
- localChunks.push(localHeader, nameBuf, data);
821
- const centralHeader = Buffer.alloc(46);
822
- centralHeader.writeUInt32LE(0x02014b50, 0);
823
- centralHeader.writeUInt16LE(20, 4);
824
- centralHeader.writeUInt16LE(20, 6);
825
- centralHeader.writeUInt16LE(0, 8);
826
- centralHeader.writeUInt16LE(0, 10);
827
- centralHeader.writeUInt16LE(dosTime, 12);
828
- centralHeader.writeUInt16LE(dosDate, 14);
829
- centralHeader.writeUInt32LE(crc, 16);
830
- centralHeader.writeUInt32LE(data.length, 20);
831
- centralHeader.writeUInt32LE(data.length, 24);
832
- centralHeader.writeUInt16LE(nameBuf.length, 28);
833
- centralHeader.writeUInt16LE(0, 30);
834
- centralHeader.writeUInt16LE(0, 32);
835
- centralHeader.writeUInt16LE(0, 34);
836
- centralHeader.writeUInt16LE(0, 36);
837
- centralHeader.writeUInt32LE(0, 38);
838
- centralHeader.writeUInt32LE(offset, 42);
839
- centralChunks.push(centralHeader, nameBuf);
840
- offset += localHeader.length + nameBuf.length + data.length;
841
- }
842
- const centralDirStart = offset;
843
- const centralDirBuf = Buffer.concat(centralChunks);
844
- const eocd = Buffer.alloc(22);
845
- eocd.writeUInt32LE(0x06054b50, 0);
846
- eocd.writeUInt16LE(0, 4);
847
- eocd.writeUInt16LE(0, 6);
848
- eocd.writeUInt16LE(files.length, 8);
849
- eocd.writeUInt16LE(files.length, 10);
850
- eocd.writeUInt32LE(centralDirBuf.length, 12);
851
- eocd.writeUInt32LE(centralDirStart, 16);
852
- eocd.writeUInt16LE(0, 20);
853
- return Buffer.concat([...localChunks, centralDirBuf, eocd]);
854
- };
855
- export const resolveStickerBuffer = async (item, opts) => {
856
- if (Buffer.isBuffer(item)) {
857
- return item;
858
- }
859
- const media = typeof item === 'string' ? { url: item } : item;
860
- const { stream } = await getStream(media, opts);
861
- return toBuffer(stream);
862
- };
863
781
  export const getStatusCodeForMediaRetry = (code) => MEDIA_RETRY_STATUS_MAP[code];
864
782
  const MEDIA_RETRY_STATUS_MAP = {
865
783
  [proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
@@ -8,8 +8,7 @@ import { WAMessageStatus, WAProto } from '../Types/index.js';
8
8
  import { isJidGroup, isJidNewsletter, isJidStatusBroadcast, jidNormalizedUser } from '../WABinary/index.js';
9
9
  import { sha256 } from './crypto.js';
10
10
  import { generateMessageIDV2, getKeyAuthor, unixTimestampSeconds } from './generics.js';
11
- import { buildZipArchive, downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, getRawMediaUploadData, resolveStickerBuffer } from './messages-media.js';
12
- import { makeSticker, convertToTrayIcon, isLikelyVideoBuffer } from './sticker.js';
11
+ import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, getRawMediaUploadData } from './messages-media.js';
13
12
  import { shouldIncludeReportingToken } from './reporting-utils.js';
14
13
  const MIMETYPE_MAP = {
15
14
  image: 'image/jpeg',
@@ -19,34 +18,6 @@ const MIMETYPE_MAP = {
19
18
  sticker: 'image/webp',
20
19
  'product-catalog-image': 'image/jpeg'
21
20
  };
22
- const RAW_PROTO_MESSAGE_KEYS = [
23
- 'conversation', 'senderKeyDistributionMessage', 'imageMessage', 'contactMessage', 'locationMessage',
24
- 'extendedTextMessage', 'documentMessage', 'audioMessage', 'videoMessage', 'call', 'chat', 'protocolMessage',
25
- 'contactsArrayMessage', 'highlyStructuredMessage', 'fastRatchetKeySenderKeyDistributionMessage',
26
- 'sendPaymentMessage', 'liveLocationMessage', 'requestPaymentMessage', 'declinePaymentRequestMessage',
27
- 'cancelPaymentRequestMessage', 'templateMessage', 'stickerMessage', 'groupInviteMessage',
28
- 'templateButtonReplyMessage', 'productMessage', 'deviceSentMessage', 'messageContextInfo', 'listMessage',
29
- 'viewOnceMessage', 'orderMessage', 'listResponseMessage', 'ephemeralMessage', 'invoiceMessage',
30
- 'buttonsMessage', 'buttonsResponseMessage', 'paymentInviteMessage', 'interactiveMessage', 'reactionMessage',
31
- 'stickerSyncRmrMessage', 'interactiveResponseMessage', 'pollCreationMessage', 'pollUpdateMessage',
32
- 'keepInChatMessage', 'documentWithCaptionMessage', 'requestPhoneNumberMessage', 'viewOnceMessageV2',
33
- 'encReactionMessage', 'editedMessage', 'viewOnceMessageV2Extension', 'pollCreationMessageV2',
34
- 'scheduledCallCreationMessage', 'groupMentionedMessage', 'pinInChatMessage', 'pollCreationMessageV3',
35
- 'scheduledCallEditMessage', 'ptvMessage', 'botInvokeMessage', 'callLogMesssage', 'messageHistoryBundle',
36
- 'encCommentMessage', 'bcallMessage', 'lottieStickerMessage', 'eventMessage', 'encEventResponseMessage',
37
- 'commentMessage', 'newsletterAdminInviteMessage', 'placeholderMessage', 'secretEncryptedMessage',
38
- 'albumMessage', 'eventCoverImage', 'stickerPackMessage', 'statusMentionMessage', 'pollResultSnapshotMessage',
39
- 'pollCreationOptionImageMessage', 'associatedChildMessage', 'groupStatusMentionMessage',
40
- 'pollCreationMessageV4', 'statusAddYours', 'groupStatusMessage', 'richResponseMessage',
41
- 'statusNotificationMessage', 'limitSharingMessage', 'botTaskMessage', 'questionMessage',
42
- 'messageHistoryNotice', 'groupStatusMessageV2', 'botForwardedMessage', 'statusQuestionAnswerMessage',
43
- 'questionReplyMessage', 'questionResponseMessage', 'statusQuotedMessage', 'statusStickerInteractionMessage',
44
- 'pollCreationMessageV5', 'newsletterFollowerInviteMessageV2', 'pollResultSnapshotMessageV3',
45
- 'newsletterAdminProfileMessage', 'newsletterAdminProfileMessageV2', 'spoilerMessage',
46
- 'pollCreationMessageV6', 'conditionalRevealMessage', 'pollAddOptionMessage', 'eventInviteMessage',
47
- 'groupRootKeyShare', 'paymentReminderMessage', 'splitPaymentMessage', 'newsletterAdminProfileStatusMessage',
48
- 'rootSecretDistributeMessage'
49
- ];
50
21
  const MessageTypeProto = {
51
22
  image: WAProto.Message.ImageMessage,
52
23
  video: WAProto.Message.VideoMessage,
@@ -881,113 +852,8 @@ export const generateWAMessageContent = async (message, options) => {
881
852
  }
882
853
  };
883
854
  }
884
- else if (hasNonNullishProperty(message, 'stickerPacks')) {
885
- const pack = message.stickerPacks;
886
- const rawStickers = Array.isArray(pack.stickers) ? pack.stickers : [];
887
- if (rawStickers.length === 0) {
888
- throw new Boom('stickerPacks.stickers must have at least one sticker', { statusCode: 400 });
889
- }
890
- const packName = pack.name || 'Sticker Pack';
891
- const publisher = pack.publisher || pack.author || '';
892
- // each entry can be raw sticker media, or { image, animated, emojis, accessibilityLabel, quality }
893
- const preparedStickers = await Promise.all(rawStickers.map(async (entry, i) => {
894
- const isWrapped = entry && typeof entry === 'object' && !Buffer.isBuffer(entry) && 'image' in entry;
895
- const rawBuffer = await resolveStickerBuffer(isWrapped ? entry.image : entry, options.options);
896
- const animated = isWrapped ? !!entry.animated : false;
897
- const emojis = (isWrapped && entry.emojis) || [];
898
- const webp = await makeSticker(rawBuffer, {
899
- pack: packName,
900
- author: publisher,
901
- emojis,
902
- animated: animated || isLikelyVideoBuffer(rawBuffer),
903
- quality: (isWrapped && entry.quality) || 60
904
- });
905
- return {
906
- fileName: `sticker_${i}.webp`,
907
- data: webp,
908
- isAnimated: animated,
909
- emojis,
910
- accessibilityLabel: isWrapped ? entry.accessibilityLabel : undefined,
911
- isLottie: false,
912
- mimetype: 'image/webp'
913
- };
914
- }));
915
- const trayIconFileName = 'tray.png';
916
- const trayIconPng = await convertToTrayIcon(await resolveStickerBuffer(
917
- (rawStickers[0] && typeof rawStickers[0] === 'object' && !Buffer.isBuffer(rawStickers[0]) && 'image' in rawStickers[0])
918
- ? rawStickers[0].image
919
- : rawStickers[0],
920
- options.options
921
- ));
922
- const stickerPackId = pack.stickerPackId || randomUUID();
923
- const zipEntries = [
924
- ...preparedStickers.map(s => ({ name: s.fileName, data: s.data })),
925
- { name: trayIconFileName, data: trayIconPng }
926
- ];
927
- const archive = buildZipArchive(zipEntries);
928
- // reuse the normal, well-tested media upload path to encrypt+upload the archive,
929
- // then repurpose the resulting media fields into the stickerPackMessage itself
930
- const uploaded = await prepareWAMessageMedia({
931
- document: archive,
932
- mimetype: 'application/zip',
933
- fileName: `${stickerPackId}.zip`
934
- }, options);
935
- const doc = uploaded.documentMessage;
936
- m = {
937
- stickerPackMessage: {
938
- stickerPackId,
939
- name: packName,
940
- publisher,
941
- packDescription: pack.description,
942
- stickers: preparedStickers.map(s => ({
943
- fileName: s.fileName,
944
- isAnimated: s.isAnimated,
945
- emojis: s.emojis,
946
- accessibilityLabel: s.accessibilityLabel,
947
- isLottie: s.isLottie,
948
- mimetype: s.mimetype
949
- })),
950
- fileLength: doc.fileLength,
951
- fileSha256: doc.fileSha256,
952
- fileEncSha256: doc.fileEncSha256,
953
- mediaKey: doc.mediaKey,
954
- directPath: doc.directPath,
955
- mediaKeyTimestamp: doc.mediaKeyTimestamp,
956
- trayIconFileName,
957
- stickerPackSize: archive.length,
958
- stickerPackOrigin: proto.Message.StickerPackMessage.StickerPackOrigin.USER_CREATED
959
- }
960
- };
961
- }
962
- else if (hasNonNullishProperty(message, 'sticker') && (message.pack || message.author || message.isPrivate || message.premium || message.animated)) {
963
- const rawBuffer = await resolveStickerBuffer(message.sticker, options.options);
964
- const finalWebp = await makeSticker(rawBuffer, {
965
- pack: message.pack || '',
966
- author: message.author || '',
967
- emojis: message.emojis || [],
968
- isPrivate: !!message.isPrivate,
969
- animated: !!message.animated,
970
- quality: message.quality || 60
971
- });
972
- m = await prepareWAMessageMedia({ sticker: finalWebp }, options);
973
- if (m.stickerMessage) {
974
- if (message.premium) {
975
- m.stickerMessage.premium = typeof message.premium === 'number' ? message.premium : 1;
976
- }
977
- if (message.isPrivate) {
978
- m.stickerMessage.isAvatar = true;
979
- }
980
- }
981
- }
982
855
  else {
983
- const rawProtoKey = RAW_PROTO_MESSAGE_KEYS.find(k => hasNonNullishProperty(message, k));
984
- if (rawProtoKey) {
985
- const built = proto.Message.fromObject({ [rawProtoKey]: message[rawProtoKey] });
986
- m = { [rawProtoKey]: built[rawProtoKey] };
987
- }
988
- else {
989
- m = await prepareWAMessageMedia(message, options);
990
- }
856
+ m = await prepareWAMessageMedia(message, options);
991
857
  }
992
858
  if (hasOptionalProperty(message, 'viewOnce') && !!message.viewOnce) {
993
859
  m = { viewOnceMessage: { message: m } };
@@ -1,54 +1,52 @@
1
- import { assertNodeErrorFree } from '../../WABinary/index.js'
2
-
1
+ import { assertNodeErrorFree } from '../../WABinary/index.js';
2
+ import { USyncUser } from '../USyncUser.js';
3
3
  export class USyncContactProtocol {
4
- constructor() {
5
- this.name = 'contact'
6
- }
7
-
8
- getQueryElement() {
9
- return {
10
- tag: 'contact',
11
- attrs: {}
12
- }
13
- }
14
-
15
- getUserElement(user) {
16
- if (user.phone) {
17
- return {
18
- tag: 'contact',
19
- attrs: {},
20
- content: user.phone
21
- }
22
- }
23
- if (user.username) {
24
- return {
25
- tag: 'contact',
26
- attrs: {
27
- username: user.username,
28
- ...(user.usernameKey ? { pin: user.usernameKey } : {}),
29
- ...(user.lid ? { lid: user.lid } : {})
30
- }
31
- }
32
- }
33
- if (user.type) {
34
- return {
35
- tag: 'contact',
36
- attrs: {
37
- type: user.type
38
- }
39
- }
40
- }
41
- return {
42
- tag: 'contact',
43
- attrs: {}
44
- }
45
- }
46
-
47
- parser(node) {
48
- if (node.tag === 'contact') {
49
- assertNodeErrorFree(node)
50
- return node?.attrs?.type === 'in'
51
- }
52
- return false
53
- }
4
+ constructor() {
5
+ this.name = 'contact';
6
+ }
7
+ getQueryElement() {
8
+ return {
9
+ tag: 'contact',
10
+ attrs: {}
11
+ };
12
+ }
13
+ getUserElement(user) {
14
+ if (user.phone) {
15
+ return {
16
+ tag: 'contact',
17
+ attrs: {},
18
+ content: user.phone
19
+ };
20
+ }
21
+ if (user.username) {
22
+ return {
23
+ tag: 'contact',
24
+ attrs: {
25
+ username: user.username,
26
+ ...(user.usernameKey ? { pin: user.usernameKey } : {}),
27
+ ...(user.lid ? { lid: user.lid } : {})
28
+ }
29
+ };
30
+ }
31
+ if (user.type) {
32
+ return {
33
+ tag: 'contact',
34
+ attrs: {
35
+ type: user.type
36
+ }
37
+ };
38
+ }
39
+ return {
40
+ tag: 'contact',
41
+ attrs: {}
42
+ };
43
+ }
44
+ parser(node) {
45
+ if (node.tag === 'contact') {
46
+ assertNodeErrorFree(node);
47
+ return node?.attrs?.type === 'in';
48
+ }
49
+ return false;
50
+ }
54
51
  }
52
+ //# sourceMappingURL=USyncContactProtocol.js.map
@@ -1,57 +1,54 @@
1
- import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js'
2
-
1
+ import { assertNodeErrorFree, getBinaryNodeChild } from '../../WABinary/index.js';
3
2
  export class USyncDeviceProtocol {
4
- constructor() {
5
- this.name = 'devices'
6
- }
7
-
8
- getQueryElement() {
9
- return {
10
- tag: 'devices',
11
- attrs: {
12
- version: '2'
13
- }
14
- }
15
- }
16
-
17
- getUserElement(/* user */) {
18
- //TODO: Implement device phashing, ts and expectedTs
19
- //TODO: if all are not present, return null <- current behavior
20
- //TODO: otherwise return a node w tag 'devices' w those as attrs
21
- return null
22
- }
23
-
24
- parser(node) {
25
- const deviceList = []
26
- let keyIndex = undefined
27
- if (node.tag === 'devices') {
28
- assertNodeErrorFree(node)
29
- const deviceListNode = getBinaryNodeChild(node, 'device-list')
30
- const keyIndexNode = getBinaryNodeChild(node, 'key-index-list')
31
- if (Array.isArray(deviceListNode?.content)) {
32
- for (const { tag, attrs } of deviceListNode.content) {
33
- const id = +attrs.id
34
- const keyIndex = +attrs['key-index']
35
- if (tag === 'device') {
36
- deviceList.push({
37
- id,
38
- keyIndex,
39
- isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
40
- })
41
- }
42
- }
43
- }
44
- if (keyIndexNode?.tag === 'key-index-list') {
45
- keyIndex = {
46
- timestamp: +keyIndexNode.attrs['ts'],
47
- signedKeyIndex: keyIndexNode?.content,
48
- expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
49
- }
50
- }
51
- }
52
- return {
53
- deviceList,
54
- keyIndex
55
- }
56
- }
3
+ constructor() {
4
+ this.name = 'devices';
5
+ }
6
+ getQueryElement() {
7
+ return {
8
+ tag: 'devices',
9
+ attrs: {
10
+ version: '2'
11
+ }
12
+ };
13
+ }
14
+ getUserElement( /* user: USyncUser */) {
15
+ //TODO: Implement device phashing, ts and expectedTs
16
+ //TODO: if all are not present, return null <- current behavior
17
+ //TODO: otherwise return a node w tag 'devices' w those as attrs
18
+ return null;
19
+ }
20
+ parser(node) {
21
+ const deviceList = [];
22
+ let keyIndex = undefined;
23
+ if (node.tag === 'devices') {
24
+ assertNodeErrorFree(node);
25
+ const deviceListNode = getBinaryNodeChild(node, 'device-list');
26
+ const keyIndexNode = getBinaryNodeChild(node, 'key-index-list');
27
+ if (Array.isArray(deviceListNode?.content)) {
28
+ for (const { tag, attrs } of deviceListNode.content) {
29
+ const id = +attrs.id;
30
+ const keyIndex = +attrs['key-index'];
31
+ if (tag === 'device') {
32
+ deviceList.push({
33
+ id,
34
+ keyIndex,
35
+ isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
36
+ });
37
+ }
38
+ }
39
+ }
40
+ if (keyIndexNode?.tag === 'key-index-list') {
41
+ keyIndex = {
42
+ timestamp: +keyIndexNode.attrs['ts'],
43
+ signedKeyIndex: keyIndexNode?.content,
44
+ expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
45
+ };
46
+ }
47
+ }
48
+ return {
49
+ deviceList,
50
+ keyIndex
51
+ };
52
+ }
57
53
  }
54
+ //# sourceMappingURL=USyncDeviceProtocol.js.map