@zervonexx/baileys 5.0.3 → 5.0.5
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 +9 -0
- package/WAProto/WAProto.json +1 -1
- package/WAProto/WAProto.proto +1 -1
- package/lib/Utils/messages-media.js +6 -0
- package/lib/Utils/messages.js +21 -11
- package/lib/index.js +1 -1
- package/package.json +3 -2
package/WAProto/WAProto.proto
CHANGED
|
@@ -4716,8 +4716,8 @@ message Message {
|
|
|
4716
4716
|
|
|
4717
4717
|
message VpcRequestMessage {
|
|
4718
4718
|
optional uint32 payloadSchemaVersion = 1;
|
|
4719
|
-
optional string requestId = 2;
|
|
4720
4719
|
optional ScopeHint scopeHint = 3;
|
|
4720
|
+
optional bytes token = 4;
|
|
4721
4721
|
enum ScopeHint {
|
|
4722
4722
|
UNKNOWN = 0;
|
|
4723
4723
|
WA_ONLY = 1;
|
|
@@ -98,6 +98,12 @@ const convertToOpusBuffer = async (buffer, logger) => {
|
|
|
98
98
|
return _tmpConvert(buffer, detected?.ext ? `.${detected.ext}` : '', '.ogg', ['-vn', '-c:a', 'libopus', '-b:a', '128k', '-ar', '48000', '-ac', '1', '-vbr', 'on', '-compression_level', '10', '-frame_duration', '20', '-application', 'audio', '-map_metadata', '-1'])
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
export const extractAudioFromVideo = async (buffer) => {
|
|
102
|
+
const detected = await fileTypeFromBuffer(buffer)
|
|
103
|
+
if (!detected?.mime.startsWith('video/')) throw new Error(`extractAudio requires a video, got ${detected?.mime ?? 'unknown'}`)
|
|
104
|
+
return convertToOpusBuffer(buffer)
|
|
105
|
+
}
|
|
106
|
+
|
|
101
107
|
const convertToMp4Buffer = async (buffer, logger) => {
|
|
102
108
|
try {
|
|
103
109
|
const { default: sharp } = await import('sharp')
|
package/lib/Utils/messages.js
CHANGED
|
@@ -17,7 +17,7 @@ import { isJidGroup, isJidNewsletter, isJidStatusBroadcast, jidNormalizedUser }
|
|
|
17
17
|
import { sha256 } from './crypto.js'
|
|
18
18
|
import { resolveNativeFlowButtons } from './native-flow.js'
|
|
19
19
|
import { generateMessageIDV2, getKeyAuthor, unixTimestampSeconds } from './generics.js'
|
|
20
|
-
import { downloadContentFromMessage, encryptedStream, prepareStream, generateThumbnail, getAudioDuration, getAudioWaveform, toBuffer, normalizeToBuffer, tmpdir } from './messages-media.js'
|
|
20
|
+
import { downloadContentFromMessage, encryptedStream, prepareStream, generateThumbnail, getAudioDuration, getAudioWaveform, toBuffer, normalizeToBuffer, tmpdir, extractAudioFromVideo } from './messages-media.js'
|
|
21
21
|
import { shouldIncludeReportingToken } from './reporting-utils.js'
|
|
22
22
|
|
|
23
23
|
const require = createRequire(import.meta.url)
|
|
@@ -252,14 +252,16 @@ export const extractMessageContent = content => {
|
|
|
252
252
|
const normalizeExternalAdReplyThumbnail = async ext => {
|
|
253
253
|
if (!ext?.thumbnail) return ext
|
|
254
254
|
const thumb = await normalizeToBuffer(ext.thumbnail)
|
|
255
|
-
if (!thumb
|
|
255
|
+
if (!thumb) return ext
|
|
256
|
+
const { default: sharp } = await import('sharp')
|
|
257
|
+
const { format } = await sharp(thumb, { sequentialRead: true }).metadata()
|
|
258
|
+
if (format === 'jpeg' && thumb.length <= 50_000) return { ...ext, thumbnail: thumb }
|
|
259
|
+
const toJpeg = (quality, resize) => sharp(thumb, { sequentialRead: true }).resize(resize ? { width: 200, height: 200, fit: 'inside' } : undefined).jpeg({ quality }).toBuffer().catch(() => null)
|
|
260
|
+
let thumbnail = await toJpeg(90)
|
|
261
|
+
if (!thumbnail) return ext
|
|
262
|
+
if (thumbnail.length <= 50_000) return { ...ext, thumbnail }
|
|
256
263
|
let quality = 90
|
|
257
|
-
while (quality >= 10) {
|
|
258
|
-
const thumbnail = await sharp(ext.thumbnail, { sequentialRead: true }).resize(200, 200, { fit: 'inside' }).jpeg({ quality }).toBuffer().catch(() => null)
|
|
259
|
-
if (!thumbnail) return ext
|
|
260
|
-
if (thumbnail.length <= 50_000) return { ...ext, thumbnail }
|
|
261
|
-
quality = Math.max(10, Math.floor(quality * (50_000 / thumbnail.length) * 0.85))
|
|
262
|
-
}
|
|
264
|
+
while (quality >= 10) { thumbnail = await toJpeg(quality, true); if (!thumbnail) return ext; if (thumbnail.length <= 50_000) return { ...ext, thumbnail }; const next = Math.max(10, Math.floor(quality * (50_000 / thumbnail.length) * 0.85)); if (next === quality) break; quality = next }
|
|
263
265
|
return ext
|
|
264
266
|
}
|
|
265
267
|
|
|
@@ -299,13 +301,21 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
299
301
|
try {
|
|
300
302
|
const packName = message.pack || message.packName || options?.pack || options?.packName || 'ZervonexStickers'
|
|
301
303
|
const authorName = message.author || message.publisher || message.packPublisher || options?.author || options?.publisher || options?.packPublisher || 'Zervonex'
|
|
302
|
-
const
|
|
304
|
+
const rawBuffer = await toBuffer(uploadData.media)
|
|
305
|
+
const { buffer } = await compressWebp(rawBuffer, { packName, authorName, stickerType: message.stickerType || options?.stickerType || StickerTypes.ROUNDED, quality: message.quality || options?.quality || 80 })
|
|
303
306
|
uploadData.media = buffer
|
|
304
307
|
uploadData.stickerSentTs = Date.now()
|
|
305
308
|
if (message.premium != null) uploadData.premium = message.premium
|
|
306
309
|
const rawAudio = message.audio ?? message.stickerAudio ?? message.audioFooter
|
|
307
|
-
if (rawAudio != null)
|
|
308
|
-
|
|
310
|
+
if (rawAudio != null) {
|
|
311
|
+
try { uploadData.audioMessage = (await prepareWAMessageMedia({ audio: rawAudio }, options)).audioMessage; uploadData.isAnimated = true } catch (e) { options.logger?.warn({ err: e }, 'sticker audio preparation failed') }
|
|
312
|
+
} else if (message.audioMessage != null) {
|
|
313
|
+
uploadData.audioMessage = message.audioMessage
|
|
314
|
+
uploadData.isAnimated = true
|
|
315
|
+
} else if (message.extractAudio || options?.extractAudio) {
|
|
316
|
+
uploadData.audioMessage = (await prepareWAMessageMedia({ audio: await extractAudioFromVideo(rawBuffer) }, options)).audioMessage
|
|
317
|
+
uploadData.isAnimated = true
|
|
318
|
+
}
|
|
309
319
|
} catch (e) { options.logger?.warn({ err: e }, 'sticker formatting failed, sending raw') }
|
|
310
320
|
}
|
|
311
321
|
|
package/lib/index.js
CHANGED
|
@@ -29,7 +29,7 @@ const info = [
|
|
|
29
29
|
'╭──────────────────────────────────────────────────────────────╮',
|
|
30
30
|
'│ │',
|
|
31
31
|
'│ ◆ Package › @zervonexx/baileys │',
|
|
32
|
-
'│ ◆ Version › 5.0.
|
|
32
|
+
'│ ◆ Version › 5.0.5 │',
|
|
33
33
|
'│ ◆ Status › Production Ready │',
|
|
34
34
|
'│ │',
|
|
35
35
|
'├──────────────────────────── ◇◆◇ ─────────────────────────────┤',
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@zervonexx/baileys",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "5.0.
|
|
5
|
+
"version": "5.0.5",
|
|
6
6
|
"description": "Advanced WhatsApp Web API built on Baileys — interactive messages, buttons, carousels, products, events, payments, polls, albums, sticker packs and more.",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"baileys",
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
"nexustech",
|
|
14
14
|
"nexustechpro",
|
|
15
15
|
"zervo",
|
|
16
|
+
"zer",
|
|
16
17
|
"zervonex baileys",
|
|
17
18
|
"Zervonex",
|
|
18
|
-
"
|
|
19
|
+
"zervone",
|
|
19
20
|
"zervonexx",
|
|
20
21
|
"baileys-advanced",
|
|
21
22
|
"whiskeysockets",
|