@itsliaaa/baileys 0.1.1 → 0.1.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/README.md +13 -0
- package/engine-requirements.js +4 -1
- package/lib/Socket/messages-send.js +1 -1
- package/lib/Utils/messages-media.js +44 -9
- package/lib/Utils/messages.js +42 -11
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ A lightweight fork of Baileys with a few fixes and a small adjustment.
|
|
|
10
10
|
- 🖼️ Fixed an issue where media could not be sent to newsletters due to an upstream issue.
|
|
11
11
|
- 📁 Reintroduced `makeInMemoryStore` with a minimal ESM adaptation and small adjustments for Baileys v7.
|
|
12
12
|
- 📦 Switched FFmpeg execution from `exec` to `spawn` for safer process handling.
|
|
13
|
+
- 🗃️ Added `@napi-rs/image` as a supported image processing backend in `getImageProcessingLibrary()`, offering a balance between performance and compatibility.
|
|
13
14
|
|
|
14
15
|
#### 📨 Message Handling & Compatibility
|
|
15
16
|
- 👉🏻 Added support for sending interactive message types (button, list, interactive, template, carousel).
|
|
@@ -19,6 +20,7 @@ A lightweight fork of Baileys with a few fixes and a small adjustment.
|
|
|
19
20
|
#### 🧩 Additional Message Options
|
|
20
21
|
- 👁️ Added optional boolean flags for message handling:
|
|
21
22
|
- `ai` - AI label on message
|
|
23
|
+
- `mentionAll` - Mentions all group participants without requiring their JIDs in `mentions` or `mentionedJid`
|
|
22
24
|
- `ephemeral`, `groupStatus`, `viewOnceV2`, `viewOnceV2Extension`, `interactiveAsTemplate` - Message wrappers
|
|
23
25
|
- `raw` - Build your message manually **(DO NOT USE FOR EXPLOITATION)**
|
|
24
26
|
|
|
@@ -230,6 +232,17 @@ sock.sendMessage(jid, {
|
|
|
230
232
|
})
|
|
231
233
|
```
|
|
232
234
|
|
|
235
|
+
##### 🧑🧑🧒🧒 Mention All
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
sock.sendMessage(jid, {
|
|
239
|
+
text: '👋🏻 Hello @all',
|
|
240
|
+
mentionAll: true
|
|
241
|
+
}, {
|
|
242
|
+
quoted: message
|
|
243
|
+
})
|
|
244
|
+
```
|
|
245
|
+
|
|
233
246
|
##### 😁 Reaction
|
|
234
247
|
|
|
235
248
|
```javascript
|
package/engine-requirements.js
CHANGED
|
@@ -13,16 +13,30 @@ import { getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from
|
|
|
13
13
|
import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto.js';
|
|
14
14
|
import { generateMessageIDV2 } from './generics.js';
|
|
15
15
|
const getTmpFilesDirectory = () => tmpdir();
|
|
16
|
+
let imageProcessingLibrary;
|
|
16
17
|
export const getImageProcessingLibrary = async () => {
|
|
18
|
+
if (imageProcessingLibrary) {
|
|
19
|
+
return imageProcessingLibrary;
|
|
20
|
+
}
|
|
17
21
|
//@ts-ignore
|
|
18
|
-
const [
|
|
22
|
+
const [sharp, image, jimp] = await Promise.all([
|
|
23
|
+
import('sharp').catch(() => { }),
|
|
24
|
+
import('@napi-rs/image').catch(() => { }),
|
|
25
|
+
import('jimp').catch(() => { })
|
|
26
|
+
]);
|
|
19
27
|
if (sharp) {
|
|
20
|
-
|
|
28
|
+
imageProcessingLibrary = { sharp };
|
|
29
|
+
}
|
|
30
|
+
else if (image) {
|
|
31
|
+
imageProcessingLibrary = { image };
|
|
21
32
|
}
|
|
22
|
-
if (jimp) {
|
|
23
|
-
|
|
33
|
+
else if (jimp) {
|
|
34
|
+
imageProcessingLibrary = { jimp };
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
throw new Boom('No image processing library available');
|
|
24
38
|
}
|
|
25
|
-
|
|
39
|
+
return imageProcessingLibrary;
|
|
26
40
|
};
|
|
27
41
|
export const hkdfInfoKey = (type) => {
|
|
28
42
|
const hkdfInfo = MEDIA_HKDF_KEY_MAPPING[type];
|
|
@@ -117,7 +131,7 @@ export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
117
131
|
bufferOrFilePath = await toBuffer(bufferOrFilePath);
|
|
118
132
|
}
|
|
119
133
|
const lib = await getImageProcessingLibrary();
|
|
120
|
-
if ('sharp' in lib &&
|
|
134
|
+
if ('sharp' in lib && lib.sharp?.default) {
|
|
121
135
|
const img = lib.sharp.default(bufferOrFilePath);
|
|
122
136
|
const dimensions = await img.metadata();
|
|
123
137
|
const buffer = await img.resize(width).jpeg({ quality: 50 }).toBuffer();
|
|
@@ -129,7 +143,22 @@ export const extractImageThumb = async (bufferOrFilePath, width = 32) => {
|
|
|
129
143
|
}
|
|
130
144
|
};
|
|
131
145
|
}
|
|
132
|
-
else if ('
|
|
146
|
+
else if ('image' in lib && lib.image?.Transformer) {
|
|
147
|
+
if (!Buffer.isBuffer(bufferOrFilePath)) {
|
|
148
|
+
bufferOrFilePath = await fs.readFile(bufferOrFilePath);
|
|
149
|
+
}
|
|
150
|
+
const img = new lib.image.Transformer(bufferOrFilePath);
|
|
151
|
+
const dimensions = await img.metadata();
|
|
152
|
+
const buffer = await img.resize(width, undefined, 0).jpeg(50);
|
|
153
|
+
return {
|
|
154
|
+
buffer,
|
|
155
|
+
original: {
|
|
156
|
+
width: dimensions.width,
|
|
157
|
+
height: dimensions.height
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
else if ('jimp' in lib && lib.jimp?.Jimp) {
|
|
133
162
|
const jimp = await lib.jimp.Jimp.read(bufferOrFilePath);
|
|
134
163
|
const dimensions = {
|
|
135
164
|
width: jimp.width,
|
|
@@ -162,7 +191,7 @@ export const generateProfilePicture = async (mediaUpload, dimensions) => {
|
|
|
162
191
|
}
|
|
163
192
|
const lib = await getImageProcessingLibrary();
|
|
164
193
|
let img;
|
|
165
|
-
if ('sharp' in lib &&
|
|
194
|
+
if ('sharp' in lib && lib.sharp?.default) {
|
|
166
195
|
img = lib.sharp
|
|
167
196
|
.default(buffer)
|
|
168
197
|
.resize(w, h)
|
|
@@ -171,7 +200,13 @@ export const generateProfilePicture = async (mediaUpload, dimensions) => {
|
|
|
171
200
|
})
|
|
172
201
|
.toBuffer();
|
|
173
202
|
}
|
|
174
|
-
else if ('
|
|
203
|
+
else if ('image' in lib && lib.image?.Transformer) {
|
|
204
|
+
img = new lib.image
|
|
205
|
+
.Transformer(buffer)
|
|
206
|
+
.resize(w, h, 0)
|
|
207
|
+
.jpeg(80);
|
|
208
|
+
}
|
|
209
|
+
else if ('jimp' in lib && lib.jimp?.Jimp) {
|
|
175
210
|
const jimp = await lib.jimp.Jimp.read(buffer);
|
|
176
211
|
const min = Math.min(jimp.width, jimp.height);
|
|
177
212
|
const cropped = jimp.crop({ x: 0, y: 0, w: min, h: min });
|
package/lib/Utils/messages.js
CHANGED
|
@@ -49,7 +49,8 @@ const mediaAnnotation = [{
|
|
|
49
49
|
newsletterName: process.env.NEWSLETTER_NAME ||
|
|
50
50
|
Buffer.from('f09d96b2f09d978df09d96baf09d978bf09d96bff09d96baf09d9785f09d9785', 'hex').toString(),
|
|
51
51
|
contentType: proto.ContextInfo.ForwardedNewsletterMessageInfo.ContentType.UPDATE,
|
|
52
|
-
accessibilityText:
|
|
52
|
+
accessibilityText: process.env.NEWSLETTER_ACCESSIBILITY_TEXT ||
|
|
53
|
+
LIBRARY_NAME
|
|
53
54
|
}
|
|
54
55
|
}];
|
|
55
56
|
/**
|
|
@@ -366,7 +367,7 @@ const prepareStickerPackMessage = async (message, options) => {
|
|
|
366
367
|
webpBuffer = buffer;
|
|
367
368
|
isAnimated = isAnimatedWebP(buffer);
|
|
368
369
|
}
|
|
369
|
-
else if ('sharp' in lib &&
|
|
370
|
+
else if ('sharp' in lib && lib.sharp?.default) {
|
|
370
371
|
// Convert to WebP, preserving metadata
|
|
371
372
|
webpBuffer = await lib
|
|
372
373
|
.sharp
|
|
@@ -377,8 +378,17 @@ const prepareStickerPackMessage = async (message, options) => {
|
|
|
377
378
|
// Non-WebP inputs converted to WebP are not animated
|
|
378
379
|
isAnimated = false;
|
|
379
380
|
}
|
|
381
|
+
else if ('image' in lib && lib.image?.Transformer) {
|
|
382
|
+
webpBuffer = await new lib
|
|
383
|
+
.image
|
|
384
|
+
.Transformer(buffer)
|
|
385
|
+
.resize(512, 512)
|
|
386
|
+
.webp(80);
|
|
387
|
+
// Non-WebP inputs converted to WebP are not animated
|
|
388
|
+
isAnimated = false;
|
|
389
|
+
}
|
|
380
390
|
else {
|
|
381
|
-
throw new Boom('No image processing library (sharp) available for converting sticker to WebP. Either install sharp or provide stickers in WebP format.');
|
|
391
|
+
throw new Boom('No image processing library (sharp or @napi-rs/image) available for converting sticker to WebP. Either install sharp or @napi-rs/image or provide stickers in WebP format.');
|
|
382
392
|
}
|
|
383
393
|
if (webpBuffer.length > 1024 * 1024) {
|
|
384
394
|
throw new Boom(`Sticker at index ${i} exceeds the 1MB size limit`, { statusCode: 400 });
|
|
@@ -405,7 +415,7 @@ const prepareStickerPackMessage = async (message, options) => {
|
|
|
405
415
|
// Already WebP - preserve original to keep exif metadata
|
|
406
416
|
coverWebpBuffer = coverBuffer;
|
|
407
417
|
}
|
|
408
|
-
else if ('sharp' in lib &&
|
|
418
|
+
else if ('sharp' in lib && lib.sharp?.default) {
|
|
409
419
|
coverWebpBuffer = await lib
|
|
410
420
|
.sharp
|
|
411
421
|
.default(coverBuffer)
|
|
@@ -413,8 +423,15 @@ const prepareStickerPackMessage = async (message, options) => {
|
|
|
413
423
|
.webp({ quality: 80 })
|
|
414
424
|
.toBuffer();
|
|
415
425
|
}
|
|
426
|
+
else if ('image' in lib && lib.image?.Transformer) {
|
|
427
|
+
coverWebpBuffer = await new lib
|
|
428
|
+
.image
|
|
429
|
+
.Transformer(coverBuffer)
|
|
430
|
+
.resize(512, 512)
|
|
431
|
+
.webp(80);
|
|
432
|
+
}
|
|
416
433
|
else {
|
|
417
|
-
throw new Boom('No image processing library (sharp) available for converting cover to WebP. Either install sharp or provide cover in WebP format.');
|
|
434
|
+
throw new Boom('No image processing library (sharp or @napi-rs/image) available for converting cover to WebP. Either install sharp or @napi-rs/image or provide cover in WebP format.');
|
|
418
435
|
}
|
|
419
436
|
// Add cover to ZIP data
|
|
420
437
|
stickerData[trayIconFileName] = [new Uint8Array(coverWebpBuffer), { level: 0 }];
|
|
@@ -457,7 +474,7 @@ const prepareStickerPackMessage = async (message, options) => {
|
|
|
457
474
|
try {
|
|
458
475
|
// Reuse the cover buffer we already processed for thumbnail generation
|
|
459
476
|
let thumbnailBuffer;
|
|
460
|
-
if ('sharp' in lib &&
|
|
477
|
+
if ('sharp' in lib && lib.sharp?.default) {
|
|
461
478
|
thumbnailBuffer = await lib
|
|
462
479
|
.sharp
|
|
463
480
|
.default(coverBuffer)
|
|
@@ -465,7 +482,14 @@ const prepareStickerPackMessage = async (message, options) => {
|
|
|
465
482
|
.jpeg()
|
|
466
483
|
.toBuffer();
|
|
467
484
|
}
|
|
468
|
-
|
|
485
|
+
if ('image' in lib && lib.image?.Transformer) {
|
|
486
|
+
thumbnailBuffer = await new lib
|
|
487
|
+
.image
|
|
488
|
+
.Transformer(coverBuffer)
|
|
489
|
+
.resize(252, 252)
|
|
490
|
+
.jpeg();
|
|
491
|
+
}
|
|
492
|
+
else if ('jimp' in lib && lib.jimp?.Jimp) {
|
|
469
493
|
const jimpImage = await lib.jimp.Jimp.read(coverBuffer);
|
|
470
494
|
thumbnailBuffer = await jimpImage
|
|
471
495
|
.resize({ w: 252, h: 252 })
|
|
@@ -1298,16 +1322,23 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1298
1322
|
key.contextInfo = { externalAdReply };
|
|
1299
1323
|
}
|
|
1300
1324
|
}
|
|
1301
|
-
if (
|
|
1325
|
+
if (
|
|
1326
|
+
(hasOptionalProperty(message, 'mentions') && message.mentions?.length) ||
|
|
1327
|
+
(hasOptionalProperty(message, 'mentionAll') && message.mentionAll)
|
|
1328
|
+
) {
|
|
1302
1329
|
const messageType = Object.keys(m)[0];
|
|
1303
1330
|
const key = m[messageType];
|
|
1304
1331
|
if ('contextInfo' in key && !!key.contextInfo) {
|
|
1305
|
-
key.contextInfo.mentionedJid = message.mentions;
|
|
1332
|
+
key.contextInfo.mentionedJid = message.mentions || [];
|
|
1306
1333
|
}
|
|
1307
1334
|
else if (key) {
|
|
1308
1335
|
key.contextInfo = {
|
|
1309
|
-
mentionedJid: message.mentions
|
|
1310
|
-
}
|
|
1336
|
+
mentionedJid: message.mentions || []
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
if (message.mentionAll) {
|
|
1340
|
+
key.contextInfo.mentionedJid = [];
|
|
1341
|
+
key.contextInfo.nonJidMentions = 1;
|
|
1311
1342
|
}
|
|
1312
1343
|
}
|
|
1313
1344
|
if (hasOptionalProperty(message, 'contextInfo') && !!message.contextInfo) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itsliaaa/baileys",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A simple fork of Baileys for WhatsApp automation",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -52,12 +52,16 @@
|
|
|
52
52
|
"ws": "^8.19.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
+
"@napi-rs/image": "~1.12.0",
|
|
55
56
|
"audio-decode": "^2.2.3",
|
|
56
57
|
"jimp": "^1.6.0",
|
|
57
58
|
"link-preview-js": "^3.0.0",
|
|
58
59
|
"sharp": "*"
|
|
59
60
|
},
|
|
60
61
|
"peerDependenciesMeta": {
|
|
62
|
+
"@napi-rs/image": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
61
65
|
"audio-decode": {
|
|
62
66
|
"optional": true
|
|
63
67
|
},
|