@rexxhayanasi/elaina-baileys 1.1.9 → 1.2.0-rc.2
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/lib/Socket/index.js +9 -35
- package/lib/Utils/async-iterable.js +41 -0
- package/lib/Utils/messages-media.js +58 -5
- package/lib/Utils/messages.js +49 -26
- package/package.json +1 -1
package/lib/Socket/index.js
CHANGED
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
let __ACTIVE_SOCKET__ = null
|
|
9
|
-
|
|
10
|
-
const makeWASocket = (config) => {
|
|
11
|
-
try {
|
|
12
|
-
if (__ACTIVE_SOCKET__) {
|
|
13
|
-
try {
|
|
14
|
-
__ACTIVE_SOCKET__.ev?.removeAllListeners?.()
|
|
15
|
-
__ACTIVE_SOCKET__.ws?.removeAllListeners?.()
|
|
16
|
-
__ACTIVE_SOCKET__.ws?.terminate?.()
|
|
17
|
-
__ACTIVE_SOCKET__.ws?.close?.()
|
|
18
|
-
} catch {}
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
__ACTIVE_SOCKET__ = null
|
|
22
|
-
} catch {}
|
|
23
|
-
}
|
|
24
|
-
} catch {}
|
|
25
|
-
|
|
26
|
-
const sock = makeBusinessSocket({
|
|
27
|
-
...DEFAULT_CONNECTION_CONFIG,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Defaults_1 = require("../Defaults");
|
|
4
|
+
const business_1 = require("./business");
|
|
5
|
+
// export the last socket layer
|
|
6
|
+
const makeWASocket = (config) => ((0, business_1.makeBusinessSocket)({
|
|
7
|
+
...Defaults_1.DEFAULT_CONNECTION_CONFIG,
|
|
28
8
|
...config
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
__ACTIVE_SOCKET__ = sock
|
|
32
|
-
|
|
33
|
-
return sock
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
exports.default = makeWASocket
|
|
9
|
+
}));
|
|
10
|
+
exports.default = makeWASocket;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toAsyncIterable = void 0;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Helper by @rexxhayanasi to convert various media inputs into an Async Iterable
|
|
7
|
+
* Compatible with Baileys buffer/stream handling
|
|
8
|
+
*/
|
|
9
|
+
function toAsyncIterable(input) {
|
|
10
|
+
if (!input) {
|
|
11
|
+
throw new Error("Invalid media stream (undefined/null)");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (input[Symbol.asyncIterator]) {
|
|
15
|
+
return input;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
if (Buffer.isBuffer(input)) {
|
|
20
|
+
return (async function* () {
|
|
21
|
+
yield input;
|
|
22
|
+
})();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (typeof input === "string") {
|
|
26
|
+
const fs = require("fs");
|
|
27
|
+
return fs.createReadStream(input);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (typeof input.on === "function") {
|
|
31
|
+
return (async function* () {
|
|
32
|
+
for await (const chunk of input) {
|
|
33
|
+
yield chunk;
|
|
34
|
+
}
|
|
35
|
+
})();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
throw new Error("Unsupported media stream type");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.toAsyncIterable = toAsyncIterable;
|
|
@@ -61,6 +61,8 @@ 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
|
+
|
|
64
66
|
const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
|
|
65
67
|
const getImageProcessingLibrary = async () => {
|
|
66
68
|
const [_jimp, sharp] = await Promise.all([
|
|
@@ -82,13 +84,26 @@ const getImageProcessingLibrary = async () => {
|
|
|
82
84
|
}
|
|
83
85
|
throw new boom_1.Boom('No image processing library available');
|
|
84
86
|
};
|
|
87
|
+
|
|
85
88
|
const hkdfInfoKey = (type) => {
|
|
86
89
|
if (type === 'sticker-pack') return 'WhatsApp Image Keys';
|
|
87
90
|
if (type === 'ptv') return 'WhatsApp Video Keys';
|
|
91
|
+
|
|
92
|
+
// Support Newsletter keys explicitly or fallback
|
|
93
|
+
if (type === 'newsletter-image') return 'WhatsApp Image Keys';
|
|
94
|
+
if (type === 'newsletter-video') return 'WhatsApp Video Keys';
|
|
95
|
+
|
|
88
96
|
const hkdfInfo = Defaults_1.MEDIA_HKDF_KEY_MAPPING[type];
|
|
97
|
+
|
|
98
|
+
// Fallback if type not found to prevent undefined key error
|
|
99
|
+
if (!hkdfInfo) {
|
|
100
|
+
return 'WhatsApp Image Keys';
|
|
101
|
+
}
|
|
102
|
+
|
|
89
103
|
return `WhatsApp ${hkdfInfo} Keys`;
|
|
90
104
|
};
|
|
91
105
|
exports.hkdfInfoKey = hkdfInfoKey;
|
|
106
|
+
|
|
92
107
|
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
93
108
|
async function getMediaKeys(buffer, mediaType) {
|
|
94
109
|
if (!buffer) {
|
|
@@ -105,6 +120,7 @@ async function getMediaKeys(buffer, mediaType) {
|
|
|
105
120
|
macKey: expandedMediaKey.slice(48, 80),
|
|
106
121
|
};
|
|
107
122
|
}
|
|
123
|
+
|
|
108
124
|
async function uploadFile(buffer, logger) {
|
|
109
125
|
const { fromBuffer } = await Promise.resolve().then(() => __importStar(require('file-type')));
|
|
110
126
|
const fileType = await fromBuffer(buffer);
|
|
@@ -209,6 +225,7 @@ async function uploadFile(buffer, logger) {
|
|
|
209
225
|
}
|
|
210
226
|
throw new Error("All upload services failed.");
|
|
211
227
|
}
|
|
228
|
+
|
|
212
229
|
async function vid2jpg(videoUrl) {
|
|
213
230
|
try {
|
|
214
231
|
const { data } = await axios_1.default.get(`https://ezgif.com/video-to-jpg?url=${encodeURIComponent(videoUrl)}`);
|
|
@@ -245,6 +262,7 @@ async function vid2jpg(videoUrl) {
|
|
|
245
262
|
throw new Error("Failed to convert video to JPG: " + error.message);
|
|
246
263
|
}
|
|
247
264
|
}
|
|
265
|
+
|
|
248
266
|
/**
|
|
249
267
|
* Extracts video thumbnail using FFmpeg
|
|
250
268
|
*/
|
|
@@ -275,6 +293,7 @@ const extractVideoThumb = async (videoPath, time = '00:00:00', size = { width: 2
|
|
|
275
293
|
});
|
|
276
294
|
};
|
|
277
295
|
exports.extractVideoThumb = extractVideoThumb;
|
|
296
|
+
|
|
278
297
|
const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
279
298
|
var _a, _b;
|
|
280
299
|
if (bufferOrFilePath instanceof stream_1.Readable) {
|
|
@@ -317,11 +336,13 @@ const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
317
336
|
}
|
|
318
337
|
};
|
|
319
338
|
exports.extractImageThumb = extractImageThumb;
|
|
339
|
+
|
|
320
340
|
const encodeBase64EncodedStringForUpload = (b64) => (encodeURIComponent(b64
|
|
321
341
|
.replace(/\+/g, '-')
|
|
322
342
|
.replace(/\//g, '_')
|
|
323
343
|
.replace(/\=+$/, '')));
|
|
324
344
|
exports.encodeBase64EncodedStringForUpload = encodeBase64EncodedStringForUpload;
|
|
345
|
+
|
|
325
346
|
const generateProfilePicture = async (mediaUpload) => {
|
|
326
347
|
let bufferOrFilePath;
|
|
327
348
|
let img;
|
|
@@ -344,12 +365,14 @@ const generateProfilePicture = async (mediaUpload) => {
|
|
|
344
365
|
};
|
|
345
366
|
};
|
|
346
367
|
exports.generateProfilePicture = generateProfilePicture;
|
|
368
|
+
|
|
347
369
|
/** gets the SHA256 of the given media message */
|
|
348
370
|
const mediaMessageSHA256B64 = (message) => {
|
|
349
371
|
const media = Object.values(message)[0];
|
|
350
372
|
return (media === null || media === void 0 ? void 0 : media.fileSha256) && Buffer.from(media.fileSha256).toString('base64');
|
|
351
373
|
};
|
|
352
374
|
exports.mediaMessageSHA256B64 = mediaMessageSHA256B64;
|
|
375
|
+
|
|
353
376
|
async function getAudioDuration(buffer) {
|
|
354
377
|
const musicMetadata = await Promise.resolve().then(() => __importStar(require('music-metadata')));
|
|
355
378
|
let metadata;
|
|
@@ -367,6 +390,7 @@ async function getAudioDuration(buffer) {
|
|
|
367
390
|
}
|
|
368
391
|
return metadata.format.duration;
|
|
369
392
|
}
|
|
393
|
+
|
|
370
394
|
async function getAudioWaveform(buffer, logger) {
|
|
371
395
|
try {
|
|
372
396
|
const { default: decoder } = await eval('import(\'audio-decode\')');
|
|
@@ -403,6 +427,7 @@ async function getAudioWaveform(buffer, logger) {
|
|
|
403
427
|
logger === null || logger === void 0 ? void 0 : logger.debug('Failed to generate waveform: ' + e);
|
|
404
428
|
}
|
|
405
429
|
}
|
|
430
|
+
|
|
406
431
|
const toReadable = (buffer) => {
|
|
407
432
|
const readable = new stream_1.Readable({ read: () => { } });
|
|
408
433
|
readable.push(buffer);
|
|
@@ -410,6 +435,7 @@ const toReadable = (buffer) => {
|
|
|
410
435
|
return readable;
|
|
411
436
|
};
|
|
412
437
|
exports.toReadable = toReadable;
|
|
438
|
+
|
|
413
439
|
const toBuffer = async (stream) => {
|
|
414
440
|
const chunks = [];
|
|
415
441
|
for await (const chunk of stream) {
|
|
@@ -419,6 +445,7 @@ const toBuffer = async (stream) => {
|
|
|
419
445
|
return Buffer.concat(chunks);
|
|
420
446
|
};
|
|
421
447
|
exports.toBuffer = toBuffer;
|
|
448
|
+
|
|
422
449
|
const getStream = async (item, opts) => {
|
|
423
450
|
if (Buffer.isBuffer(item)) {
|
|
424
451
|
return { stream: (0, exports.toReadable)(item), type: 'buffer' };
|
|
@@ -432,6 +459,7 @@ const getStream = async (item, opts) => {
|
|
|
432
459
|
return { stream: (0, fs_1.createReadStream)(item.url), type: 'file' };
|
|
433
460
|
};
|
|
434
461
|
exports.getStream = getStream;
|
|
462
|
+
|
|
435
463
|
/** generates a thumbnail for a given media, if required */
|
|
436
464
|
async function generateThumbnail(file, mediaType, options) {
|
|
437
465
|
var _a;
|
|
@@ -480,11 +508,13 @@ async function generateThumbnail(file, mediaType, options) {
|
|
|
480
508
|
originalImageDimensions
|
|
481
509
|
};
|
|
482
510
|
}
|
|
511
|
+
|
|
483
512
|
const getHttpStream = async (url, options = {}) => {
|
|
484
513
|
const fetched = await axios_1.default.get(url.toString(), { ...options, responseType: 'stream' });
|
|
485
514
|
return fetched.data;
|
|
486
515
|
};
|
|
487
516
|
exports.getHttpStream = getHttpStream;
|
|
517
|
+
|
|
488
518
|
const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
|
489
519
|
const { stream, type } = await (0, exports.getStream)(media, opts);
|
|
490
520
|
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
|
@@ -528,6 +558,7 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
|
|
|
528
558
|
}
|
|
529
559
|
};
|
|
530
560
|
exports.prepareStream = prepareStream;
|
|
561
|
+
|
|
531
562
|
const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfRequired, opts } = {}) => {
|
|
532
563
|
const { stream, type } = await (0, exports.getStream)(media, opts);
|
|
533
564
|
logger === null || logger === void 0 ? void 0 : logger.debug('fetched media stream');
|
|
@@ -614,6 +645,7 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
|
|
|
614
645
|
}
|
|
615
646
|
};
|
|
616
647
|
exports.encryptedStream = encryptedStream;
|
|
648
|
+
|
|
617
649
|
const DEF_HOST = 'mmg.whatsapp.net';
|
|
618
650
|
const AES_CHUNK_SIZE = 16;
|
|
619
651
|
const toSmallestChunkSize = (num) => {
|
|
@@ -621,6 +653,7 @@ const toSmallestChunkSize = (num) => {
|
|
|
621
653
|
};
|
|
622
654
|
const getUrlFromDirectPath = (directPath) => `https://${DEF_HOST}${directPath}`;
|
|
623
655
|
exports.getUrlFromDirectPath = getUrlFromDirectPath;
|
|
656
|
+
|
|
624
657
|
const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
|
|
625
658
|
const isValidMediaUrl = url === null || url === void 0 ? void 0 : url.startsWith('https://mmg.whatsapp.net/');
|
|
626
659
|
const downloadUrl = isValidMediaUrl ? url : (0, exports.getUrlFromDirectPath)(directPath);
|
|
@@ -631,6 +664,7 @@ const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, o
|
|
|
631
664
|
return (0, exports.downloadEncryptedContent)(downloadUrl, keys, opts);
|
|
632
665
|
};
|
|
633
666
|
exports.downloadContentFromMessage = downloadContentFromMessage;
|
|
667
|
+
|
|
634
668
|
const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startByte, endByte, options } = {}) => {
|
|
635
669
|
let bytesFetched = 0;
|
|
636
670
|
let startChunk = 0;
|
|
@@ -711,6 +745,7 @@ const downloadEncryptedContent = async (downloadUrl, { cipherKey, iv }, { startB
|
|
|
711
745
|
return fetched.pipe(output, { end: true });
|
|
712
746
|
};
|
|
713
747
|
exports.downloadEncryptedContent = downloadEncryptedContent;
|
|
748
|
+
|
|
714
749
|
function extensionForMediaMessage(message) {
|
|
715
750
|
const getExtension = (mimetype) => mimetype.split(';')[0].split('/')[1];
|
|
716
751
|
const type = Object.keys(message)[0];
|
|
@@ -726,13 +761,24 @@ function extensionForMediaMessage(message) {
|
|
|
726
761
|
}
|
|
727
762
|
return extension;
|
|
728
763
|
}
|
|
729
|
-
|
|
764
|
+
|
|
765
|
+
const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, options }, refreshMediaConn) => {
|
|
730
766
|
return async (stream, { mediaType, fileEncSha256B64, newsletter, timeoutMs }) => {
|
|
731
767
|
var _a, _b;
|
|
732
768
|
let uploadInfo = await refreshMediaConn(false);
|
|
733
769
|
let urls;
|
|
734
770
|
const hosts = [...customUploadHosts, ...uploadInfo.hosts];
|
|
735
771
|
const chunks = [];
|
|
772
|
+
|
|
773
|
+
// --- MODIFIKASI: Panggil via objek toAsyncIterable_1 ---
|
|
774
|
+
try {
|
|
775
|
+
// Kita akses properti .toAsyncIterable karena diimpor sebagai objek
|
|
776
|
+
stream = toAsyncIterable_1.toAsyncIterable(stream);
|
|
777
|
+
} catch (error) {
|
|
778
|
+
throw new boom_1.Boom(error.message, { statusCode: 400 });
|
|
779
|
+
}
|
|
780
|
+
// --------------------------------------------------------
|
|
781
|
+
|
|
736
782
|
if (!Buffer.isBuffer(stream)) {
|
|
737
783
|
for await (const chunk of stream) {
|
|
738
784
|
chunks.push(chunk);
|
|
@@ -745,8 +791,13 @@ function extensionForMediaMessage(message) {
|
|
|
745
791
|
if (mediaType === 'sticker-pack') {
|
|
746
792
|
media = '/mms/image';
|
|
747
793
|
}
|
|
794
|
+
|
|
748
795
|
if (newsletter) {
|
|
749
|
-
|
|
796
|
+
if (media) {
|
|
797
|
+
media = media.replace('/mms/', '/newsletter/newsletter-');
|
|
798
|
+
} else {
|
|
799
|
+
media = '/newsletter/newsletter-image';
|
|
800
|
+
}
|
|
750
801
|
}
|
|
751
802
|
|
|
752
803
|
for (const { hostname, maxContentLengthBytes } of hosts) {
|
|
@@ -800,6 +851,7 @@ function extensionForMediaMessage(message) {
|
|
|
800
851
|
};
|
|
801
852
|
};
|
|
802
853
|
exports.getWAUploadToServer = getWAUploadToServer;
|
|
854
|
+
|
|
803
855
|
const getMediaRetryKey = (mediaKey) => {
|
|
804
856
|
return (0, crypto_1.hkdf)(mediaKey, 32, { info: 'WhatsApp Media Retry Notification' });
|
|
805
857
|
};
|
|
@@ -838,6 +890,7 @@ const encryptMediaRetryRequest = async (key, mediaKey, meId) => {
|
|
|
838
890
|
return req;
|
|
839
891
|
};
|
|
840
892
|
exports.encryptMediaRetryRequest = encryptMediaRetryRequest;
|
|
893
|
+
|
|
841
894
|
const decodeMediaRetryNode = (node) => {
|
|
842
895
|
const rmrNode = (0, WABinary_1.getBinaryNodeChild)(node, 'rmr');
|
|
843
896
|
const event = {
|
|
@@ -867,20 +920,20 @@ const decodeMediaRetryNode = (node) => {
|
|
|
867
920
|
return event;
|
|
868
921
|
};
|
|
869
922
|
exports.decodeMediaRetryNode = decodeMediaRetryNode;
|
|
923
|
+
|
|
870
924
|
const decryptMediaRetryData = async ({ ciphertext, iv }, mediaKey, msgId) => {
|
|
871
925
|
const retryKey = await getMediaRetryKey(mediaKey);
|
|
872
926
|
const plaintext = (0, crypto_1.aesDecryptGCM)(ciphertext, retryKey, iv, Buffer.from(msgId));
|
|
873
927
|
return WAProto_1.proto.MediaRetryNotification.decode(plaintext);
|
|
874
928
|
};
|
|
875
929
|
exports.decryptMediaRetryData = decryptMediaRetryData;
|
|
930
|
+
|
|
876
931
|
const getStatusCodeForMediaRetry = (code) => MEDIA_RETRY_STATUS_MAP[code];
|
|
877
932
|
exports.getStatusCodeForMediaRetry = getStatusCodeForMediaRetry;
|
|
933
|
+
|
|
878
934
|
const MEDIA_RETRY_STATUS_MAP = {
|
|
879
935
|
[WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS]: 200,
|
|
880
936
|
[WAProto_1.proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
|
|
881
937
|
[WAProto_1.proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
|
|
882
938
|
[WAProto_1.proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418,
|
|
883
939
|
};
|
|
884
|
-
function __importStar(arg0) {
|
|
885
|
-
throw new Error('Function not implemented.');
|
|
886
|
-
}
|
package/lib/Utils/messages.js
CHANGED
|
@@ -41,7 +41,10 @@ const MIMETYPE_MAP = {
|
|
|
41
41
|
audio: 'audio/ogg; codecs=opus',
|
|
42
42
|
sticker: 'image/webp',
|
|
43
43
|
'product-catalog-image': 'image/jpeg',
|
|
44
|
-
'sticker-pack': 'application/x-zip-compressed'
|
|
44
|
+
'sticker-pack': 'application/x-zip-compressed',
|
|
45
|
+
"ptv": "video/mp4",
|
|
46
|
+
"newsletter-image": "image/jpeg",
|
|
47
|
+
"newsletter-video": "video/mp4"
|
|
45
48
|
};
|
|
46
49
|
const MessageTypeProto = {
|
|
47
50
|
'image': Types_1.WAProto.Message.ImageMessage,
|
|
@@ -85,36 +88,51 @@ const assertColor = async (color) => {
|
|
|
85
88
|
return assertedColor;
|
|
86
89
|
}
|
|
87
90
|
};
|
|
88
|
-
const prepareWAMessageMedia = async (message, options) => {
|
|
91
|
+
const prepareWAMessageMedia = async (message, options) => {
|
|
89
92
|
const logger = options.logger;
|
|
90
93
|
let mediaType;
|
|
94
|
+
|
|
91
95
|
for (const key of Defaults_1.MEDIA_KEYS) {
|
|
92
96
|
if (key in message) {
|
|
93
97
|
mediaType = key;
|
|
94
98
|
}
|
|
95
99
|
}
|
|
100
|
+
|
|
101
|
+
if (!mediaType && 'ptv' in message) {
|
|
102
|
+
mediaType = 'ptv';
|
|
103
|
+
}
|
|
104
|
+
|
|
96
105
|
if (!mediaType) {
|
|
97
106
|
throw new boom_1.Boom('Invalid media type', { statusCode: 400 });
|
|
98
107
|
}
|
|
108
|
+
|
|
109
|
+
let isPtv = false;
|
|
110
|
+
if (mediaType === 'ptv') {
|
|
111
|
+
isPtv = true;
|
|
112
|
+
mediaType = 'video';
|
|
113
|
+
}
|
|
114
|
+
|
|
99
115
|
const uploadData = {
|
|
100
116
|
...message,
|
|
101
|
-
media: message[mediaType]
|
|
117
|
+
media: message[mediaType] || message['ptv']
|
|
102
118
|
};
|
|
119
|
+
|
|
103
120
|
delete uploadData[mediaType];
|
|
104
|
-
|
|
121
|
+
delete uploadData['ptv'];
|
|
122
|
+
|
|
105
123
|
const cacheableKey = typeof uploadData.media === 'object' &&
|
|
106
124
|
('url' in uploadData.media) &&
|
|
107
125
|
!!uploadData.media.url &&
|
|
108
126
|
!!options.mediaCache && (
|
|
109
127
|
mediaType + ':' + uploadData.media.url.toString());
|
|
110
|
-
|
|
128
|
+
|
|
111
129
|
if (mediaType === 'document' && !uploadData.fileName) {
|
|
112
130
|
uploadData.fileName = 'file';
|
|
113
131
|
}
|
|
114
132
|
if (!uploadData.mimetype) {
|
|
115
133
|
uploadData.mimetype = MIMETYPE_MAP[mediaType];
|
|
116
134
|
}
|
|
117
|
-
|
|
135
|
+
|
|
118
136
|
if (cacheableKey) {
|
|
119
137
|
const mediaBuff = options.mediaCache.get(cacheableKey);
|
|
120
138
|
if (mediaBuff) {
|
|
@@ -130,20 +148,20 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
130
148
|
|
|
131
149
|
if (isNewsletter) {
|
|
132
150
|
logger === null || logger === void 0 ? void 0 : logger.debug({ key: cacheableKey }, 'Preparing raw media for newsletter');
|
|
133
|
-
|
|
151
|
+
|
|
134
152
|
const { bodyPath, fileSha256, fileLength, didSaveToTmpPath } = await (0, messages_media_1.prepareStream)(
|
|
135
|
-
uploadData.media,
|
|
136
|
-
options.mediaTypeOverride || mediaType,
|
|
153
|
+
uploadData.media,
|
|
154
|
+
options.mediaTypeOverride || mediaType,
|
|
137
155
|
{ logger, opts: options.options }
|
|
138
156
|
);
|
|
139
157
|
|
|
140
158
|
const fileEncSha256B64 = fileSha256.toString('base64');
|
|
141
|
-
|
|
142
|
-
const { mediaUrl, directPath } = await options.upload(bodyPath, {
|
|
143
|
-
fileEncSha256B64,
|
|
144
|
-
mediaType,
|
|
159
|
+
|
|
160
|
+
const { mediaUrl, directPath } = await options.upload(bodyPath, {
|
|
161
|
+
fileEncSha256B64,
|
|
162
|
+
mediaType,
|
|
145
163
|
timeoutMs: options.mediaUploadTimeoutMs,
|
|
146
|
-
newsletter: true
|
|
164
|
+
newsletter: true
|
|
147
165
|
});
|
|
148
166
|
|
|
149
167
|
if (didSaveToTmpPath && bodyPath) {
|
|
@@ -165,7 +183,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
165
183
|
})
|
|
166
184
|
});
|
|
167
185
|
|
|
168
|
-
if (
|
|
186
|
+
if (isPtv) {
|
|
169
187
|
obj.ptvMessage = obj.videoMessage;
|
|
170
188
|
delete obj.videoMessage;
|
|
171
189
|
}
|
|
@@ -188,18 +206,23 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
188
206
|
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
|
|
189
207
|
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
190
208
|
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
191
|
-
|
|
209
|
+
|
|
192
210
|
const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath, } = await (0, messages_media_1.encryptedStream)(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
193
211
|
logger,
|
|
194
212
|
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
195
213
|
opts: options.options
|
|
196
214
|
});
|
|
197
|
-
|
|
215
|
+
|
|
198
216
|
const fileEncSha256B64 = (fileEncSha256 !== null && fileEncSha256 !== void 0 ? fileEncSha256 : fileSha256).toString('base64');
|
|
199
|
-
|
|
217
|
+
|
|
200
218
|
const [{ mediaUrl, directPath, handle }] = await Promise.all([
|
|
201
219
|
(async () => {
|
|
202
|
-
const result = await options.upload(encWriteStream, {
|
|
220
|
+
const result = await options.upload(encWriteStream, {
|
|
221
|
+
fileEncSha256B64,
|
|
222
|
+
mediaType,
|
|
223
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
224
|
+
newsletter: false
|
|
225
|
+
});
|
|
203
226
|
logger === null || logger === void 0 ? void 0 : logger.debug({ mediaType, cacheableKey }, 'uploaded media');
|
|
204
227
|
return result;
|
|
205
228
|
})(),
|
|
@@ -258,7 +281,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
258
281
|
})
|
|
259
282
|
});
|
|
260
283
|
|
|
261
|
-
if (
|
|
284
|
+
if (isPtv) {
|
|
262
285
|
obj.ptvMessage = obj.videoMessage;
|
|
263
286
|
delete obj.videoMessage;
|
|
264
287
|
}
|
|
@@ -270,6 +293,7 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
270
293
|
};
|
|
271
294
|
exports.prepareWAMessageMedia = prepareWAMessageMedia;
|
|
272
295
|
|
|
296
|
+
|
|
273
297
|
const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
|
|
274
298
|
ephemeralExpiration = ephemeralExpiration || 0;
|
|
275
299
|
const content = {
|
|
@@ -453,12 +477,11 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
453
477
|
break;
|
|
454
478
|
}
|
|
455
479
|
}
|
|
456
|
-
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
ptv: true
|
|
480
|
+
else if ('ptv' in message && message.ptv) {
|
|
481
|
+
const generated = await (0, exports.prepareWAMessageMedia)({
|
|
482
|
+
ptv: message.ptv
|
|
460
483
|
}, options);
|
|
461
|
-
m.ptvMessage = ptvMessage;
|
|
484
|
+
m.ptvMessage = generated.ptvMessage || generated.videoMessage;
|
|
462
485
|
}
|
|
463
486
|
else if ('product' in message) {
|
|
464
487
|
const { imageMessage } = await (0, exports.prepareWAMessageMedia)({ image: message.product.productImage }, options);
|
|
@@ -1281,4 +1304,4 @@ const prepareStickerPackMessage = async (stickerPack, options) => {
|
|
|
1281
1304
|
|
|
1282
1305
|
return { stickerPackMessage };
|
|
1283
1306
|
};
|
|
1284
|
-
exports.prepareStickerPackMessage = prepareStickerPackMessage;
|
|
1307
|
+
exports.prepareStickerPackMessage = prepareStickerPackMessage;
|