kage-baileys 25.3.26 → 25.3.27

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,135 +1,198 @@
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
+ */
2
18
  const raw = require('../extras/WAProto');
3
19
  let proto = raw.proto || raw;
4
20
 
21
+ // ---------- Normalize namespaces so legacy Baileys code keeps working ----------
22
+
23
+ // 1. Message lives under E2E in the new protos
5
24
  if (proto.E2E && proto.E2E.Message && !proto.Message) {
6
25
  proto.Message = proto.E2E.Message;
7
26
  }
8
- if (proto.E2E && proto.E2E.WebMessageInfo && !proto.WebMessageInfo) {
9
- proto.WebMessageInfo = proto.E2E.WebMessageInfo;
10
- }
11
27
 
28
+ // 2. HistorySyncType location differs
12
29
  const histType =
13
30
  (proto.HistorySync && proto.HistorySync.HistorySync && proto.HistorySync.HistorySync.HistorySyncType) ||
14
31
  (proto.HistorySync && proto.HistorySync.HistorySyncType) ||
15
- (proto.Message && proto.Message.HistorySyncNotification && proto.Message.HistorySyncNotification.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
+
16
35
  if (histType) {
17
- if (proto.HistorySync && !proto.HistorySync.HistorySyncType) proto.HistorySync.HistorySyncType = histType;
18
- if (proto.Message && !proto.Message.HistorySyncType) proto.Message.HistorySyncType = 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
+ }
19
42
  }
20
43
 
21
- try { require('./compat.cjs')(proto); } catch (_) {}
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
+ }
49
+ }
22
50
 
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;
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
+ return;
73
+ }
33
74
 
34
- // StickerMessage.encode → append audioMessage as field 26
35
- const prevSticker = M.StickerMessage.encode;
75
+ if (!M.StickerMessage || !M.AudioMessage || !M.FutureProofMessage) {
76
+ // Classes missing → leave untouched so normal stickers still work
77
+ return;
78
+ }
79
+
80
+ // --- StickerMessage.encode: append audioMessage (field 26 / tag 210) ---
81
+ const previousStickerEncode = M.StickerMessage.encode;
36
82
  M.StickerMessage.encode = function (message, writer) {
37
- const has = message && Object.prototype.hasOwnProperty.call(message, 'audioMessage');
38
- const audio = has ? message.audioMessage : null;
39
- if (has) delete message.audioMessage;
83
+ const hasAudio = message && Object.prototype.hasOwnProperty.call(message, 'audioMessage');
84
+ const audio = hasAudio ? message.audioMessage : null;
85
+ if (hasAudio) delete message.audioMessage;
40
86
  try {
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
87
+ const result = previousStickerEncode.call(this, message, writer);
88
+ if (audio) {
89
+ // field 26, wire type 2 → tag 210
90
+ M.AudioMessage.encode(audio, result.uint32(210).fork()).ldelim();
44
91
  }
45
- return w;
92
+ return result;
46
93
  } finally {
47
- if (has) message.audioMessage = audio;
94
+ if (hasAudio) message.audioMessage = audio;
48
95
  }
49
96
  };
50
97
 
98
+ // --- StickerMessage.fromObject: accept audioMessage ---
51
99
  if (typeof M.StickerMessage.fromObject === 'function') {
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;
100
+ const previousStickerFromObject = M.StickerMessage.fromObject;
101
+ M.StickerMessage.fromObject = function (object) {
102
+ const message = previousStickerFromObject.call(this, object);
103
+ if (object && object.audioMessage) {
104
+ message.audioMessage = M.AudioMessage.fromObject
105
+ ? M.AudioMessage.fromObject(object.audioMessage)
106
+ : object.audioMessage;
59
107
  }
60
- return m;
108
+ return message;
61
109
  };
62
110
  }
111
+
112
+ // Ensure prototype property exists (for hasOwnProperty / toObject paths)
63
113
  if (!Object.prototype.hasOwnProperty.call(M.StickerMessage.prototype, 'audioMessage')) {
64
114
  M.StickerMessage.prototype.audioMessage = null;
65
115
  }
66
116
 
67
- // Message.encode → drop own stickerMessage when audioStickerMessage present, emit field 134
68
- const prevMsg = M.encode;
117
+ // --- Message.encode: emit audioStickerMessage (field 134 / tag 1074) ---
118
+ const previousMessageEncode = M.encode;
69
119
  M.encode = function (message, writer) {
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;
120
+ const hasAudioSticker = message && Object.prototype.hasOwnProperty.call(message, 'audioStickerMessage');
121
+ const hasSticker = message && Object.prototype.hasOwnProperty.call(message, 'stickerMessage');
122
+ const audioSticker = hasAudioSticker ? message.audioStickerMessage : null;
123
+ const stickerMessage = hasSticker ? message.stickerMessage : null;
74
124
 
75
- if (hasAS) {
125
+ if (hasAudioSticker) {
76
126
  delete message.audioStickerMessage;
77
- if (hasS) delete message.stickerMessage;
127
+ // Prefer the nested sticker inside audioStickerMessage when present
128
+ // (Tensura/Mahiru payload puts sticker under audioStickerMessage.message)
129
+ if (hasSticker) delete message.stickerMessage;
78
130
  }
79
131
 
80
132
  try {
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
133
+ const result = previousMessageEncode.call(this, message, writer);
134
+ if (audioSticker) {
135
+ // field 134, wire type 2 → tag 1074
136
+ M.FutureProofMessage.encode(
137
+ audioSticker,
138
+ result.uint32(1074).fork()
139
+ ).ldelim();
86
140
  }
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;
141
+ return result;
96
142
  } finally {
97
- if (hasAS && hasS) message.stickerMessage = sm;
98
- if (hasAS) message.audioStickerMessage = as;
143
+ if (hasAudioSticker && hasSticker) message.stickerMessage = stickerMessage;
144
+ if (hasAudioSticker) message.audioStickerMessage = audioSticker;
99
145
  }
100
146
  };
101
147
 
148
+ // --- Message.fromObject: accept audioStickerMessage ---
102
149
  if (typeof M.fromObject === 'function') {
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) {
150
+ const previousMessageFromObject = M.fromObject;
151
+ M.fromObject = function (object) {
152
+ const message = previousMessageFromObject.call(this, object);
153
+ if (object && object.audioStickerMessage) {
154
+ const inner = object.audioStickerMessage.message || object.audioStickerMessage;
155
+ // Preserve nested stickerMessage.audioMessage if present (Tensura path)
156
+ if (
157
+ inner &&
158
+ inner.stickerMessage &&
159
+ object.audioStickerMessage.message &&
160
+ object.audioStickerMessage.message.stickerMessage &&
161
+ object.audioStickerMessage.message.stickerMessage.audioMessage
162
+ ) {
112
163
  inner.stickerMessage.audioMessage =
113
- obj.audioStickerMessage.message.stickerMessage.audioMessage;
164
+ object.audioStickerMessage.message.stickerMessage.audioMessage;
114
165
  }
115
- m.audioStickerMessage = M.FutureProofMessage && M.FutureProofMessage.fromObject
166
+ message.audioStickerMessage = M.FutureProofMessage.fromObject
116
167
  ? M.FutureProofMessage.fromObject({ message: inner })
117
168
  : { message: inner };
118
- if (m.stickerMessage && inner && inner.stickerMessage) delete m.stickerMessage;
169
+ // Match Tensura behavior: drop top-level sticker when audio sticker is set
170
+ if (message.stickerMessage && inner && inner.stickerMessage) {
171
+ delete message.stickerMessage;
172
+ }
119
173
  }
120
- return m;
174
+ return message;
121
175
  };
122
176
  }
177
+
123
178
  if (!Object.prototype.hasOwnProperty.call(M.prototype, 'audioStickerMessage')) {
124
179
  M.prototype.audioStickerMessage = null;
125
180
  }
126
181
 
127
- M.__audioStickerPatched = true;
182
+ // Dual flags: kage native + Tensura/Mahiru style so external patches skip
183
+ M.__audioStickerKagePatchedV3 = true;
184
+ M.__mahiruAudioStickerPatched = true;
185
+ M.__tensuraAudioStickerPatched = true;
186
+ M.__kageAudioStickerEncodeComplete = true;
128
187
  }
129
188
 
130
- if (proto.Message) applySoundSticker(proto.Message);
131
- if (proto.E2E && proto.E2E.Message && proto.E2E.Message !== proto.Message) {
132
- applySoundSticker(proto.E2E.Message);
189
+ try {
190
+ applyAudioStickerSupport(proto);
191
+ } catch (err) {
192
+ // Never break loading of WAProto because of the optional audio-sticker patch
193
+ if (typeof console !== 'undefined' && console.warn) {
194
+ console.warn('[kage-baileys/WAProto] Audio Sticker patch skipped:', err && err.message);
195
+ }
133
196
  }
134
197
 
135
198
  module.exports = { proto };
@@ -729,7 +729,6 @@ 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;
733
732
  message AlbumMessage {
734
733
  optional uint32 expectedImageCount = 2;
735
734
  optional uint32 expectedVideoCount = 3;
@@ -1909,9 +1908,6 @@ message Message {
1909
1908
  optional bool isLottie = 21;
1910
1909
  optional string accessibilityLabel = 22;
1911
1910
  optional Message.MediaKeyDomain mediaKeyDomain = 23;
1912
- optional int32 premium = 24;
1913
- optional string emojis = 25;
1914
- optional AudioMessage audioMessage = 26;
1915
1911
  }
1916
1912
  message StickerPackMessage {
1917
1913
  optional string stickerPackId = 1;
@@ -1,192 +1,156 @@
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
+ */
2
9
 
3
10
  const { randomBytes } = require('node:crypto');
11
+ const { proto } = require('../../WAProto');
4
12
 
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');
13
+ const RAW = Symbol('kageAudioStickerRawFields');
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 << 3) | 2), varint(b.length), b]);
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;
29
47
  }
30
48
 
31
49
  /**
32
- * Build the exact wire bytes for a sound sticker (Baileys #2932 / WA sound sticker format).
33
- * Field 134 -> FutureProofMessage { message: { stickerMessage: { ... + audioMessage } } }
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.
34
54
  */
35
55
  function buildAudioStickerContent({ stickerMessage, audioMessage, isAnimated = false, emoji = '🔊' }) {
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 || '🔊')
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());
89
86
  }
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
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)
103
103
  }
104
- }
105
- },
106
- messageContextInfo: {
107
- messageSecret: randomBytes(32)
108
- }
109
- };
104
+ };
110
105
 
111
- // Force correct wire bytes for field 134 (in case encode patch is missing or incomplete)
112
- content[RAW] = [[134, futureProofBody]];
106
+ content[RAW] = [[134, futureProofBody]];
113
107
 
114
- // Install encode hook once so RAW fields are emitted
115
- ensureRawEncodeHook(M);
116
-
117
- return content;
108
+ return content;
118
109
  }
119
110
 
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;
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 }');
133
119
  }
134
120
 
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
- }
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');
144
141
  }
145
- return out;
146
- };
147
- M.__kageRawEncodeHook = true;
148
- M.__audioStickerPatched = true;
149
- }
150
142
 
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
- });
143
+ return buildAudioStickerContent({
144
+ stickerMessage: stickerPrep.stickerMessage,
145
+ audioMessage: audioPrep.audioMessage,
146
+ isAnimated,
147
+ emoji: spec.emoji || '🔊'
148
+ });
185
149
  }
186
150
 
187
151
  module.exports = {
188
- buildAudioStickerContent,
189
- prepareAudioStickerMessage,
190
- ensureRawEncodeHook,
191
- RAW_SYMBOL: RAW
152
+ buildAudioStickerContent,
153
+ prepareAudioStickerMessage,
154
+ ensureAudioStickerEncodeSupport,
155
+ RAW_SYMBOL: RAW
192
156
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kage-baileys",
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.",
3
+ "version": "25.3.27",
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]",
5
5
  "keywords": [
6
6
  "kage-baileys",
7
7
  "baileys",