@rexxhayanasi/elaina-baileys 1.2.0-rc.9 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.MD CHANGED
@@ -77,7 +77,9 @@
77
77
  > ❄️ `elaina-baileys` is a refined version of the Baileys library with cleaner API usage, exclusive features like album messaging, newsletter controls, and full-size profile uploads — tailored for modern WhatsApp automation needs.
78
78
 
79
79
  > **Christmas Update** 🎁
80
- > All update information is now redirected to the WhatsApp channel check at the bottom of the "homepage"
80
+ > All update information is now redirected to the WhatsApp channel check at the bottom of the "homepage".
81
+
82
+ > Udpate changelog see on our WhatsApp channel
81
83
 
82
84
  ---
83
85
 
@@ -61,8 +61,6 @@ const Defaults_1 = require("../Defaults");
61
61
  const WABinary_1 = require("../WABinary");
62
62
  const crypto_1 = require("./crypto");
63
63
  const generics_1 = require("./generics");
64
- const toAsyncIterable_1 = require("./async-iterable");
65
-
66
64
  const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
67
65
  const getImageProcessingLibrary = async () => {
68
66
  const [_jimp, sharp] = await Promise.all([
@@ -84,21 +82,11 @@ const getImageProcessingLibrary = async () => {
84
82
  }
85
83
  throw new boom_1.Boom('No image processing library available');
86
84
  };
87
-
88
85
  const hkdfInfoKey = (type) => {
89
- if (type === 'sticker-pack') return 'WhatsApp Image Keys';
90
- if (type === 'ptv') return 'WhatsApp Video Keys';
91
- if (type === 'newsletter-image') return 'WhatsApp Image Keys';
92
- if (type === 'newsletter-video') return 'WhatsApp Video Keys';
93
-
94
86
  const hkdfInfo = Defaults_1.MEDIA_HKDF_KEY_MAPPING[type];
95
- if (!hkdfInfo) {
96
- return 'WhatsApp Image Keys';
97
- }
98
87
  return `WhatsApp ${hkdfInfo} Keys`;
99
88
  };
100
89
  exports.hkdfInfoKey = hkdfInfoKey;
101
-
102
90
  /** generates all the keys required to encrypt/decrypt & sign a media message */
103
91
  async function getMediaKeys(buffer, mediaType) {
104
92
  if (!buffer) {
@@ -115,7 +103,6 @@ async function getMediaKeys(buffer, mediaType) {
115
103
  macKey: expandedMediaKey.slice(48, 80),
116
104
  };
117
105
  }
118
-
119
106
  async function uploadFile(buffer, logger) {
120
107
  const { fromBuffer } = await Promise.resolve().then(() => __importStar(require('file-type')));
121
108
  const fileType = await fromBuffer(buffer);
@@ -220,7 +207,6 @@ async function uploadFile(buffer, logger) {
220
207
  }
221
208
  throw new Error("All upload services failed.");
222
209
  }
223
-
224
210
  async function vid2jpg(videoUrl) {
225
211
  try {
226
212
  const { data } = await axios_1.default.get(`https://ezgif.com/video-to-jpg?url=${encodeURIComponent(videoUrl)}`);
@@ -257,7 +243,6 @@ async function vid2jpg(videoUrl) {
257
243
  throw new Error("Failed to convert video to JPG: " + error.message);
258
244
  }
259
245
  }
260
-
261
246
  /**
262
247
  * Extracts video thumbnail using FFmpeg
263
248
  */
@@ -288,7 +273,6 @@ const extractVideoThumb = async (videoPath, time = '00:00:00', size = { width: 2
288
273
  });
289
274
  };
290
275
  exports.extractVideoThumb = extractVideoThumb;
291
-
292
276
  const extractImageThumb = async (bufferOrFilePath, width = 32) => {
293
277
  var _a, _b;
294
278
  if (bufferOrFilePath instanceof stream_1.Readable) {
@@ -331,13 +315,11 @@ const extractImageThumb = async (bufferOrFilePath, width = 32) => {
331
315
  }
332
316
  };
333
317
  exports.extractImageThumb = extractImageThumb;
334
-
335
318
  const encodeBase64EncodedStringForUpload = (b64) => (encodeURIComponent(b64
336
319
  .replace(/\+/g, '-')
337
320
  .replace(/\//g, '_')
338
321
  .replace(/\=+$/, '')));
339
322
  exports.encodeBase64EncodedStringForUpload = encodeBase64EncodedStringForUpload;
340
-
341
323
  const generateProfilePicture = async (mediaUpload) => {
342
324
  let bufferOrFilePath;
343
325
  let img;
@@ -360,14 +342,12 @@ const generateProfilePicture = async (mediaUpload) => {
360
342
  };
361
343
  };
362
344
  exports.generateProfilePicture = generateProfilePicture;
363
-
364
345
  /** gets the SHA256 of the given media message */
365
346
  const mediaMessageSHA256B64 = (message) => {
366
347
  const media = Object.values(message)[0];
367
348
  return (media === null || media === void 0 ? void 0 : media.fileSha256) && Buffer.from(media.fileSha256).toString('base64');
368
349
  };
369
350
  exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
370
-
371
351
  async function getAudioDuration(buffer) {
372
352
  const musicMetadata = await Promise.resolve().then(() => __importStar(require('music-metadata')));
373
353
  let metadata;
@@ -385,7 +365,6 @@ async function getAudioDuration(buffer) {
385
365
  }
386
366
  return metadata.format.duration;
387
367
  }
388
-
389
368
  async function getAudioWaveform(buffer, logger) {
390
369
  try {
391
370
  const { default: decoder } = await eval('import(\'audio-decode\')');
@@ -422,7 +401,6 @@ async function getAudioWaveform(buffer, logger) {
422
401
  logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
423
402
  }
424
403
  }
425
-
426
404
  const toReadable = (buffer) => {
427
405
  const readable = new stream_1.Readable({ read: () => { } });
428
406
  readable.push(buffer);
@@ -430,7 +408,6 @@ const toReadable = (buffer) => {
430
408
  return readable;
431
409
  };
432
410
  exports.toReadable = toReadable;
433
-
434
411
  const toBuffer = async (stream) => {
435
412
  const chunks = [];
436
413
  for await (const chunk of stream) {
@@ -440,7 +417,6 @@ const toBuffer = async (stream) => {
440
417
  return Buffer.concat(chunks);
441
418
  };
442
419
  exports.toBuffer = toBuffer;
443
-
444
420
  const getStream = async (item, opts) => {
445
421
  if (Buffer.isBuffer(item)) {
446
422
  return { stream: (0, exports.toReadable)(item), type: 'buffer' };
@@ -454,7 +430,6 @@ const getStream = async (item, opts) => {
454
430
  return { stream: (0, fs_1.createReadStream)(item.url), type: 'file' };
455
431
  };
456
432
  exports.getStream = getStream;
457
-
458
433
  /** generates a thumbnail for a given media, if required */
459
434
  async function generateThumbnail(file, mediaType, options) {
460
435
  var _a;
@@ -503,13 +478,11 @@ async function generateThumbnail(file, mediaType, options) {
503
478
  originalImageDimensions
504
479
  };
505
480
  }
506
-
507
481
  const getHttpStream = async (url, options = {}) => {
508
482
  const fetched = await axios_1.default.get(url.toString(), { ...options, responseType: 'stream' });
509
483
  return fetched.data;
510
484
  };
511
485
  exports.getHttpStream = getHttpStream;
512
-
513
486
  const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
514
487
  const { stream, type } = await (0, exports.getStream)(media, opts);
515
488
  logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
@@ -553,7 +526,6 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
553
526
  }
554
527
  };
555
528
  exports.prepareStream = prepareStream;
556
-
557
529
  const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
558
530
  const { stream, type } = await (0, exports.getStream)(media, opts);
559
531
  logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
@@ -640,7 +612,6 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
640
612
  }
641
613
  };
642
614
  exports.encryptedStream = encryptedStream;
643
-
644
615
  const DEF_HOST = 'mmg.whatsapp.net';
645
616
  const AES_CHUNK_SIZE = 16;
646
617
  const toSmallestChunkSize = (num) => {
@@ -648,7 +619,6 @@ const toSmallestChunkSize = (num) => {
648
619
  };
649
620
  const getUrlFromDirectPath = (directPath) => `https://${DEF_HOST}${directPath}`;
650
621
  exports.getUrlFromDirectPath = getUrlFromDirectPath;
651
-
652
622
  const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
653
623
  const isValidMediaUrl = url === null || url === void 0 ? void 0 : url.startsWith('https://mmg.whatsapp.net/');
654
624
  const downloadUrl = isValidMediaUrl ? url : (0, exports.getUrlFromDirectPath)(directPath);
@@ -659,7 +629,6 @@ const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, o
659
629
  return (0, exports.downloadEncryptedContent)(downloadUrl, keys, opts);
660
630
  };
661
631
  exports.downloadContentFromMessage = downloadContentFromMessage;
662
-
663
632
  const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startByte, endByte, options } = {}) => {
664
633
  let bytesFetched = 0;
665
634
  let startChunk = 0;
@@ -740,7 +709,6 @@ const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startB
740
709
  return fetched.pipe(output, { end: true });
741
710
  };
742
711
  exports.downloadEncryptedContent = downloadEncryptedContent;
743
-
744
712
  function extensionForMediaMessage(message) {
745
713
  const getExtension = (mimetype) => mimetype.split(';')[0].split('/')[1];
746
714
  const type = Object.keys(message)[0];
@@ -756,7 +724,6 @@ function extensionForMediaMessage(message) {
756
724
  }
757
725
  return extension;
758
726
  }
759
-
760
727
  const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
761
728
  return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
762
729
  var _a, _b;
@@ -764,14 +731,6 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
764
731
  let urls;
765
732
  const hosts = [...customUploadHosts, ...uploadInfo.hosts];
766
733
  const chunks = [];
767
-
768
- try {
769
- stream = toAsyncIterable_1.toAsyncIterable(stream);
770
- } catch (error) {
771
- throw new boom_1.Boom(error.message, { statusCode: 400 });
772
- }
773
- // --------------------------------------------------------
774
-
775
734
  if (!Buffer.isBuffer(stream)) {
776
735
  for await (const chunk of stream) {
777
736
  chunks.push(chunk);
@@ -779,20 +738,10 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
779
738
  }
780
739
  const reqBody = Buffer.isBuffer(stream) ? stream : Buffer.concat(chunks);
781
740
  fileEncSha256B64 = (0, exports.encodeBase64EncodedStringForUpload)(fileEncSha256B64);
782
-
783
741
  let media = Defaults_1.MEDIA_PATH_MAP[mediaType];
784
- if (mediaType === 'sticker-pack') {
785
- media = '/mms/image';
786
- }
787
-
788
742
  if (newsletter) {
789
- if (media) {
790
- media = media.replace('/mms/', '/newsletter/newsletter-');
791
- } else {
792
- media = '/newsletter/newsletter-image';
793
- }
743
+ media = media === null || media === void 0 ? void 0 : media.replace('/mms/', '/newsletter/newsletter-');
794
744
  }
795
-
796
745
  for (const { hostname, maxContentLengthBytes } of hosts) {
797
746
  logger.debug(`uploading to "${hostname}"`);
798
747
  const auth = encodeURIComponent(uploadInfo.auth);
@@ -843,8 +792,7 @@ const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options },
843
792
  return urls;
844
793
  };
845
794
  };
846
- exports.getWAUploadToServer = getWAUploadToServer;
847
-
795
+ exports.getWAUploadToServer = getWAUploadToServer;
848
796
  const getMediaRetryKey = (mediaKey) => {
849
797
  return (0, crypto_1.hkdf)(mediaKey, 32, { info: 'WhatsApp Media Retry Notification' });
850
798
  };
@@ -883,7 +831,6 @@ const encryptMediaRetryRequest = async (key, mediaKey, meId) => {
883
831
  return req;
884
832
  };
885
833
  exports.encryptMediaRetryRequest = encryptMediaRetryRequest;
886
-
887
834
  const decodeMediaRetryNode = (node) => {
888
835
  const rmrNode = (0, WABinary_1.getBinaryNodeChild)(node, 'rmr');
889
836
  const event = {
@@ -913,20 +860,20 @@ const decodeMediaRetryNode = (node) => {
913
860
  return event;
914
861
  };
915
862
  exports.decodeMediaRetryNode = decodeMediaRetryNode;
916
-
917
863
  const decryptMediaRetryData = async ({ ciphertext, iv }, mediaKey, msgId) => {
918
864
  const retryKey = await getMediaRetryKey(mediaKey);
919
865
  const plaintext = (0, crypto_1.aesDecryptGCM)(ciphertext, retryKey, iv, Buffer.from(msgId));
920
866
  return WAProto_1.proto.MediaRetryNotification.decode(plaintext);
921
867
  };
922
868
  exports.decryptMediaRetryData = decryptMediaRetryData;
923
-
924
869
  const getStatusCodeForMediaRetry = (code) => MEDIA_RETRY_STATUS_MAP[code];
925
870
  exports.getStatusCodeForMediaRetry = getStatusCodeForMediaRetry;
926
-
927
871
  const MEDIA_RETRY_STATUS_MAP = {
928
872
  [WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
929
873
  [WAProto_1.proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
930
874
  [WAProto_1.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
931
875
  [WAProto_1.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418,
932
876
  };
877
+ function __importStar(arg0) {
878
+ throw new Error('Function not implemented.');
879
+ }
@@ -2,29 +2,11 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- Object.defineProperty(exports, "__esModule", { value: true })
6
- const getImageProcessingLibrary = async () => {
7
- const lib = {};
8
- try {
9
- lib.sharp = require('sharp');
10
- } catch {}
11
- try {
12
- lib.jimp = require('jimp');
13
- } catch {}
14
- return lib;
15
- };
16
- const isWebPBuffer = (buffer) => {
17
- return buffer.length >= 12 && buffer.toString('ascii', 8, 12) === 'WEBP';
18
- };
19
- const isAnimatedWebP = (buffer) => {
20
- if (!isWebPBuffer(buffer)) return false;
21
- return buffer.includes(Buffer.from("ANIM"));
22
- };
23
- exports.prepareStickerPackMessage = exports.assertMediaContent = exports.downloadMediaMessage = exports.aggregateMessageKeysNotFromMe = exports.updateMessageWithPollUpdate = exports.updateMessageWithReaction = exports.updateMessageWithReceipt = exports.getDevice = exports.extractMessageContent = exports.normalizeMessageContent = exports.getContentType = exports.generateWAMessage = exports.generateWAMessageFromContent = exports.generateWAMessageContent = exports.generateForwardMessageContent = exports.prepareDisappearingMessageSettingContent = exports.prepareWAMessageMedia = exports.generateLinkPreviewIfRequired = exports.extractUrlFromText = void 0;
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.assertMediaContent = exports.downloadMediaMessage = exports.aggregateMessageKeysNotFromMe = exports.updateMessageWithPollUpdate = exports.updateMessageWithReaction = exports.updateMessageWithReceipt = exports.getDevice = exports.extractMessageContent = exports.normalizeMessageContent = exports.getContentType = exports.generateWAMessage = exports.generateWAMessageFromContent = exports.generateWAMessageContent = exports.generateForwardMessageContent = exports.prepareDisappearingMessageSettingContent = exports.prepareWAMessageMedia = exports.generateLinkPreviewIfRequired = exports.extractUrlFromText = void 0;
24
7
  exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage;
25
8
  const boom_1 = require("@hapi/boom");
26
9
  const axios_1 = __importDefault(require("axios"));
27
- const fflate_1 = require("fflate");
28
10
  const crypto_1 = require("crypto");
29
11
  const fs_1 = require("fs");
30
12
  const WAProto_1 = require("../../WAProto");
@@ -41,10 +23,6 @@ const MIMETYPE_MAP = {
41
23
  audio: 'audio/ogg; codecs=opus',
42
24
  sticker: 'image/webp',
43
25
  'product-catalog-image': 'image/jpeg',
44
- 'sticker-pack': 'application/x-zip-compressed',
45
- "ptv": "video/mp4",
46
- "newsletter-image": "image/jpeg",
47
- "newsletter-video": "video/mp4"
48
26
  };
49
27
  const MessageTypeProto = {
50
28
  'image': Types_1.WAProto.Message.ImageMessage,
@@ -88,53 +66,36 @@ const assertColor = async (color) => {
88
66
  return assertedColor;
89
67
  }
90
68
  };
91
- const prepareWAMessageMedia = async (message, options) => {
69
+ const prepareWAMessageMedia = async (message, options) => {
92
70
  const logger = options.logger;
93
71
  let mediaType;
94
-
95
72
  for (const key of Defaults_1.MEDIA_KEYS) {
96
73
  if (key in message) {
97
74
  mediaType = key;
98
75
  }
99
76
  }
100
-
101
- if (!mediaType && 'ptv' in message) {
102
- mediaType = 'ptv';
103
- }
104
-
105
77
  if (!mediaType) {
106
78
  throw new boom_1.Boom('Invalid media type', { statusCode: 400 });
107
79
  }
108
-
109
- let isPtv = false;
110
- if (mediaType === 'ptv') {
111
- isPtv = true;
112
- mediaType = 'video';
113
- }
114
-
115
80
  const uploadData = {
116
81
  ...message,
117
- media: message[mediaType] || message['ptv']
82
+ media: message[mediaType]
118
83
  };
119
-
120
- if (!(mediaType === 'audio' && uploadData.ptt)) {
121
84
  delete uploadData[mediaType];
122
- }
123
- delete uploadData['ptv'];
124
-
85
+ // check if cacheable + generate cache key
125
86
  const cacheableKey = typeof uploadData.media === 'object' &&
126
87
  ('url' in uploadData.media) &&
127
88
  !!uploadData.media.url &&
128
89
  !!options.mediaCache && (
129
- mediaType + ':' + uploadData.media.url.toString());
130
-
90
+ // generate the key
91
+ mediaType + ':' + uploadData.media.url.toString());
131
92
  if (mediaType === 'document' && !uploadData.fileName) {
132
93
  uploadData.fileName = 'file';
133
94
  }
134
95
  if (!uploadData.mimetype) {
135
96
  uploadData.mimetype = MIMETYPE_MAP[mediaType];
136
97
  }
137
-
98
+ // check for cache hit
138
99
  if (cacheableKey) {
139
100
  const mediaBuff = options.mediaCache.get(cacheableKey);
140
101
  if (mediaBuff) {
@@ -145,91 +106,22 @@ const assertColor = async (color) => {
145
106
  return obj;
146
107
  }
147
108
  }
148
-
149
- const isNewsletter = options.newsletter || (options.jid && (0, WABinary_1.isJidNewsletter)(options.jid));
150
- if (isNewsletter) {
151
- logger === null || logger === void 0 ? void 0 : logger.debug({ key: cacheableKey }, 'Preparing raw media for newsletter');
152
-
153
-
154
- const { bodyPath, fileSha256, fileLength, didSaveToTmpPath, encWriteStream } = await (0, messages_media_1.prepareStream)(
155
- uploadData.media,
156
- options.mediaTypeOverride || mediaType,
157
- { logger, opts: options.options }
158
- );
159
-
160
- const fileEncSha256B64 = fileSha256.toString('base64');
161
- const streamToUpload = bodyPath || encWriteStream;
162
-
163
- const { mediaUrl, directPath } = await options.upload(streamToUpload, {
164
- fileEncSha256B64,
165
- mediaType,
166
- timeoutMs: options.mediaUploadTimeoutMs,
167
- newsletter: true
168
- });
169
-
170
- if (didSaveToTmpPath && bodyPath) {
171
- try {
172
- await fs_1.promises.unlink(bodyPath);
173
- } catch (error) {
174
- logger === null || logger === void 0 ? void 0 : logger.warn('failed to remove tmp file');
175
- }
176
- }
177
-
178
- const obj = Types_1.WAProto.Message.fromObject({
179
- [`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
180
- url: mediaUrl,
181
- directPath,
182
- fileSha256,
183
- fileLength,
184
- ...uploadData,
185
- media: undefined
186
- })
187
- });
188
-
189
- if (mediaType === 'audio' && uploadData.ptt) {
190
- obj.audioMessage.ptt = true;
191
- }
192
-
193
- if (isPtv) {
194
- obj.ptvMessage = obj.videoMessage;
195
- delete obj.videoMessage;
196
- }
197
-
198
- if (obj.stickerMessage) {
199
- obj.stickerMessage.stickerSentTs = Date.now();
200
- }
201
-
202
- if (cacheableKey) {
203
- logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
204
- options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
205
- }
206
-
207
- return obj;
208
- }
209
-
210
109
  const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
211
110
  const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
212
111
  (typeof uploadData['jpegThumbnail'] === 'undefined');
213
112
  const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
214
113
  const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
215
114
  const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
216
-
217
- const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
115
+ const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (options.newsletter ? messages_media_1.prepareStream : messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
218
116
  logger,
219
117
  saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
220
118
  opts: options.options
221
119
  });
222
-
223
- const fileEncSha256B64 = (fileEncSha256 !== null && fileEncSha256 !== void 0 ? fileEncSha256 : fileSha256).toString('base64');
224
-
120
+ // url safe Base64 encode the SHA256 hash of the body
121
+ const fileEncSha256B64 = (options.newsletter ? fileSha256 : fileEncSha256 !== null && fileEncSha256 !== void 0 ? fileEncSha256 : fileSha256).toString('base64');
225
122
  const [{ mediaUrl, directPath, handle }] = await Promise.all([
226
123
  (async () => {
227
- const result = await options.upload(encWriteStream, {
228
- fileEncSha256B64,
229
- mediaType,
230
- timeoutMs: options.mediaUploadTimeoutMs,
231
- newsletter: false
232
- });
124
+ const result = await options.upload(encWriteStream, { fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs });
233
125
  logger === null || logger === void 0 ? void 0 : logger.debug({ mediaType, cacheableKey }, 'uploaded media');
234
126
  return result;
235
127
  })(),
@@ -241,16 +133,21 @@ const assertColor = async (color) => {
241
133
  if (!uploadData.width && originalImageDimensions) {
242
134
  uploadData.width = originalImageDimensions.width;
243
135
  uploadData.height = originalImageDimensions.height;
136
+ logger === null || logger === void 0 ? void 0 : logger.debug('set dimensions');
244
137
  }
138
+ logger === null || logger === void 0 ? void 0 : logger.debug('generated thumbnail');
245
139
  }
246
140
  if (requiresDurationComputation) {
247
141
  uploadData.seconds = await (0, messages_media_1.getAudioDuration)(bodyPath);
142
+ logger === null || logger === void 0 ? void 0 : logger.debug('computed audio duration');
248
143
  }
249
144
  if (requiresWaveformProcessing) {
250
145
  uploadData.waveform = await (0, messages_media_1.getAudioWaveform)(bodyPath, logger);
146
+ logger === null || logger === void 0 ? void 0 : logger.debug('processed waveform');
251
147
  }
252
148
  if (requiresAudioBackground) {
253
149
  uploadData.backgroundArgb = await assertColor(options.backgroundColor);
150
+ logger === null || logger === void 0 ? void 0 : logger.debug('computed backgroundColor audio status');
254
151
  }
255
152
  }
256
153
  catch (error) {
@@ -258,10 +155,11 @@ const assertColor = async (color) => {
258
155
  }
259
156
  })(),
260
157
  ])
261
- .finally(async () => {
158
+ .finally(async () => {
262
159
  if (!Buffer.isBuffer(encWriteStream)) {
263
160
  encWriteStream.destroy();
264
161
  }
162
+ // remove tmp files
265
163
  if (didSaveToTmpPath && bodyPath) {
266
164
  try {
267
165
  await fs_1.promises.access(bodyPath);
@@ -273,7 +171,6 @@ const assertColor = async (color) => {
273
171
  }
274
172
  }
275
173
  });
276
-
277
174
  const obj = Types_1.WAProto.Message.fromObject({
278
175
  [`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
279
176
  url: handle ? undefined : mediaUrl,
@@ -287,20 +184,17 @@ const assertColor = async (color) => {
287
184
  media: undefined
288
185
  })
289
186
  });
290
-
291
- if (isPtv) {
187
+ if (uploadData.ptv) {
292
188
  obj.ptvMessage = obj.videoMessage;
293
189
  delete obj.videoMessage;
294
190
  }
295
-
296
191
  if (cacheableKey) {
192
+ logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
297
193
  options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
298
194
  }
299
195
  return obj;
300
196
  };
301
197
  exports.prepareWAMessageMedia = prepareWAMessageMedia;
302
-
303
-
304
198
  const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
305
199
  ephemeralExpiration = ephemeralExpiration || 0;
306
200
  const content = {
@@ -484,11 +378,9 @@ const generateWAMessageContent = async (message, options) => {
484
378
  break;
485
379
  }
486
380
  }
487
- else if ('ptv' in message && message.ptv) {
488
- const generated = await (0, exports.prepareWAMessageMedia)({
489
- ptv: message.ptv
490
- }, options);
491
- m.ptvMessage = generated.ptvMessage || generated.videoMessage;
381
+ else if ('ptv' in message && message.ptv) {
382
+ const { videoMessage } = await (0, exports.prepareWAMessageMedia)({ video: message.video }, options);
383
+ m.ptvMessage = videoMessage;
492
384
  }
493
385
  else if ('product' in message) {
494
386
  const { imageMessage } = await (0, exports.prepareWAMessageMedia)({ image: message.product.productImage }, options);
@@ -1145,170 +1037,3 @@ const getSenderLid = (message) => {
1145
1037
  return { jid: sender, lid };
1146
1038
  };
1147
1039
  exports.getSenderLid = getSenderLid;
1148
-
1149
- /**
1150
- STICKER PACK FUNCTION RECODE BY
1151
- @RexxHayanasi < Maintainer @rexxhayanasi/elaina-baileys >
1152
- **/
1153
-
1154
- const prepareStickerPackMessage = async (stickerPack, options) => {
1155
- const { stickers, name, publisher, packId, description } = stickerPack;
1156
-
1157
- if (stickers.length > 60) {
1158
- throw new boom_1.Boom('Sticker pack exceeds the maximum limit of 60 stickers', { statusCode: 400 });
1159
- }
1160
-
1161
- if (stickers.length === 0) {
1162
- throw new boom_1.Boom('Sticker pack must contain at least one sticker', { statusCode: 400 });
1163
- }
1164
-
1165
- const stickerPackIdValue = packId || (0, generics_1.generateMessageIDV2)();
1166
- const lib = await getImageProcessingLibrary();
1167
- const stickerData = {};
1168
-
1169
- const stickerPromises = stickers.map(async (s, i) => {
1170
- const { stream } = await (0, messages_media_1.getStream)(s.data);
1171
- const buffer = await (0, generics_1.toBuffer)(stream);
1172
-
1173
- let webpBuffer;
1174
- let isAnimated = false;
1175
- const isWebP = isWebPBuffer(buffer);
1176
-
1177
- if (isWebP) {
1178
- webpBuffer = buffer;
1179
- isAnimated = isAnimatedWebP(buffer);
1180
- } else if (lib.sharp) {
1181
- webpBuffer = await lib.sharp(buffer).webp().toBuffer();
1182
- isAnimated = false;
1183
- } else {
1184
- throw new boom_1.Boom(
1185
- 'No image processing library (sharp) available for converting sticker to WebP. Either install sharp or provide stickers in WebP format.'
1186
- );
1187
- }
1188
-
1189
- if (webpBuffer.length > 1024 * 1024) {
1190
- throw new boom_1.Boom(`Sticker at index ${i} exceeds the 1MB size limit`, { statusCode: 400 });
1191
- }
1192
-
1193
- const hash = (0, crypto_2.sha256)(webpBuffer).toString('base64').replace(/\//g, '-');
1194
- const fileName = `${hash}.webp`;
1195
-
1196
- stickerData[fileName] = [new Uint8Array(webpBuffer), { level: 0 }];
1197
-
1198
- return {
1199
- fileName,
1200
- mimetype: 'image/webp',
1201
- isAnimated,
1202
- emojis: s.emojis || [],
1203
- accessibilityLabel: s.accessibilityLabel
1204
- };
1205
- });
1206
-
1207
- const stickerMetadata = await Promise.all(stickerPromises);
1208
-
1209
- const trayIconFileName = `${stickerPackIdValue}.webp`;
1210
- const { stream: coverStream } = await (0, messages_media_1.getStream)(stickerPack.cover);
1211
- const coverBuffer = await (0, generics_1.toBuffer)(coverStream);
1212
-
1213
- let coverWebpBuffer;
1214
- const isCoverWebP = isWebPBuffer(coverBuffer);
1215
-
1216
- if (isCoverWebP) {
1217
- coverWebpBuffer = coverBuffer;
1218
- } else if (lib.sharp) {
1219
- coverWebpBuffer = await lib.sharp(coverBuffer).webp().toBuffer();
1220
- } else {
1221
- throw new boom_1.Boom(
1222
- 'No image processing library (sharp) available for converting cover to WebP. Either install sharp or provide cover in WebP format.'
1223
- );
1224
- }
1225
-
1226
- stickerData[trayIconFileName] = [new Uint8Array(coverWebpBuffer), { level: 0 }];
1227
-
1228
- const zipBuffer = await new Promise((resolve, reject) => {
1229
- (0, fflate_1.zip)(stickerData, (err, data) => {
1230
- if (err) {
1231
- reject(err);
1232
- } else {
1233
- resolve(Buffer.from(data));
1234
- }
1235
- });
1236
- });
1237
-
1238
- const stickerPackSize = zipBuffer.length;
1239
-
1240
- const stickerPackUpload = await (0, messages_media_1.encryptedStream)(zipBuffer, 'sticker-pack', {
1241
- logger: options.logger,
1242
- opts: options.options
1243
- });
1244
-
1245
- const stickerPackUploadResult = await options.upload(stickerPackUpload.encFilePath, {
1246
- fileEncSha256B64: stickerPackUpload.fileEncSha256.toString('base64'),
1247
- mediaType: 'sticker-pack',
1248
- timeoutMs: options.mediaUploadTimeoutMs
1249
- });
1250
-
1251
- await fs_1.promises.unlink(stickerPackUpload.encFilePath);
1252
-
1253
- const stickerPackMessage = {
1254
- name: name,
1255
- publisher: publisher,
1256
- stickerPackId: stickerPackIdValue,
1257
- packDescription: description,
1258
- stickerPackOrigin: WAProto_1.proto.Message.StickerPackMessage.StickerPackOrigin.USER_CREATED,
1259
- stickerPackSize: stickerPackSize,
1260
- stickers: stickerMetadata,
1261
- fileSha256: stickerPackUpload.fileSha256,
1262
- fileEncSha256: stickerPackUpload.fileEncSha256,
1263
- mediaKey: stickerPackUpload.mediaKey,
1264
- directPath: stickerPackUploadResult.directPath,
1265
- fileLength: stickerPackUpload.fileLength,
1266
- mediaKeyTimestamp: (0, generics_1.unixTimestampSeconds)(),
1267
- trayIconFileName: trayIconFileName
1268
- };
1269
-
1270
- try {
1271
- let thumbnailBuffer;
1272
- if (lib.sharp) {
1273
- thumbnailBuffer = await lib.sharp(coverBuffer).resize(252, 252).jpeg().toBuffer();
1274
- } else if (lib.jimp) {
1275
- const jimpImage = await lib.jimp.read(coverBuffer);
1276
- thumbnailBuffer = await jimpImage.resize(252, 252).getBufferAsync(lib.jimp.MIME_JPEG);
1277
- } else {
1278
- throw new Error('No image processing library available for thumbnail generation');
1279
- }
1280
-
1281
- if (!thumbnailBuffer || thumbnailBuffer.length === 0) {
1282
- throw new Error('Failed to generate thumbnail buffer');
1283
- }
1284
-
1285
- const thumbUpload = await (0, messages_media_1.encryptedStream)(thumbnailBuffer, 'thumbnail-sticker-pack', {
1286
- logger: options.logger,
1287
- opts: options.options,
1288
- mediaKey: stickerPackUpload.mediaKey
1289
- });
1290
-
1291
- const thumbUploadResult = await options.upload(thumbUpload.encFilePath, {
1292
- fileEncSha256B64: thumbUpload.fileEncSha256.toString('base64'),
1293
- mediaType: 'thumbnail-sticker-pack',
1294
- timeoutMs: options.mediaUploadTimeoutMs
1295
- });
1296
-
1297
- await fs_1.promises.unlink(thumbUpload.encFilePath);
1298
-
1299
- Object.assign(stickerPackMessage, {
1300
- thumbnailDirectPath: thumbUploadResult.directPath,
1301
- thumbnailSha256: thumbUpload.fileSha256,
1302
- thumbnailEncSha256: thumbUpload.fileEncSha256,
1303
- thumbnailHeight: 252,
1304
- thumbnailWidth: 252,
1305
- imageDataHash: (0, crypto_2.sha256)(thumbnailBuffer).toString('base64')
1306
- });
1307
-
1308
- } catch (e) {
1309
- options.logger === null || options.logger === void 0 ? void 0 : options.logger.warn(`Thumbnail generation failed: ${e}`);
1310
- }
1311
-
1312
- return { stickerPackMessage };
1313
- };
1314
- exports.prepareStickerPackMessage = prepareStickerPackMessage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexxhayanasi/elaina-baileys",
3
- "version": "1.2.0-rc.9",
3
+ "version": "1.2.0",
4
4
  "description": "Custom Baileys WhatsApp API",
5
5
  "keywords": [
6
6
  "baileys",
@@ -18,7 +18,7 @@
18
18
  "homepage": "https://whatsapp.com/channel/0029Vb70uHbD8SE2w5Q9M107",
19
19
  "license": "MIT",
20
20
  "publishConfig": {
21
- "tag": "experimental"
21
+ "tag": "latest"
22
22
  },
23
23
  "author": "RexxHayanasi",
24
24
  "main": "lib/index.js",