kage-baileys 25.3.20 β 25.3.21
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/Example/plugins/audiosticker.js +55 -19
- package/lib/Utils/audio-sticker.js +208 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/messages.js +6 -0
- package/package.json +1 -1
|
@@ -297,7 +297,7 @@ async function downloadBuffer(node, info, client) {
|
|
|
297
297
|
return null
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
function buildExifPayload(packname, author) {
|
|
300
|
+
function buildExifPayload(packname, author, soundSha256Base64 = null) {
|
|
301
301
|
const json = {
|
|
302
302
|
'sticker-pack-id': 'com.mahiru.audiosticker',
|
|
303
303
|
'sticker-pack-name': String(packname ?? ''),
|
|
@@ -305,6 +305,12 @@ function buildExifPayload(packname, author) {
|
|
|
305
305
|
emojis: ['π']
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
+
// WhatsApp sound stickers link the webp to the audio via sound-sha256
|
|
309
|
+
// (base64 of the unencrypted audio fileSha256).
|
|
310
|
+
if (soundSha256Base64) {
|
|
311
|
+
json['sound-sha256'] = String(soundSha256Base64)
|
|
312
|
+
}
|
|
313
|
+
|
|
308
314
|
const exifAttr = Buffer.from([
|
|
309
315
|
0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00,
|
|
310
316
|
0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00,
|
|
@@ -383,8 +389,8 @@ function injectExifRiffFallback(webpBuffer, exifData) {
|
|
|
383
389
|
return Buffer.concat([header, body])
|
|
384
390
|
}
|
|
385
391
|
|
|
386
|
-
async function addStickerExif(webpBuffer, packname, author) {
|
|
387
|
-
const exifData = buildExifPayload(packname, author)
|
|
392
|
+
async function addStickerExif(webpBuffer, packname, author, soundSha256Base64 = null) {
|
|
393
|
+
const exifData = buildExifPayload(packname, author, soundSha256Base64)
|
|
388
394
|
|
|
389
395
|
try {
|
|
390
396
|
const module = await import('node-webpmux')
|
|
@@ -607,11 +613,12 @@ async function convertToOggOpus(buffer, ext = 'mp3') {
|
|
|
607
613
|
|
|
608
614
|
async function buildAudioMessageFromBuffer(client, buffer, ext, fallbackSeconds = 0) {
|
|
609
615
|
const { oggBuffer, realSeconds } = await convertToOggOpus(buffer, ext)
|
|
616
|
+
// Sound stickers require a normal audio upload (NOT PTT / voice note).
|
|
610
617
|
const prepared = await prepareWAMessageMedia(
|
|
611
618
|
{
|
|
612
619
|
audio: oggBuffer,
|
|
613
620
|
mimetype: 'audio/ogg; codecs=opus',
|
|
614
|
-
ptt:
|
|
621
|
+
ptt: false
|
|
615
622
|
},
|
|
616
623
|
{
|
|
617
624
|
upload: client.waUploadToServer,
|
|
@@ -627,14 +634,14 @@ async function buildAudioMessageFromBuffer(client, buffer, ext, fallbackSeconds
|
|
|
627
634
|
? fallbackSeconds
|
|
628
635
|
: 5
|
|
629
636
|
|
|
630
|
-
const audioMessage = prepared.audioMessage
|
|
637
|
+
const audioMessage = { ...prepared.audioMessage }
|
|
631
638
|
audioMessage.seconds = Math.max(1, Math.min(MAX_DURATION, Math.round(chosenSeconds)))
|
|
632
|
-
|
|
639
|
+
// Critical: ptt must stay false inside StickerMessage.audioMessage
|
|
640
|
+
audioMessage.ptt = false
|
|
633
641
|
audioMessage.mimetype = 'audio/ogg; codecs=opus'
|
|
634
642
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
643
|
+
// Drop waveform β official sound stickers do not include it
|
|
644
|
+
if (audioMessage.waveform) delete audioMessage.waveform
|
|
638
645
|
|
|
639
646
|
return audioMessage
|
|
640
647
|
}
|
|
@@ -650,9 +657,21 @@ async function sendCombinedAudioSticker(client, chat, stickerBuffer, isAnimated,
|
|
|
650
657
|
throw new Error('La conexiΓ³n Kage Baileys no tiene relayMessage disponible.')
|
|
651
658
|
}
|
|
652
659
|
|
|
660
|
+
// Re-inject EXIF with sound-sha256 so the webp is linked to the audio clip
|
|
661
|
+
let finalSticker = stickerBuffer
|
|
662
|
+
try {
|
|
663
|
+
const sha = audioMessage?.fileSha256
|
|
664
|
+
if (sha && (Buffer.isBuffer(sha) || sha instanceof Uint8Array)) {
|
|
665
|
+
const b64 = Buffer.from(sha).toString('base64')
|
|
666
|
+
finalSticker = await addStickerExif(stickerBuffer, 'Audio Sticker', 'Kage', b64)
|
|
667
|
+
}
|
|
668
|
+
} catch (e) {
|
|
669
|
+
console.warn('[AUDIO STICKER] EXIF sound-sha256 skip:', e?.message || e)
|
|
670
|
+
}
|
|
671
|
+
|
|
653
672
|
const prepared = await prepareWAMessageMedia(
|
|
654
673
|
{
|
|
655
|
-
sticker:
|
|
674
|
+
sticker: finalSticker,
|
|
656
675
|
isAnimated: Boolean(isAnimated)
|
|
657
676
|
},
|
|
658
677
|
{
|
|
@@ -665,20 +684,33 @@ async function sendCombinedAudioSticker(client, chat, stickerBuffer, isAnimated,
|
|
|
665
684
|
throw new Error('Kage Baileys no pudo preparar el sticker.')
|
|
666
685
|
}
|
|
667
686
|
|
|
687
|
+
// Official layout (from real WA clients / Baileys#2932):
|
|
688
|
+
// Message {
|
|
689
|
+
// audioStickerMessage (134): FutureProofMessage {
|
|
690
|
+
// message: {
|
|
691
|
+
// stickerMessage: {
|
|
692
|
+
// ...sticker fields...,
|
|
693
|
+
// premium: 0, // field 24
|
|
694
|
+
// emojis: "π", // field 25 (optional)
|
|
695
|
+
// audioMessage: {...} // field 26
|
|
696
|
+
// }
|
|
697
|
+
// }
|
|
698
|
+
// }
|
|
699
|
+
// }
|
|
700
|
+
// IMPORTANT: do NOT put stickerMessage at the top level, or clients show a plain sticker.
|
|
668
701
|
const stickerMessage = {
|
|
669
702
|
...prepared.stickerMessage,
|
|
670
703
|
isAnimated: Boolean(isAnimated),
|
|
704
|
+
premium: 0,
|
|
705
|
+
emojis: 'π',
|
|
671
706
|
audioMessage
|
|
672
707
|
}
|
|
673
708
|
|
|
674
|
-
const innerMessage = {
|
|
675
|
-
stickerMessage
|
|
676
|
-
}
|
|
677
|
-
|
|
678
709
|
const payload = {
|
|
679
|
-
stickerMessage,
|
|
680
710
|
audioStickerMessage: {
|
|
681
|
-
message:
|
|
711
|
+
message: {
|
|
712
|
+
stickerMessage
|
|
713
|
+
}
|
|
682
714
|
},
|
|
683
715
|
messageContextInfo: {
|
|
684
716
|
messageSecret: randomBytes(32)
|
|
@@ -686,16 +718,20 @@ async function sendCombinedAudioSticker(client, chat, stickerBuffer, isAnimated,
|
|
|
686
718
|
}
|
|
687
719
|
|
|
688
720
|
const encoded = proto.Message.encode(payload).finish()
|
|
689
|
-
const
|
|
721
|
+
const buf = Buffer.from(encoded)
|
|
722
|
+
const audioStickerTag = Buffer.from([0xb2, 0x08]) // field 134
|
|
723
|
+
const audioInsideTag = Buffer.from([0xd2, 0x01]) // field 26 inside StickerMessage
|
|
690
724
|
|
|
691
|
-
if (!
|
|
725
|
+
if (!buf.includes(audioStickerTag)) {
|
|
692
726
|
throw new Error('Kage Baileys no pudo serializar el campo audioStickerMessage (134).')
|
|
693
727
|
}
|
|
694
728
|
|
|
695
|
-
if (!
|
|
729
|
+
if (!buf.includes(audioInsideTag)) {
|
|
696
730
|
throw new Error('Kage Baileys no pudo serializar el audio dentro de StickerMessage (26).')
|
|
697
731
|
}
|
|
698
732
|
|
|
733
|
+
// Also ensure there is NO top-level stickerMessage tag (field 26 = 0xd2 0x01 at root would be wrong context,
|
|
734
|
+
// but the presence of only 134 is what matters for clients).
|
|
699
735
|
await client.relayMessage(chat, payload, {})
|
|
700
736
|
}
|
|
701
737
|
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Kage Baileys β native Audio / Sound Sticker support
|
|
4
|
+
*
|
|
5
|
+
* Builds the official WhatsApp sound-sticker payload:
|
|
6
|
+
*
|
|
7
|
+
* Message {
|
|
8
|
+
* audioStickerMessage (134): FutureProofMessage {
|
|
9
|
+
* message {
|
|
10
|
+
* stickerMessage (26): {
|
|
11
|
+
* ...webp fields...,
|
|
12
|
+
* premium: 0,
|
|
13
|
+
* emojis: "π",
|
|
14
|
+
* audioMessage (26): AudioMessage { ptt: false, ... }
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* messageContextInfo { messageSecret }
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* Implementation notes (from real client captures / Baileys#2932 / working sends):
|
|
22
|
+
* - Top-level field MUST be only audioStickerMessage (134), never also stickerMessage.
|
|
23
|
+
* - Audio is uploaded as normal audio (ptt: false), not a voice note.
|
|
24
|
+
* - Protobuf field 26 inside StickerMessage carries the AudioMessage.
|
|
25
|
+
* - We inject field 134 via a temporary encode hook so older generated WAProto still works.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const { randomBytes } = require('node:crypto');
|
|
29
|
+
const { proto } = require('../../WAProto');
|
|
30
|
+
|
|
31
|
+
const RAW = Symbol('kageAudioStickerRawFields');
|
|
32
|
+
|
|
33
|
+
function varint(n) {
|
|
34
|
+
const out = [];
|
|
35
|
+
n = n >>> 0;
|
|
36
|
+
while (n > 127) {
|
|
37
|
+
out.push((n & 0x7f) | 0x80);
|
|
38
|
+
n >>>= 7;
|
|
39
|
+
}
|
|
40
|
+
out.push(n);
|
|
41
|
+
return Buffer.from(out);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function ld(fieldNumber, body) {
|
|
45
|
+
const b = Buffer.isBuffer(body) ? body : Buffer.from(body);
|
|
46
|
+
return Buffer.concat([varint(fieldNumber * 8 + 2), varint(b.length), b]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Ensure Message.encode can emit field 134 even if the generated static code
|
|
51
|
+
* does not know about audioStickerMessage yet.
|
|
52
|
+
*/
|
|
53
|
+
function ensureAudioStickerEncodeSupport() {
|
|
54
|
+
const M = proto && proto.Message;
|
|
55
|
+
if (!M || M.__kageAudioStickerEncodeV1) return;
|
|
56
|
+
if (typeof M.encode !== 'function') return;
|
|
57
|
+
|
|
58
|
+
const previous = M.encode;
|
|
59
|
+
M.encode = function (message, writer) {
|
|
60
|
+
const out = previous.call(this, message, writer);
|
|
61
|
+
if (message && message[RAW] && Array.isArray(message[RAW])) {
|
|
62
|
+
for (const [field, body] of message[RAW]) {
|
|
63
|
+
out.uint32((field * 8 + 2) >>> 0).bytes(body);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
};
|
|
68
|
+
M.__kageAudioStickerEncodeV1 = true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Build a Message content object ready for generateWAMessageFromContent / relayMessage.
|
|
73
|
+
*
|
|
74
|
+
* @param {object} params
|
|
75
|
+
* @param {object} params.stickerMessage - prepared StickerMessage (from prepareWAMessageMedia)
|
|
76
|
+
* @param {object} params.audioMessage - prepared AudioMessage (from prepareWAMessageMedia, ptt:false)
|
|
77
|
+
* @param {boolean} [params.isAnimated]
|
|
78
|
+
* @param {string} [params.emoji='π']
|
|
79
|
+
*/
|
|
80
|
+
function buildAudioStickerContent({ stickerMessage, audioMessage, isAnimated = false, emoji = 'π' }) {
|
|
81
|
+
if (!stickerMessage) throw new Error('audio-sticker: missing stickerMessage');
|
|
82
|
+
if (!audioMessage) throw new Error('audio-sticker: missing audioMessage');
|
|
83
|
+
|
|
84
|
+
ensureAudioStickerEncodeSupport();
|
|
85
|
+
|
|
86
|
+
// Clone and force required fields
|
|
87
|
+
const audio = { ...audioMessage };
|
|
88
|
+
audio.ptt = false;
|
|
89
|
+
if (audio.mimetype == null) audio.mimetype = 'audio/ogg; codecs=opus';
|
|
90
|
+
if (audio.waveform) delete audio.waveform;
|
|
91
|
+
|
|
92
|
+
const sticker = {
|
|
93
|
+
...stickerMessage,
|
|
94
|
+
isAnimated: Boolean(isAnimated || stickerMessage.isAnimated),
|
|
95
|
+
premium: 0,
|
|
96
|
+
emojis: String(emoji || 'π'),
|
|
97
|
+
// Keep audioMessage on the object for libraries that know field 26;
|
|
98
|
+
// we also force-append it in the raw bytes below.
|
|
99
|
+
audioMessage: audio
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// --- Manual wire encoding of the nested structure ---
|
|
103
|
+
// FutureProofMessage.message = Message { stickerMessage = StickerMessage { ... + field 26 audio } }
|
|
104
|
+
let stickerBytes;
|
|
105
|
+
try {
|
|
106
|
+
stickerBytes = Buffer.from(proto.Message.StickerMessage.encode(sticker).finish());
|
|
107
|
+
} catch {
|
|
108
|
+
// Fallback: encode without audioMessage then append field 26
|
|
109
|
+
const { audioMessage: _drop, ...base } = sticker;
|
|
110
|
+
stickerBytes = Buffer.from(proto.Message.StickerMessage.encode(base).finish());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Always append AudioMessage as field 26 (tag 210 = 0xd2 0x01) so it is present
|
|
114
|
+
// even if the generated StickerMessage.encode ignores unknown properties.
|
|
115
|
+
const audioBytes = Buffer.from(proto.Message.AudioMessage.encode(audio).finish());
|
|
116
|
+
const stickerWithAudio = Buffer.concat([stickerBytes, ld(26, audioBytes)]);
|
|
117
|
+
|
|
118
|
+
// Message { stickerMessage (26) }
|
|
119
|
+
const innerMessage = ld(26, stickerWithAudio);
|
|
120
|
+
// FutureProofMessage { message (1) }
|
|
121
|
+
const futureProofBody = ld(1, innerMessage);
|
|
122
|
+
|
|
123
|
+
const content = proto.Message.create
|
|
124
|
+
? proto.Message.create({
|
|
125
|
+
messageContextInfo: {
|
|
126
|
+
messageSecret: randomBytes(32)
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
: {
|
|
130
|
+
messageContextInfo: {
|
|
131
|
+
messageSecret: randomBytes(32)
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
content[RAW] = [[134, futureProofBody]];
|
|
136
|
+
|
|
137
|
+
// Also set the high-level fields for any code that inspects the object
|
|
138
|
+
// (decode paths / logging). Encode will emit RAW field 134.
|
|
139
|
+
content.audioStickerMessage = {
|
|
140
|
+
message: {
|
|
141
|
+
stickerMessage: sticker
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
return content;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* High-level helper: prepare media + build content.
|
|
150
|
+
* Expects options.upload / options.logger like prepareWAMessageMedia.
|
|
151
|
+
*
|
|
152
|
+
* message.audioSticker = {
|
|
153
|
+
* sticker: Buffer | { url } | stream, // image or webp
|
|
154
|
+
* audio: Buffer | { url } | stream, // any audio WA accepts
|
|
155
|
+
* isAnimated?: boolean,
|
|
156
|
+
* emoji?: string,
|
|
157
|
+
* mimetype?: string // audio mimetype override
|
|
158
|
+
* }
|
|
159
|
+
*/
|
|
160
|
+
async function prepareAudioStickerMessage(message, options) {
|
|
161
|
+
const { prepareWAMessageMedia } = require('./messages.js');
|
|
162
|
+
const spec = message.audioSticker || message.soundSticker || message;
|
|
163
|
+
if (!spec || (!spec.sticker && !spec.image && !spec.webp)) {
|
|
164
|
+
throw new Error('audioSticker requires { sticker, audio }');
|
|
165
|
+
}
|
|
166
|
+
if (!spec.audio) {
|
|
167
|
+
throw new Error('audioSticker requires { sticker, audio }');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const stickerInput = spec.sticker || spec.image || spec.webp;
|
|
171
|
+
const isAnimated = Boolean(spec.isAnimated);
|
|
172
|
+
|
|
173
|
+
const [stickerPrep, audioPrep] = await Promise.all([
|
|
174
|
+
prepareWAMessageMedia(
|
|
175
|
+
{ sticker: stickerInput, isAnimated },
|
|
176
|
+
options
|
|
177
|
+
),
|
|
178
|
+
prepareWAMessageMedia(
|
|
179
|
+
{
|
|
180
|
+
audio: spec.audio,
|
|
181
|
+
mimetype: spec.mimetype || 'audio/ogg; codecs=opus',
|
|
182
|
+
ptt: false
|
|
183
|
+
},
|
|
184
|
+
options
|
|
185
|
+
)
|
|
186
|
+
]);
|
|
187
|
+
|
|
188
|
+
if (!stickerPrep?.stickerMessage) {
|
|
189
|
+
throw new Error('audio-sticker: failed to prepare sticker media');
|
|
190
|
+
}
|
|
191
|
+
if (!audioPrep?.audioMessage) {
|
|
192
|
+
throw new Error('audio-sticker: failed to prepare audio media');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return buildAudioStickerContent({
|
|
196
|
+
stickerMessage: stickerPrep.stickerMessage,
|
|
197
|
+
audioMessage: audioPrep.audioMessage,
|
|
198
|
+
isAnimated,
|
|
199
|
+
emoji: spec.emoji || 'π'
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
module.exports = {
|
|
204
|
+
buildAudioStickerContent,
|
|
205
|
+
prepareAudioStickerMessage,
|
|
206
|
+
ensureAudioStickerEncodeSupport,
|
|
207
|
+
RAW_SYMBOL: RAW
|
|
208
|
+
};
|
package/lib/Utils/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./generics.js"), exports);
|
|
18
18
|
__exportStar(require("./decode-wa-message.js"), exports);
|
|
19
19
|
__exportStar(require("./messages.js"), exports);
|
|
20
|
+
__exportStar(require("./audio-sticker.js"), exports);
|
|
20
21
|
__exportStar(require("./messages-media.js"), exports);
|
|
21
22
|
__exportStar(require("./validate-connection.js"), exports);
|
|
22
23
|
__exportStar(require("./crypto.js"), exports);
|
package/lib/Utils/messages.js
CHANGED
|
@@ -630,6 +630,12 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
630
630
|
delete message.raw;
|
|
631
631
|
return message;
|
|
632
632
|
}
|
|
633
|
+
// Native sound / audio sticker (WhatsApp field 134)
|
|
634
|
+
else if ((0, exports.hasNonNullishProperty)(message, 'audioSticker') ||
|
|
635
|
+
(0, exports.hasNonNullishProperty)(message, 'soundSticker')) {
|
|
636
|
+
const { prepareAudioStickerMessage } = require('./audio-sticker.js');
|
|
637
|
+
return await prepareAudioStickerMessage(message, options);
|
|
638
|
+
}
|
|
633
639
|
|
|
634
640
|
else if ((0, exports.hasNonNullishProperty)(message, 'code') ||
|
|
635
641
|
(0, exports.hasNonNullishProperty)(message, 'links') ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kage-baileys",
|
|
3
|
-
"version": "25.3.
|
|
3
|
+
"version": "25.3.21",
|
|
4
4
|
"description": "Kage Baileys full merge β Builders + mbuilder + Framework + advanced sticker packs + KAGE pairing + extended WAProto. Multi-device ready. FIXED: all core modules deduplicated, removed third-party libsignal-node fork.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kage-baileys",
|