Skip to content

AudioStickerMessage Builder ​

AudioStickerMessage is an advanced builder for creating and dispatching WhatsApp Sound Stickers (Audio Stickers) that combine visual stickers (Static WebP or Animated WebP/GIF) with an attached audio track (audio/ogg; codecs=opus).

It leverages WhatsApp Field 26 (tag 210) and FutureProof tag 134, optimized with strict constraints so that the resulting sticker can be saved to user favorites (Add to Favorites).


Key Features ​

  • Full Favorites Compatibility: Adapts and compresses WebP frames strictly to <= 480 KB (safely below WhatsApp's 500 KB favorites database ceiling), allowing users to star and save the sticker without errors.
  • Static & Animated Support: Supports still images (JPG, PNG) as well as short video clips (MP4, GIF).
  • Independent Duration Control: Constrains the visual loop to 3–5 seconds (adhering to WhatsApp sticker limits) while permitting audio playback up to 25 seconds.
  • Dual Protobuf Architecture: Retains the native stickerMessage root structure so the WhatsApp UI recognizes it as a favorite-eligible sticker item.

Usage Examples ​

1. Fluent Builder ​

javascript
import { AudioStickerMessage } from 'leaves-guardian';

const soundSticker = new AudioStickerMessage(client)
  .setSticker('./assets/clip.mp4')       // Video MP4 or Image
  .setAudio('./assets/sfx.mp3')          // MP3, M4A, or Voice Note
  .setPackName('Roxy Audio Pack')
  .setAuthor('Royal Engine Studio')
  .setMaxAudioDuration(25)               // Audio duration (max 25s)
  .setMaxVisualDuration(4)               // Visual animation loop (max 4s)
  .setAnimated(true);

await soundSticker.send(msg.chat.id);

2. Direct Socket Helper ​

javascript
await client.sendAudioSticker(chatId, stickerBuffer, audioBuffer, {
  packName: 'Sound Pack',
  author: 'Leaves Guardian',
  isAnimated: true,
  maxAudioDuration: 25
});

Method Reference ​

MethodDescription
.setSticker(source)Sets the visual sticker media (Buffer, URL, or filepath). Auto-converted to 512x512 WebP.
.setAudio(source)Sets the companion audio track (Buffer, URL, or filepath). Auto-converted to 48kHz OGG Opus.
.setPackName(name)Sets the sticker pack title in the EXIF metadata.
.setAuthor(author)Sets the author/publisher in the EXIF metadata.
.setMaxAudioDuration(sec)Sets the audio duration ceiling (default: 25s, max: 30s).
.setMaxVisualDuration(sec)Sets the animation loop limit (default: 4s, capped at 5s to guarantee <= 480 KB).
.setAnimated(bool)Flags the sticker as an animated moving sticker.
.build()Processes media inputs and outputs the complete audio sticker payload.
.send(jid, options)Uploads media to WhatsApp servers and relays the audio sticker message.

Released under the MIT License.