@d0v3riz/baileys 6.7.20 → 6.7.22
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/business.d.ts +30 -2
- package/lib/Socket/chats.d.ts +8 -3
- package/lib/Socket/chats.js +20 -2
- package/lib/Socket/groups.d.ts +8 -2
- package/lib/Socket/groups.js +1 -0
- package/lib/Socket/index.d.ts +30 -2
- package/lib/Socket/messages-recv.d.ts +30 -2
- package/lib/Socket/messages-recv.js +140 -0
- package/lib/Socket/messages-send.d.ts +30 -2
- package/lib/Socket/messages-send.js +28 -2
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +46 -0
- package/lib/Socket/newsletter.d.ts +141 -0
- package/lib/Socket/newsletter.js +183 -0
- package/lib/Socket/socket.js +0 -1
- package/lib/Types/Chat.d.ts +3 -0
- package/lib/Types/Events.d.ts +26 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/Message.d.ts +6 -1
- package/lib/Types/Newsletter.d.ts +134 -0
- package/lib/Types/Newsletter.js +33 -0
- package/lib/Types/index.d.ts +1 -0
- package/lib/Types/index.js +1 -0
- package/lib/Utils/auth-utils.js +1 -1
- package/lib/Utils/chat-utils.js +14 -1
- package/lib/Utils/decode-wa-message.d.ts +3 -4
- package/lib/Utils/decode-wa-message.js +5 -1
- package/lib/Utils/generics.d.ts +1 -0
- package/lib/Utils/generics.js +4 -0
- package/lib/Utils/history.js +0 -6
- package/lib/Utils/messages-media.d.ts +11 -3
- package/lib/Utils/messages-media.js +74 -35
- package/lib/Utils/messages.d.ts +2 -2
- package/lib/Utils/messages.js +39 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/package.json +5 -5
|
@@ -91,7 +91,8 @@ function decodeMessageNode(stanza, meId, meLid) {
|
|
|
91
91
|
senderPn: (_c = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _c === void 0 ? void 0 : _c.sender_pn,
|
|
92
92
|
participant,
|
|
93
93
|
participantPn: (_d = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _d === void 0 ? void 0 : _d.participant_pn,
|
|
94
|
-
participantLid: (_e = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _e === void 0 ? void 0 : _e.participant_lid
|
|
94
|
+
participantLid: (_e = stanza === null || stanza === void 0 ? void 0 : stanza.attrs) === null || _e === void 0 ? void 0 : _e.participant_lid,
|
|
95
|
+
...(msgType === 'newsletter' && stanza.attrs.server_id ? { server_id: stanza.attrs.server_id } : {})
|
|
95
96
|
};
|
|
96
97
|
const fullMessage = {
|
|
97
98
|
key,
|
|
@@ -124,6 +125,9 @@ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
|
|
|
124
125
|
const details = WAProto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
125
126
|
fullMessage.verifiedBizName = details.verifiedName;
|
|
126
127
|
}
|
|
128
|
+
if (tag === 'unavailable' && attrs.type === 'view_once') {
|
|
129
|
+
fullMessage.key.isViewOnce = true;
|
|
130
|
+
}
|
|
127
131
|
if (tag !== 'enc' && tag !== 'plaintext') {
|
|
128
132
|
continue;
|
|
129
133
|
}
|
package/lib/Utils/generics.d.ts
CHANGED
package/lib/Utils/generics.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.promiseTimeout = promiseTimeout;
|
|
|
8
8
|
exports.bindWaitForEvent = bindWaitForEvent;
|
|
9
9
|
exports.trimUndefined = trimUndefined;
|
|
10
10
|
exports.bytesToCrockford = bytesToCrockford;
|
|
11
|
+
exports.encodeNewsletterMessage = encodeNewsletterMessage;
|
|
11
12
|
const boom_1 = require("@hapi/boom");
|
|
12
13
|
const axios_1 = __importDefault(require("axios"));
|
|
13
14
|
const crypto_1 = require("crypto");
|
|
@@ -394,3 +395,6 @@ function bytesToCrockford(buffer) {
|
|
|
394
395
|
}
|
|
395
396
|
return crockford.join('');
|
|
396
397
|
}
|
|
398
|
+
function encodeNewsletterMessage(message) {
|
|
399
|
+
return WAProto_1.proto.Message.encode(message).finish();
|
|
400
|
+
}
|
package/lib/Utils/history.js
CHANGED
|
@@ -42,9 +42,6 @@ const processHistoryMessage = (item) => {
|
|
|
42
42
|
});
|
|
43
43
|
const msgs = chat.messages || [];
|
|
44
44
|
delete chat.messages;
|
|
45
|
-
delete chat.archived;
|
|
46
|
-
delete chat.muteEndTime;
|
|
47
|
-
delete chat.pinned;
|
|
48
45
|
for (const item of msgs) {
|
|
49
46
|
const message = item.message;
|
|
50
47
|
messages.push(message);
|
|
@@ -64,9 +61,6 @@ const processHistoryMessage = (item) => {
|
|
|
64
61
|
});
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
|
-
if ((0, WABinary_1.isJidUser)(chat.id) && chat.readOnly && chat.archived) {
|
|
68
|
-
delete chat.readOnly;
|
|
69
|
-
}
|
|
70
64
|
chats.push({ ...chat });
|
|
71
65
|
}
|
|
72
66
|
break;
|
|
@@ -7,17 +7,25 @@ import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType,
|
|
|
7
7
|
import { BinaryNode } from '../WABinary';
|
|
8
8
|
import { ILogger } from './logger';
|
|
9
9
|
export declare const hkdfInfoKey: (type: MediaType) => string;
|
|
10
|
+
export declare const getRawMediaUploadData: (media: WAMediaUpload, mediaType: MediaType, logger?: ILogger) => Promise<{
|
|
11
|
+
filePath: string;
|
|
12
|
+
fileSha256: Buffer<ArrayBufferLike>;
|
|
13
|
+
fileLength: number;
|
|
14
|
+
}>;
|
|
10
15
|
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
11
16
|
export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): Promise<MediaDecryptionKeyInfo>;
|
|
12
17
|
export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
|
|
13
18
|
buffer: Buffer<ArrayBufferLike>;
|
|
14
19
|
original: {
|
|
15
|
-
width: number
|
|
16
|
-
height: number
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
17
22
|
};
|
|
18
23
|
}>;
|
|
19
24
|
export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
|
|
20
|
-
export declare const generateProfilePicture: (mediaUpload: WAMediaUpload
|
|
25
|
+
export declare const generateProfilePicture: (mediaUpload: WAMediaUpload, dimensions?: {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}) => Promise<{
|
|
21
29
|
img: Buffer<ArrayBufferLike>;
|
|
22
30
|
}>;
|
|
23
31
|
/** gets the SHA256 of the given media message */
|
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.getHttpStream = exports.getStream = exports.toBuffer = exports.toReadable = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.hkdfInfoKey = void 0;
|
|
39
|
+
exports.getStatusCodeForMediaRetry = exports.decryptMediaRetryData = exports.decodeMediaRetryNode = exports.encryptMediaRetryRequest = exports.getWAUploadToServer = exports.downloadEncryptedContent = exports.downloadContentFromMessage = exports.getUrlFromDirectPath = exports.encryptedStream = exports.getHttpStream = exports.getStream = exports.toBuffer = exports.toReadable = exports.mediaMessageSHA256B64 = exports.generateProfilePicture = exports.encodeBase64EncodedStringForUpload = exports.extractImageThumb = exports.getRawMediaUploadData = exports.hkdfInfoKey = void 0;
|
|
40
40
|
exports.getMediaKeys = getMediaKeys;
|
|
41
41
|
exports.getAudioDuration = getAudioDuration;
|
|
42
42
|
exports.getAudioWaveform = getAudioWaveform;
|
|
@@ -58,20 +58,10 @@ const crypto_1 = require("./crypto");
|
|
|
58
58
|
const generics_1 = require("./generics");
|
|
59
59
|
const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
|
|
60
60
|
const getImageProcessingLibrary = async () => {
|
|
61
|
-
const [
|
|
62
|
-
(async () => {
|
|
63
|
-
const jimp = await Promise.resolve().then(() => __importStar(require('jimp'))).catch(() => { });
|
|
64
|
-
return jimp;
|
|
65
|
-
})(),
|
|
66
|
-
(async () => {
|
|
67
|
-
const sharp = await Promise.resolve().then(() => __importStar(require('sharp'))).catch(() => { });
|
|
68
|
-
return sharp;
|
|
69
|
-
})()
|
|
70
|
-
]);
|
|
61
|
+
const [jimp, sharp] = await Promise.all([Promise.resolve().then(() => __importStar(require('jimp'))).catch(() => { }), Promise.resolve().then(() => __importStar(require('sharp'))).catch(() => { })]);
|
|
71
62
|
if (sharp) {
|
|
72
63
|
return { sharp };
|
|
73
64
|
}
|
|
74
|
-
const jimp = (_jimp === null || _jimp === void 0 ? void 0 : _jimp.default) || _jimp;
|
|
75
65
|
if (jimp) {
|
|
76
66
|
return { jimp };
|
|
77
67
|
}
|
|
@@ -82,6 +72,45 @@ const hkdfInfoKey = (type) => {
|
|
|
82
72
|
return `WhatsApp ${hkdfInfo} Keys`;
|
|
83
73
|
};
|
|
84
74
|
exports.hkdfInfoKey = hkdfInfoKey;
|
|
75
|
+
const getRawMediaUploadData = async (media, mediaType, logger) => {
|
|
76
|
+
const { stream } = await (0, exports.getStream)(media);
|
|
77
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('got stream for raw upload');
|
|
78
|
+
const hasher = Crypto.createHash('sha256');
|
|
79
|
+
const filePath = (0, path_1.join)((0, os_1.tmpdir)(), mediaType + (0, generics_1.generateMessageIDV2)());
|
|
80
|
+
const fileWriteStream = (0, fs_1.createWriteStream)(filePath);
|
|
81
|
+
let fileLength = 0;
|
|
82
|
+
try {
|
|
83
|
+
for await (const data of stream) {
|
|
84
|
+
fileLength += data.length;
|
|
85
|
+
hasher.update(data);
|
|
86
|
+
if (!fileWriteStream.write(data)) {
|
|
87
|
+
await (0, events_1.once)(fileWriteStream, 'drain');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
fileWriteStream.end();
|
|
91
|
+
await (0, events_1.once)(fileWriteStream, 'finish');
|
|
92
|
+
stream.destroy();
|
|
93
|
+
const fileSha256 = hasher.digest();
|
|
94
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('hashed data for raw upload');
|
|
95
|
+
return {
|
|
96
|
+
filePath: filePath,
|
|
97
|
+
fileSha256,
|
|
98
|
+
fileLength
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
fileWriteStream.destroy();
|
|
103
|
+
stream.destroy();
|
|
104
|
+
try {
|
|
105
|
+
await fs_1.promises.unlink(filePath);
|
|
106
|
+
}
|
|
107
|
+
catch (_a) {
|
|
108
|
+
//
|
|
109
|
+
}
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
exports.getRawMediaUploadData = getRawMediaUploadData;
|
|
85
114
|
/** generates all the keys required to encrypt/decrypt & sign a media message */
|
|
86
115
|
async function getMediaKeys(buffer, mediaType) {
|
|
87
116
|
if (!buffer) {
|
|
@@ -128,14 +157,15 @@ const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
128
157
|
}
|
|
129
158
|
};
|
|
130
159
|
}
|
|
131
|
-
else if ('jimp' in lib && typeof ((_b = lib.jimp) === null || _b === void 0 ? void 0 : _b.
|
|
132
|
-
const
|
|
133
|
-
const jimp = await read(bufferOrFilePath);
|
|
160
|
+
else if ('jimp' in lib && typeof ((_b = lib.jimp) === null || _b === void 0 ? void 0 : _b.Jimp) === 'object') {
|
|
161
|
+
const jimp = await lib.jimp.default.Jimp.read(bufferOrFilePath);
|
|
134
162
|
const dimensions = {
|
|
135
|
-
width: jimp.
|
|
136
|
-
height: jimp.
|
|
163
|
+
width: jimp.width,
|
|
164
|
+
height: jimp.height
|
|
137
165
|
};
|
|
138
|
-
const buffer = await jimp
|
|
166
|
+
const buffer = await jimp
|
|
167
|
+
.resize({ w: width, mode: lib.jimp.ResizeStrategy.BILINEAR })
|
|
168
|
+
.getBuffer('image/jpeg', { quality: 50 });
|
|
139
169
|
return {
|
|
140
170
|
buffer,
|
|
141
171
|
original: dimensions
|
|
@@ -148,35 +178,35 @@ const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
148
178
|
exports.extractImageThumb = extractImageThumb;
|
|
149
179
|
const encodeBase64EncodedStringForUpload = (b64) => encodeURIComponent(b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, ''));
|
|
150
180
|
exports.encodeBase64EncodedStringForUpload = encodeBase64EncodedStringForUpload;
|
|
151
|
-
const generateProfilePicture = async (mediaUpload) => {
|
|
181
|
+
const generateProfilePicture = async (mediaUpload, dimensions) => {
|
|
152
182
|
var _a, _b;
|
|
153
|
-
let
|
|
183
|
+
let buffer;
|
|
184
|
+
const { width: w = 640, height: h = 640 } = dimensions || {};
|
|
154
185
|
if (Buffer.isBuffer(mediaUpload)) {
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
else if ('url' in mediaUpload) {
|
|
158
|
-
bufferOrFilePath = mediaUpload.url.toString();
|
|
186
|
+
buffer = mediaUpload;
|
|
159
187
|
}
|
|
160
188
|
else {
|
|
161
|
-
|
|
189
|
+
// Use getStream to handle all WAMediaUpload types (Buffer, Stream, URL)
|
|
190
|
+
const { stream } = await (0, exports.getStream)(mediaUpload);
|
|
191
|
+
// Convert the resulting stream to a buffer
|
|
192
|
+
buffer = await (0, exports.toBuffer)(stream);
|
|
162
193
|
}
|
|
163
194
|
const lib = await getImageProcessingLibrary();
|
|
164
195
|
let img;
|
|
165
196
|
if ('sharp' in lib && typeof ((_a = lib.sharp) === null || _a === void 0 ? void 0 : _a.default) === 'function') {
|
|
166
197
|
img = lib.sharp
|
|
167
|
-
.default(
|
|
168
|
-
.resize(
|
|
198
|
+
.default(buffer)
|
|
199
|
+
.resize(w, h)
|
|
169
200
|
.jpeg({
|
|
170
201
|
quality: 50
|
|
171
202
|
})
|
|
172
203
|
.toBuffer();
|
|
173
204
|
}
|
|
174
|
-
else if ('jimp' in lib && typeof ((_b = lib.jimp) === null || _b === void 0 ? void 0 : _b.
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
img = cropped.quality(50).resize(640, 640, RESIZE_BILINEAR).getBufferAsync(MIME_JPEG);
|
|
205
|
+
else if ('jimp' in lib && typeof ((_b = lib.jimp) === null || _b === void 0 ? void 0 : _b.Jimp) === 'object') {
|
|
206
|
+
const jimp = await lib.jimp.default.Jimp.read(buffer);
|
|
207
|
+
const min = Math.min(jimp.width, jimp.height);
|
|
208
|
+
const cropped = jimp.crop({ x: 0, y: 0, w: min, h: min });
|
|
209
|
+
img = cropped.resize({ w, h, mode: lib.jimp.ResizeStrategy.BILINEAR }).getBuffer('image/jpeg', { quality: 50 });
|
|
180
210
|
}
|
|
181
211
|
else {
|
|
182
212
|
throw new boom_1.Boom('No image processing library available');
|
|
@@ -273,7 +303,12 @@ const getStream = async (item, opts) => {
|
|
|
273
303
|
if ('stream' in item) {
|
|
274
304
|
return { stream: item.stream, type: 'readable' };
|
|
275
305
|
}
|
|
276
|
-
|
|
306
|
+
const urlStr = item.url.toString();
|
|
307
|
+
if (urlStr.startsWith('data:')) {
|
|
308
|
+
const buffer = Buffer.from(urlStr.split(',')[1], 'base64');
|
|
309
|
+
return { stream: (0, exports.toReadable)(buffer), type: 'buffer' };
|
|
310
|
+
}
|
|
311
|
+
if (urlStr.startsWith('http://') || urlStr.startsWith('https://')) {
|
|
277
312
|
return { stream: await (0, exports.getHttpStream)(item.url, opts), type: 'remote' };
|
|
278
313
|
}
|
|
279
314
|
return { stream: (0, fs_1.createReadStream)(item.url), type: 'file' };
|
|
@@ -406,7 +441,11 @@ const toSmallestChunkSize = (num) => {
|
|
|
406
441
|
const getUrlFromDirectPath = (directPath) => `https://${DEF_HOST}${directPath}`;
|
|
407
442
|
exports.getUrlFromDirectPath = getUrlFromDirectPath;
|
|
408
443
|
const downloadContentFromMessage = async ({ mediaKey, directPath, url }, type, opts = {}) => {
|
|
409
|
-
const
|
|
444
|
+
const isValidMediaUrl = url === null || url === void 0 ? void 0 : url.startsWith('https://mmg.whatsapp.net/');
|
|
445
|
+
const downloadUrl = isValidMediaUrl ? url : (0, exports.getUrlFromDirectPath)(directPath);
|
|
446
|
+
if (!downloadUrl) {
|
|
447
|
+
throw new boom_1.Boom('No valid media URL or directPath present in message', { statusCode: 400 });
|
|
448
|
+
}
|
|
410
449
|
const keys = await getMediaKeys(mediaKey, type);
|
|
411
450
|
return (0, exports.downloadEncryptedContent)(downloadUrl, keys, opts);
|
|
412
451
|
};
|
package/lib/Utils/messages.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Transform } from 'stream';
|
|
2
2
|
import { proto } from '../../WAProto';
|
|
3
|
-
import { AnyMediaMessageContent, AnyMessageContent,
|
|
3
|
+
import { AnyMediaMessageContent, AnyMessageContent, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAProto } from '../Types';
|
|
4
4
|
import { ILogger } from './logger';
|
|
5
5
|
import { MediaDownloadOptions } from './messages-media';
|
|
6
6
|
/**
|
|
@@ -10,7 +10,7 @@ import { MediaDownloadOptions } from './messages-media';
|
|
|
10
10
|
*/
|
|
11
11
|
export declare const extractUrlFromText: (text: string) => string | undefined;
|
|
12
12
|
export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions["getUrlInfo"], logger: MessageGenerationOptions["logger"]) => Promise<import("../Types").WAUrlInfo | undefined>;
|
|
13
|
-
export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options:
|
|
13
|
+
export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
|
|
14
14
|
export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number) => proto.Message;
|
|
15
15
|
/**
|
|
16
16
|
* Generate forwarded message content like WA does
|
package/lib/Utils/messages.js
CHANGED
|
@@ -82,12 +82,10 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
82
82
|
media: message[mediaType]
|
|
83
83
|
};
|
|
84
84
|
delete uploadData[mediaType];
|
|
85
|
-
// check if cacheable + generate cache key
|
|
86
85
|
const cacheableKey = typeof uploadData.media === 'object' &&
|
|
87
86
|
'url' in uploadData.media &&
|
|
88
87
|
!!uploadData.media.url &&
|
|
89
88
|
!!options.mediaCache &&
|
|
90
|
-
// generate the key
|
|
91
89
|
mediaType + ':' + uploadData.media.url.toString();
|
|
92
90
|
if (mediaType === 'document' && !uploadData.fileName) {
|
|
93
91
|
uploadData.fileName = 'file';
|
|
@@ -95,7 +93,6 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
95
93
|
if (!uploadData.mimetype) {
|
|
96
94
|
uploadData.mimetype = MIMETYPE_MAP[mediaType];
|
|
97
95
|
}
|
|
98
|
-
// check for cache hit
|
|
99
96
|
if (cacheableKey) {
|
|
100
97
|
const mediaBuff = options.mediaCache.get(cacheableKey);
|
|
101
98
|
if (mediaBuff) {
|
|
@@ -106,6 +103,37 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
106
103
|
return obj;
|
|
107
104
|
}
|
|
108
105
|
}
|
|
106
|
+
const isNewsletter = !!options.jid && (0, WABinary_1.isJidNewsletter)(options.jid);
|
|
107
|
+
if (isNewsletter) {
|
|
108
|
+
logger === null || logger === void 0 ? void 0 : logger.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
|
|
109
|
+
const { filePath, fileSha256, fileLength } = await (0, messages_media_1.getRawMediaUploadData)(uploadData.media, options.mediaTypeOverride || mediaType, logger);
|
|
110
|
+
const fileSha256B64 = fileSha256.toString('base64');
|
|
111
|
+
const { mediaUrl, directPath } = await options.upload(filePath, {
|
|
112
|
+
fileEncSha256B64: fileSha256B64,
|
|
113
|
+
mediaType: mediaType,
|
|
114
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
115
|
+
});
|
|
116
|
+
await fs_1.promises.unlink(filePath);
|
|
117
|
+
const obj = Types_1.WAProto.Message.fromObject({
|
|
118
|
+
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
119
|
+
url: mediaUrl,
|
|
120
|
+
directPath,
|
|
121
|
+
fileSha256,
|
|
122
|
+
fileLength,
|
|
123
|
+
...uploadData,
|
|
124
|
+
media: undefined
|
|
125
|
+
})
|
|
126
|
+
});
|
|
127
|
+
if (uploadData.ptv) {
|
|
128
|
+
obj.ptvMessage = obj.videoMessage;
|
|
129
|
+
delete obj.videoMessage;
|
|
130
|
+
}
|
|
131
|
+
if (cacheableKey) {
|
|
132
|
+
logger === null || logger === void 0 ? void 0 : logger.debug({ cacheableKey }, 'set cache');
|
|
133
|
+
options.mediaCache.set(cacheableKey, Types_1.WAProto.Message.encode(obj).finish());
|
|
134
|
+
}
|
|
135
|
+
return obj;
|
|
136
|
+
}
|
|
109
137
|
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
110
138
|
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') && typeof uploadData['jpegThumbnail'] === 'undefined';
|
|
111
139
|
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true;
|
|
@@ -116,7 +144,6 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
116
144
|
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
117
145
|
opts: options.options
|
|
118
146
|
});
|
|
119
|
-
// url safe Base64 encode the SHA256 hash of the body
|
|
120
147
|
const fileEncSha256B64 = fileEncSha256.toString('base64');
|
|
121
148
|
const [{ mediaUrl, directPath }] = await Promise.all([
|
|
122
149
|
(async () => {
|
|
@@ -399,12 +426,12 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
399
426
|
m.pollCreationMessageV2 = pollCreationMessage;
|
|
400
427
|
}
|
|
401
428
|
else {
|
|
402
|
-
if (message.poll.selectableCount
|
|
429
|
+
if (message.poll.selectableCount === 1) {
|
|
403
430
|
//poll v3 is for single select polls
|
|
404
431
|
m.pollCreationMessageV3 = pollCreationMessage;
|
|
405
432
|
}
|
|
406
433
|
else {
|
|
407
|
-
// poll
|
|
434
|
+
// poll for multiple choice polls
|
|
408
435
|
m.pollCreationMessage = pollCreationMessage;
|
|
409
436
|
}
|
|
410
437
|
}
|
|
@@ -456,7 +483,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
456
483
|
const key = (0, exports.getContentType)(innerMessage);
|
|
457
484
|
const timestamp = (0, generics_1.unixTimestampSeconds)(options.timestamp);
|
|
458
485
|
const { quoted, userJid, contextInfo } = options;
|
|
459
|
-
if (quoted) {
|
|
486
|
+
if (quoted && !(0, WABinary_1.isJidNewsletter)(jid)) {
|
|
460
487
|
const participant = quoted.key.fromMe
|
|
461
488
|
? userJid
|
|
462
489
|
: quoted.participant || quoted.key.participant || quoted.key.remoteJid;
|
|
@@ -491,7 +518,9 @@ const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
491
518
|
// and it's not a protocol message -- delete, toggle disappear message
|
|
492
519
|
key !== 'protocolMessage' &&
|
|
493
520
|
// already not converted to disappearing message
|
|
494
|
-
key !== 'ephemeralMessage'
|
|
521
|
+
key !== 'ephemeralMessage' &&
|
|
522
|
+
// newsletters don't support ephemeral messages
|
|
523
|
+
!(0, WABinary_1.isJidNewsletter)(jid)) {
|
|
495
524
|
innerMessage[key].contextInfo = {
|
|
496
525
|
...(innerMessage[key].contextInfo || {}),
|
|
497
526
|
expiration: options.ephemeralExpiration || Defaults_1.WA_DEFAULT_EPHEMERAL
|
|
@@ -518,7 +547,8 @@ const generateWAMessage = async (jid, content, options) => {
|
|
|
518
547
|
var _a;
|
|
519
548
|
// ensure msg ID is with every log
|
|
520
549
|
options.logger = (_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.child({ msgId: options.messageId });
|
|
521
|
-
|
|
550
|
+
// Pass jid in the options to generateWAMessageContent
|
|
551
|
+
return (0, exports.generateWAMessageFromContent)(jid, await (0, exports.generateWAMessageContent)(content, { ...options, jid }), options);
|
|
522
552
|
};
|
|
523
553
|
exports.generateWAMessage = generateWAMessage;
|
|
524
554
|
/** Get the key to access the true type of content */
|
|
@@ -16,7 +16,7 @@ class USyncDisappearingModeProtocol {
|
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
18
|
parser(node) {
|
|
19
|
-
if (node.tag === '
|
|
19
|
+
if (node.tag === 'disappearing_mode') {
|
|
20
20
|
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
21
21
|
const duration = +(node === null || node === void 0 ? void 0 : node.attrs.duration);
|
|
22
22
|
const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d0v3riz/baileys",
|
|
3
|
-
"version": "6.7.
|
|
3
|
+
"version": "6.7.22",
|
|
4
4
|
"description": "A WebSockets library for interacting with WhatsApp Web",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"whatsapp",
|
|
@@ -62,14 +62,14 @@
|
|
|
62
62
|
"eslint-config-prettier": "^10.1.2",
|
|
63
63
|
"eslint-plugin-prettier": "^5.4.0",
|
|
64
64
|
"jest": "^29.7.0",
|
|
65
|
-
"jimp": "^
|
|
65
|
+
"jimp": "^1.6.0",
|
|
66
66
|
"json": "^11.0.0",
|
|
67
67
|
"link-preview-js": "^3.0.0",
|
|
68
68
|
"open": "^8.4.2",
|
|
69
69
|
"prettier": "^3.5.3",
|
|
70
70
|
"protobufjs-cli": "^1.1.3",
|
|
71
71
|
"release-it": "^15.10.3",
|
|
72
|
-
"sharp": "^0.
|
|
72
|
+
"sharp": "^0.34.2",
|
|
73
73
|
"ts-jest": "^29.3.2",
|
|
74
74
|
"ts-node": "^10.8.1",
|
|
75
75
|
"typedoc": "^0.27.9",
|
|
@@ -78,9 +78,9 @@
|
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"audio-decode": "^2.1.3",
|
|
81
|
-
"jimp": "^
|
|
81
|
+
"jimp": "^1.6.0",
|
|
82
82
|
"link-preview-js": "^3.0.0",
|
|
83
|
-
"sharp": "^0.
|
|
83
|
+
"sharp": "^0.34.2"
|
|
84
84
|
},
|
|
85
85
|
"peerDependenciesMeta": {
|
|
86
86
|
"audio-decode": {
|