kage-baileys 25.3.24 → 25.3.26

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/WAProto/index.js CHANGED
@@ -1,201 +1,135 @@
1
1
  'use strict';
2
- /**
3
- * Fixed WAProto entrypoint for kage-baileys.
4
- * Missing generated index.js + shape differences between the old monolithic
5
- * WAProto and the new split protos under extras/WAProto.
6
- *
7
- * Also applies permanent Audio Sticker support (field 134 audioStickerMessage
8
- * on Message + field 26 audioMessage on StickerMessage) so plugins such as
9
- * stickeraudio / audiosticker / Tensura-style audioSticker can encode the
10
- * combined message without conflicting runtime hacks.
11
- *
12
- * Compatible with:
13
- * - kage native audio-sticker util (field 134)
14
- * - Tensura / Mahiru audioSticker.js patches (field 1074 wire tag = field 134)
15
- * Sets both __audioStickerKagePatchedV3 and __mahiruAudioStickerPatched so
16
- * external patches skip and do not double-encode.
17
- */
18
2
  const raw = require('../extras/WAProto');
19
3
  let proto = raw.proto || raw;
20
4
 
21
- // ---------- Normalize namespaces so legacy Baileys code keeps working ----------
22
-
23
- // 1. Message lives under E2E in the new protos
24
5
  if (proto.E2E && proto.E2E.Message && !proto.Message) {
25
6
  proto.Message = proto.E2E.Message;
26
7
  }
8
+ if (proto.E2E && proto.E2E.WebMessageInfo && !proto.WebMessageInfo) {
9
+ proto.WebMessageInfo = proto.E2E.WebMessageInfo;
10
+ }
27
11
 
28
- // 2. HistorySyncType location differs
29
12
  const histType =
30
13
  (proto.HistorySync && proto.HistorySync.HistorySync && proto.HistorySync.HistorySync.HistorySyncType) ||
31
14
  (proto.HistorySync && proto.HistorySync.HistorySyncType) ||
32
- (proto.Message && proto.Message.HistorySyncNotification && proto.Message.HistorySyncNotification.HistorySyncType) ||
33
- (proto.E2E && proto.E2E.Message && proto.E2E.Message.HistorySyncNotification && proto.E2E.Message.HistorySyncNotification.HistorySyncType);
34
-
15
+ (proto.Message && proto.Message.HistorySyncNotification && proto.Message.HistorySyncNotification.HistorySyncType);
35
16
  if (histType) {
36
- if (proto.HistorySync && !proto.HistorySync.HistorySyncType) {
37
- proto.HistorySync.HistorySyncType = histType;
38
- }
39
- if (proto.Message && !proto.Message.HistorySyncType) {
40
- proto.Message.HistorySyncType = histType;
41
- }
42
- }
43
-
44
- // 3. Common other aliases that appear in Baileys code
45
- if (proto.E2E) {
46
- if (proto.E2E.WebMessageInfo && !proto.WebMessageInfo) {
47
- proto.WebMessageInfo = proto.E2E.WebMessageInfo;
48
- }
17
+ if (proto.HistorySync && !proto.HistorySync.HistorySyncType) proto.HistorySync.HistorySyncType = histType;
18
+ if (proto.Message && !proto.Message.HistorySyncType) proto.Message.HistorySyncType = histType;
49
19
  }
50
20
 
51
- // Apply original field-name compatibility patches
52
- try {
53
- require('./compat.cjs')(proto);
54
- } catch (_) {}
55
-
56
- // ---------------------------------------------------------------------------
57
- // Audio Sticker support (permanent, idempotent, dual-flag for Tensura/Mahiru)
58
- // Protobuf tags:
59
- // Message.audioStickerMessage = 134 → tag 1074 (length-delimited)
60
- // StickerMessage.audioMessage = 26 → tag 210 (length-delimited)
61
- // The generated E2E.js lags behind WAProto.proto; this ensures encode /
62
- // fromObject always handle the fields used by audio-sticker plugins.
63
- // ---------------------------------------------------------------------------
64
- function applyAudioStickerSupport(p) {
65
- const M = p && p.Message;
66
- if (!M) return;
67
-
68
- // Already applied completely by this module
69
- if (M.__kageAudioStickerEncodeComplete) {
70
- M.__audioStickerKagePatchedV3 = true;
71
- M.__mahiruAudioStickerPatched = true;
72
- M.__audioStickerPatched = true;
73
- return;
74
- }
21
+ try { require('./compat.cjs')(proto); } catch (_) {}
75
22
 
76
- if (!M.StickerMessage || !M.AudioMessage || !M.FutureProofMessage) {
77
- // Classes missing → leave untouched so normal stickers still work
78
- return;
79
- }
23
+ /**
24
+ * Sound sticker (audio sticker) support — field layout from real WhatsApp clients:
25
+ * Message.audioStickerMessage = 134 (FutureProofMessage)
26
+ * StickerMessage.audioMessage = 26 (AudioMessage)
27
+ * StickerMessage.premium = 24
28
+ * StickerMessage.emojis = 25
29
+ */
30
+ function applySoundSticker(M) {
31
+ if (!M || M.__audioStickerPatched) return;
32
+ if (!M.StickerMessage || !M.AudioMessage) return;
80
33
 
81
- // --- StickerMessage.encode: append audioMessage (field 26 / tag 210) ---
82
- const previousStickerEncode = M.StickerMessage.encode;
34
+ // StickerMessage.encode → append audioMessage as field 26
35
+ const prevSticker = M.StickerMessage.encode;
83
36
  M.StickerMessage.encode = function (message, writer) {
84
- const hasAudio = message && Object.prototype.hasOwnProperty.call(message, 'audioMessage');
85
- const audio = hasAudio ? message.audioMessage : null;
86
- if (hasAudio) delete message.audioMessage;
37
+ const has = message && Object.prototype.hasOwnProperty.call(message, 'audioMessage');
38
+ const audio = has ? message.audioMessage : null;
39
+ if (has) delete message.audioMessage;
87
40
  try {
88
- const result = previousStickerEncode.call(this, message, writer);
89
- if (audio) {
90
- // field 26, wire type 2 → tag 210
91
- M.AudioMessage.encode(audio, result.uint32(210).fork()).ldelim();
41
+ const w = prevSticker.call(this, message, writer);
42
+ if (audio && M.AudioMessage) {
43
+ M.AudioMessage.encode(audio, w.uint32(210).fork()).ldelim(); // 26 << 3 | 2 = 210
92
44
  }
93
- return result;
45
+ return w;
94
46
  } finally {
95
- if (hasAudio) message.audioMessage = audio;
47
+ if (has) message.audioMessage = audio;
96
48
  }
97
49
  };
98
50
 
99
- // --- StickerMessage.fromObject: accept audioMessage ---
100
51
  if (typeof M.StickerMessage.fromObject === 'function') {
101
- const previousStickerFromObject = M.StickerMessage.fromObject;
102
- M.StickerMessage.fromObject = function (object) {
103
- const message = previousStickerFromObject.call(this, object);
104
- if (object && object.audioMessage) {
105
- message.audioMessage = M.AudioMessage.fromObject
106
- ? M.AudioMessage.fromObject(object.audioMessage)
107
- : object.audioMessage;
52
+ const prev = M.StickerMessage.fromObject;
53
+ M.StickerMessage.fromObject = function (obj) {
54
+ const m = prev.call(this, obj);
55
+ if (obj && obj.audioMessage) {
56
+ m.audioMessage = M.AudioMessage.fromObject
57
+ ? M.AudioMessage.fromObject(obj.audioMessage)
58
+ : obj.audioMessage;
108
59
  }
109
- return message;
60
+ return m;
110
61
  };
111
62
  }
112
-
113
- // Ensure prototype property exists (for hasOwnProperty / toObject paths)
114
63
  if (!Object.prototype.hasOwnProperty.call(M.StickerMessage.prototype, 'audioMessage')) {
115
64
  M.StickerMessage.prototype.audioMessage = null;
116
65
  }
117
66
 
118
- // --- Message.encode: emit audioStickerMessage (field 134 / tag 1074) ---
119
- const previousMessageEncode = M.encode;
67
+ // Message.encode → drop own stickerMessage when audioStickerMessage present, emit field 134
68
+ const prevMsg = M.encode;
120
69
  M.encode = function (message, writer) {
121
- const hasAudioSticker = message && Object.prototype.hasOwnProperty.call(message, 'audioStickerMessage');
122
- const hasSticker = message && Object.prototype.hasOwnProperty.call(message, 'stickerMessage');
123
- const audioSticker = hasAudioSticker ? message.audioStickerMessage : null;
124
- const stickerMessage = hasSticker ? message.stickerMessage : null;
70
+ const hasAS = message && Object.prototype.hasOwnProperty.call(message, 'audioStickerMessage');
71
+ const hasS = message && Object.prototype.hasOwnProperty.call(message, 'stickerMessage');
72
+ const as = hasAS ? message.audioStickerMessage : null;
73
+ const sm = hasS ? message.stickerMessage : null;
125
74
 
126
- if (hasAudioSticker) {
75
+ if (hasAS) {
127
76
  delete message.audioStickerMessage;
128
- // Prefer the nested sticker inside audioStickerMessage when present
129
- // (Tensura/Mahiru payload puts sticker under audioStickerMessage.message)
130
- if (hasSticker) delete message.stickerMessage;
77
+ if (hasS) delete message.stickerMessage;
131
78
  }
132
79
 
133
80
  try {
134
- const result = previousMessageEncode.call(this, message, writer);
135
- if (audioSticker) {
136
- // field 134, wire type 2 → tag 1074
137
- M.FutureProofMessage.encode(
138
- audioSticker,
139
- result.uint32(1074).fork()
140
- ).ldelim();
81
+ const w = prevMsg.call(this, message, writer);
82
+
83
+ // Emit field 134 if we have the wrapper
84
+ if (as && M.FutureProofMessage) {
85
+ M.FutureProofMessage.encode(as, w.uint32(1074).fork()).ldelim(); // 134 << 3 | 2 = 1074
141
86
  }
142
- return result;
87
+
88
+ // Also support RAW injected bytes (used by audio-sticker.js for exact wire match)
89
+ if (message && message[Symbol.for('kage.audioSticker.raw')]) {
90
+ for (const [field, body] of message[Symbol.for('kage.audioSticker.raw')]) {
91
+ w.uint32(((field << 3) | 2) >>> 0).bytes(body);
92
+ }
93
+ }
94
+
95
+ return w;
143
96
  } finally {
144
- if (hasAudioSticker && hasSticker) message.stickerMessage = stickerMessage;
145
- if (hasAudioSticker) message.audioStickerMessage = audioSticker;
97
+ if (hasAS && hasS) message.stickerMessage = sm;
98
+ if (hasAS) message.audioStickerMessage = as;
146
99
  }
147
100
  };
148
101
 
149
- // --- Message.fromObject: accept audioStickerMessage ---
150
102
  if (typeof M.fromObject === 'function') {
151
- const previousMessageFromObject = M.fromObject;
152
- M.fromObject = function (object) {
153
- const message = previousMessageFromObject.call(this, object);
154
- if (object && object.audioStickerMessage) {
155
- const inner = object.audioStickerMessage.message || object.audioStickerMessage;
156
- // Preserve nested stickerMessage.audioMessage if present (Tensura path)
157
- if (
158
- inner &&
159
- inner.stickerMessage &&
160
- object.audioStickerMessage.message &&
161
- object.audioStickerMessage.message.stickerMessage &&
162
- object.audioStickerMessage.message.stickerMessage.audioMessage
163
- ) {
103
+ const prev = M.fromObject;
104
+ M.fromObject = function (obj) {
105
+ const m = prev.call(this, obj);
106
+ if (obj && obj.audioStickerMessage) {
107
+ const inner = obj.audioStickerMessage.message || obj.audioStickerMessage;
108
+ if (inner && inner.stickerMessage &&
109
+ obj.audioStickerMessage.message &&
110
+ obj.audioStickerMessage.message.stickerMessage &&
111
+ obj.audioStickerMessage.message.stickerMessage.audioMessage) {
164
112
  inner.stickerMessage.audioMessage =
165
- object.audioStickerMessage.message.stickerMessage.audioMessage;
113
+ obj.audioStickerMessage.message.stickerMessage.audioMessage;
166
114
  }
167
- message.audioStickerMessage = M.FutureProofMessage.fromObject
115
+ m.audioStickerMessage = M.FutureProofMessage && M.FutureProofMessage.fromObject
168
116
  ? M.FutureProofMessage.fromObject({ message: inner })
169
117
  : { message: inner };
170
- // Match Tensura behavior: drop top-level sticker when audio sticker is set
171
- if (message.stickerMessage && inner && inner.stickerMessage) {
172
- delete message.stickerMessage;
173
- }
118
+ if (m.stickerMessage && inner && inner.stickerMessage) delete m.stickerMessage;
174
119
  }
175
- return message;
120
+ return m;
176
121
  };
177
122
  }
178
-
179
123
  if (!Object.prototype.hasOwnProperty.call(M.prototype, 'audioStickerMessage')) {
180
124
  M.prototype.audioStickerMessage = null;
181
125
  }
182
126
 
183
- // Dual flags: kage native + Tensura/Mahiru style so external patches skip
184
- M.__audioStickerKagePatchedV3 = true;
185
- M.__mahiruAudioStickerPatched = true;
186
- M.__audioStickerPatched = true;
187
- M.__tensuraAudioStickerPatched = true;
188
127
  M.__audioStickerPatched = true;
189
- M.__kageAudioStickerEncodeComplete = true;
190
128
  }
191
129
 
192
- try {
193
- applyAudioStickerSupport(proto);
194
- } catch (err) {
195
- // Never break loading of WAProto because of the optional audio-sticker patch
196
- if (typeof console !== 'undefined' && console.warn) {
197
- console.warn('[kage-baileys/WAProto] Audio Sticker patch skipped:', err && err.message);
198
- }
130
+ if (proto.Message) applySoundSticker(proto.Message);
131
+ if (proto.E2E && proto.E2E.Message && proto.E2E.Message !== proto.Message) {
132
+ applySoundSticker(proto.E2E.Message);
199
133
  }
200
134
 
201
135
  module.exports = { proto };
@@ -729,6 +729,7 @@ message Message {
729
729
  optional StatusQuestionAnswerMessage statusQuestionAnswerMessage = 105;
730
730
  optional FutureProofMessage questionReplyMessage = 106;
731
731
  optional QuestionResponseMessage questionResponseMessage = 107;
732
+ optional FutureProofMessage audioStickerMessage = 134;
732
733
  message AlbumMessage {
733
734
  optional uint32 expectedImageCount = 2;
734
735
  optional uint32 expectedVideoCount = 3;
@@ -1908,6 +1909,9 @@ message Message {
1908
1909
  optional bool isLottie = 21;
1909
1910
  optional string accessibilityLabel = 22;
1910
1911
  optional Message.MediaKeyDomain mediaKeyDomain = 23;
1912
+ optional int32 premium = 24;
1913
+ optional string emojis = 25;
1914
+ optional AudioMessage audioMessage = 26;
1911
1915
  }
1912
1916
  message StickerPackMessage {
1913
1917
  optional string stickerPackId = 1;
@@ -1,156 +1,192 @@
1
1
  'use strict';
2
- /**
3
- * Kage Baileys — native Audio / Sound Sticker support
4
- * Aligned with elaina-baileys working payload:
5
- * { __proto__: prepared, audioStickerMessage: { message: prepared }, messageContextInfo }
6
- * + Message.encode field 134 / StickerMessage field 26 (via WAProto patch)
7
- * + getMediaType recognizes audioStickerMessage → mediatype=sticker
8
- */
9
2
 
10
3
  const { randomBytes } = require('node:crypto');
11
- const { proto } = require('../../WAProto');
12
4
 
13
- const RAW = Symbol('kageAudioStickerRawFields');
5
+ function getProto() {
6
+ try {
7
+ return require('../../WAProto').proto || require('../../WAProto');
8
+ } catch {
9
+ return require('../../../WAProto').proto || require('../../../WAProto');
10
+ }
11
+ }
12
+
13
+ const RAW = Symbol.for('kage.audioSticker.raw');
14
14
 
15
15
  function varint(n) {
16
- const out = [];
17
- n = n >>> 0;
18
- while (n > 127) {
19
- out.push((n & 0x7f) | 0x80);
20
- n >>>= 7;
21
- }
22
- out.push(n);
23
- return Buffer.from(out);
16
+ const out = [];
17
+ n = n >>> 0;
18
+ while (n > 127) {
19
+ out.push((n & 0x7f) | 0x80);
20
+ n >>>= 7;
21
+ }
22
+ out.push(n);
23
+ return Buffer.from(out);
24
24
  }
25
25
 
26
26
  function ld(fieldNumber, body) {
27
- const b = Buffer.isBuffer(body) ? body : Buffer.from(body);
28
- return Buffer.concat([varint(fieldNumber * 8 + 2), varint(b.length), b]);
29
- }
30
-
31
- function ensureAudioStickerEncodeSupport() {
32
- const M = proto && proto.Message;
33
- if (!M || M.__kageAudioStickerEncodeV1) return;
34
- if (typeof M.encode !== 'function') return;
35
-
36
- const previous = M.encode;
37
- M.encode = function (message, writer) {
38
- const out = previous.call(this, message, writer);
39
- if (message && message[RAW] && Array.isArray(message[RAW])) {
40
- for (const [field, body] of message[RAW]) {
41
- out.uint32((field * 8 + 2) >>> 0).bytes(body);
42
- }
43
- }
44
- return out;
45
- };
46
- M.__kageAudioStickerEncodeV1 = true;
27
+ const b = Buffer.isBuffer(body) ? body : Buffer.from(body);
28
+ return Buffer.concat([varint((fieldNumber << 3) | 2), varint(b.length), b]);
47
29
  }
48
30
 
49
31
  /**
50
- * Build Message content for relayMessage / generateWAMessageFromContent.
51
- *
52
- * Uses elaina-style __proto__ so getMediaType sees stickerMessage via prototype
53
- * while encode (WAProto V3) only emits field 134 when audioStickerMessage is own prop.
32
+ * Build the exact wire bytes for a sound sticker (Baileys #2932 / WA sound sticker format).
33
+ * Field 134 -> FutureProofMessage { message: { stickerMessage: { ... + audioMessage } } }
54
34
  */
55
35
  function buildAudioStickerContent({ stickerMessage, audioMessage, isAnimated = false, emoji = '🔊' }) {
56
- if (!stickerMessage) throw new Error('audio-sticker: missing stickerMessage');
57
- if (!audioMessage) throw new Error('audio-sticker: missing audioMessage');
58
-
59
- ensureAudioStickerEncodeSupport();
60
-
61
- const audio = { ...audioMessage };
62
- audio.ptt = false;
63
- if (audio.mimetype == null) audio.mimetype = 'audio/ogg; codecs=opus';
64
- if (audio.waveform) delete audio.waveform;
65
-
66
- const sticker = {
67
- ...stickerMessage,
68
- isAnimated: Boolean(isAnimated || stickerMessage.isAnimated),
69
- premium: 0,
70
- emojis: String(emoji || '🔊'),
71
- audioMessage: audio
72
- };
73
-
74
- // prepared shape (own stickerMessage) — used as __proto__ for mediatype
75
- const prepared = {
76
- stickerMessage: sticker
77
- };
78
-
79
- // Manual wire body as backup (RAW) in case generated encode skips field 134
80
- let stickerBytes;
81
- try {
82
- stickerBytes = Buffer.from(proto.Message.StickerMessage.encode(sticker).finish());
83
- } catch {
84
- const { audioMessage: _drop, ...base } = sticker;
85
- stickerBytes = Buffer.from(proto.Message.StickerMessage.encode(base).finish());
36
+ if (!stickerMessage) throw new Error('audio-sticker: missing stickerMessage');
37
+ if (!audioMessage) throw new Error('audio-sticker: missing audioMessage');
38
+
39
+ const proto = getProto();
40
+ const M = proto.Message;
41
+ if (!M || !M.StickerMessage || !M.AudioMessage) {
42
+ throw new Error('audio-sticker: protobuf classes missing');
43
+ }
44
+
45
+ const audio = { ...audioMessage };
46
+ audio.ptt = false;
47
+ if (!audio.mimetype) audio.mimetype = 'audio/ogg; codecs=opus';
48
+ // WhatsApp sound stickers do not use waveform on the embedded audio
49
+ if (audio.waveform) delete audio.waveform;
50
+
51
+ const sticker = {
52
+ ...stickerMessage,
53
+ isAnimated: Boolean(isAnimated || stickerMessage.isAnimated),
54
+ premium: 0,
55
+ emojis: String(emoji || '🔊'),
56
+ audioMessage: audio
57
+ };
58
+
59
+ // Encode StickerMessage WITH the audioMessage field (26) appended by our patch or manually
60
+ let stickerBytes;
61
+ try {
62
+ stickerBytes = Buffer.from(M.StickerMessage.encode(sticker).finish());
63
+ } catch (e) {
64
+ // Fallback: encode base then manually append field 26
65
+ const { audioMessage: _a, ...base } = sticker;
66
+ stickerBytes = Buffer.from(M.StickerMessage.encode(base).finish());
67
+ const audioBytes = Buffer.from(M.AudioMessage.encode(audio).finish());
68
+ stickerBytes = Buffer.concat([stickerBytes, ld(26, audioBytes)]);
69
+ }
70
+
71
+ // Ensure field 26 is present even if the encode patch did not run
72
+ // (we already tried; if patch worked it is already there)
73
+
74
+ // Inner Message = { stickerMessage: <bytes of sticker+audio> }
75
+ // Field 26 of Message is stickerMessage
76
+ const innerMessageBytes = ld(26, stickerBytes);
77
+
78
+ // FutureProofMessage = { message: innerMessage }
79
+ // Field 1 of FutureProofMessage is message
80
+ const futureProofBody = ld(1, innerMessageBytes);
81
+
82
+ // prepared object that getMediaType still sees as sticker (via __proto__)
83
+ const prepared = {
84
+ stickerMessage: {
85
+ ...stickerMessage,
86
+ isAnimated: Boolean(isAnimated || stickerMessage.isAnimated),
87
+ premium: 0,
88
+ emojis: String(emoji || '🔊')
86
89
  }
87
- const audioBytes = Buffer.from(proto.Message.AudioMessage.encode(audio).finish());
88
- // Ensure field 26 present
89
- const stickerWithAudio = Buffer.concat([stickerBytes, ld(26, audioBytes)]);
90
- const innerMessage = ld(26, stickerWithAudio);
91
- const futureProofBody = ld(1, innerMessage);
92
-
93
- // Elaina working shape:
94
- // __proto__: prepared → getMediaType finds stickerMessage
95
- // audioStickerMessage → encode emits field 134; V3 patch drops own stickerMessage
96
- const content = {
97
- __proto__: prepared,
98
- audioStickerMessage: {
99
- message: prepared
100
- },
101
- messageContextInfo: {
102
- messageSecret: randomBytes(32)
90
+ };
91
+
92
+ // Final content shape used by relayMessage / generateWAMessageFromContent
93
+ const content = {
94
+ __proto__: prepared,
95
+ audioStickerMessage: {
96
+ message: {
97
+ stickerMessage: {
98
+ ...stickerMessage,
99
+ isAnimated: Boolean(isAnimated || stickerMessage.isAnimated),
100
+ premium: 0,
101
+ emojis: String(emoji || '🔊'),
102
+ audioMessage: audio
103
103
  }
104
- };
104
+ }
105
+ },
106
+ messageContextInfo: {
107
+ messageSecret: randomBytes(32)
108
+ }
109
+ };
105
110
 
106
- content[RAW] = [[134, futureProofBody]];
111
+ // Force correct wire bytes for field 134 (in case encode patch is missing or incomplete)
112
+ content[RAW] = [[134, futureProofBody]];
107
113
 
108
- return content;
114
+ // Install encode hook once so RAW fields are emitted
115
+ ensureRawEncodeHook(M);
116
+
117
+ return content;
109
118
  }
110
119
 
111
- async function prepareAudioStickerMessage(message, options) {
112
- const { prepareWAMessageMedia } = require('./messages.js');
113
- const spec = message.audioSticker || message.soundSticker || message;
114
- if (!spec || (!spec.sticker && !spec.image && !spec.webp)) {
115
- throw new Error('audioSticker requires { sticker, audio }');
116
- }
117
- if (!spec.audio) {
118
- throw new Error('audioSticker requires { sticker, audio }');
120
+ function ensureRawEncodeHook(M) {
121
+ if (!M || M.__kageRawEncodeHook) return;
122
+ const previous = M.encode;
123
+ if (typeof previous !== 'function') return;
124
+
125
+ M.encode = function (message, writer) {
126
+ // Drop own stickerMessage when audioStickerMessage is present (avoid double emission)
127
+ const hasAS = message && Object.prototype.hasOwnProperty.call(message, 'audioStickerMessage');
128
+ const hasS = message && Object.prototype.hasOwnProperty.call(message, 'stickerMessage');
129
+ let savedSticker;
130
+ if (hasAS && hasS) {
131
+ savedSticker = message.stickerMessage;
132
+ delete message.stickerMessage;
119
133
  }
120
134
 
121
- const stickerInput = spec.sticker || spec.image || spec.webp;
122
- const isAnimated = Boolean(spec.isAnimated);
123
-
124
- const [stickerPrep, audioPrep] = await Promise.all([
125
- prepareWAMessageMedia({ sticker: stickerInput, isAnimated }, options),
126
- prepareWAMessageMedia(
127
- {
128
- audio: spec.audio,
129
- mimetype: spec.mimetype || 'audio/ogg; codecs=opus',
130
- ptt: false
131
- },
132
- options
133
- )
134
- ]);
135
-
136
- if (!stickerPrep?.stickerMessage) {
137
- throw new Error('audio-sticker: failed to prepare sticker media');
138
- }
139
- if (!audioPrep?.audioMessage) {
140
- throw new Error('audio-sticker: failed to prepare audio media');
135
+ const out = previous.call(this, message, writer);
136
+
137
+ if (hasAS && savedSticker) message.stickerMessage = savedSticker;
138
+
139
+ // Append any RAW injected fields (exact wire bytes for field 134)
140
+ if (message && message[RAW] && Array.isArray(message[RAW])) {
141
+ for (const [field, body] of message[RAW]) {
142
+ out.uint32(((field << 3) | 2) >>> 0).bytes(body);
143
+ }
141
144
  }
145
+ return out;
146
+ };
147
+ M.__kageRawEncodeHook = true;
148
+ M.__audioStickerPatched = true;
149
+ }
142
150
 
143
- return buildAudioStickerContent({
144
- stickerMessage: stickerPrep.stickerMessage,
145
- audioMessage: audioPrep.audioMessage,
146
- isAnimated,
147
- emoji: spec.emoji || '🔊'
148
- });
151
+ async function prepareAudioStickerMessage(message, options) {
152
+ const { prepareWAMessageMedia } = require('./messages.js');
153
+ const spec = message.audioSticker || message.soundSticker || message;
154
+ if (!spec || (!spec.sticker && !spec.image && !spec.webp)) {
155
+ throw new Error('audioSticker requires { sticker, audio }');
156
+ }
157
+ if (!spec.audio) {
158
+ throw new Error('audioSticker requires { sticker, audio }');
159
+ }
160
+
161
+ const stickerInput = spec.sticker || spec.image || spec.webp;
162
+ const isAnimated = Boolean(spec.isAnimated);
163
+
164
+ const [stickerPrep, audioPrep] = await Promise.all([
165
+ prepareWAMessageMedia({ sticker: stickerInput, isAnimated }, options),
166
+ prepareWAMessageMedia(
167
+ {
168
+ audio: spec.audio,
169
+ mimetype: spec.mimetype || 'audio/ogg; codecs=opus',
170
+ ptt: false
171
+ },
172
+ options
173
+ )
174
+ ]);
175
+
176
+ if (!stickerPrep?.stickerMessage) throw new Error('audio-sticker: failed to prepare sticker');
177
+ if (!audioPrep?.audioMessage) throw new Error('audio-sticker: failed to prepare audio');
178
+
179
+ return buildAudioStickerContent({
180
+ stickerMessage: stickerPrep.stickerMessage,
181
+ audioMessage: audioPrep.audioMessage,
182
+ isAnimated,
183
+ emoji: spec.emoji || '🔊'
184
+ });
149
185
  }
150
186
 
151
187
  module.exports = {
152
- buildAudioStickerContent,
153
- prepareAudioStickerMessage,
154
- ensureAudioStickerEncodeSupport,
155
- RAW_SYMBOL: RAW
188
+ buildAudioStickerContent,
189
+ prepareAudioStickerMessage,
190
+ ensureRawEncodeHook,
191
+ RAW_SYMBOL: RAW
156
192
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kage-baileys",
3
- "version": "25.3.24",
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. [audio-sticker patch for Mahiru/Tensura compatibility] [audio-sticker patch for Mahiru/Tensura compatibility]",
3
+ "version": "25.3.26",
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",
7
7
  "baileys",