Skip to content

Message Builders Overview ​

Leaves Guardian includes a comprehensive suite of 12 Message Builders (Layer 5) for constructing complex, interactive, and media-rich WhatsApp message payloads with a fluent, chainable API.

All builders inherit from BaseBuilder, providing a shared set of capabilities including text templating, channel forwarding, external ad replies, user mentions, and message quoting.


Available Builders at a Glance ​

Builder ClassTarget Payload TypeKey Capabilities
TextMessageextendedTextMessageFormatted text, link preview toggles, advanced link preview (v0.4.0), mentions, and quotes.
ButtonMessageinteractiveMessageNative flow buttons (Quick Reply, CTA URL, CTA Copy, CTA Call, Dropdowns) and carousel conversion .toCard().
ButtonMessageV2buttonsMessageLegacy buttons message using headerType: 6 (Location Header) ensuring quick reply visibility on older clients.
LocationMessageinteractiveMessageInteractive location card with pin 📍, bold title, avatar thumbnail, and buttons.
ListMessageinteractiveMessageMulti-section selection menu lists with titles and descriptions.
CarouselMessageinteractiveMessageMulti-card horizontal carousel structures with per-card buttons and images, supporting array insertion.
AlbumMessagealbumMessageNative WhatsApp photo and video collection automatically grouped into a unified grid album card.
OrderMessageorderMessageOfficial WhatsApp catalog invoice and order summary message with micro-unit currency calculation.
StickerPackMessagestickerPackMessageOfficial WhatsApp sticker pack bundle distribution complete with tray cover and emoji associations.
MediaMessageUnified MediaSingle builder for Image, Video, Audio/PTT, Document, and Sticker.
StickerMessagestickerMessageWebP sticker conversion with custom EXIF pack and author metadata.
ProductMessageproductMessageProduct catalog cards with currency-formatted pricing and retailer IDs.
PollMessagepollCreationMessageSingle-select or multi-select polling and voting messages.
AIRichMessageinteractiveMessageStructured response cards with markdown, code snippets, source badges, and interactive HTML widgets.
CanvasMessageinteractiveMessageHTML-based canvas payload generator with domain whitelisting.
EventMessageeventMessageWhatsApp native group calendar event invitations.
RichMessageinteractiveMessageVisual flex cards with headers, footers, badges, and action buttons.
A2UIMessageinteractiveMessageAgent-to-User Interface generative UI widget based on Meta Bloks / StarCore.

Shared Methods (BaseBuilder) ​

Because every builder extends BaseBuilder, the following chainable methods are universally available on all builders:

javascript
builder
  .setTitle('Header Title')
  .setBody('Main body content with {{variable}} support')
  .setFooter('Footer note');

2. Built-in String Templating (setVars) ​

You can embed placeholders in any text field and resolve them dynamically using .setVars():

javascript
builder
  .setBody('Hello {{name}}, your order #{{orderId}} is ready!')
  .setVars({ name: 'Rafa', orderId: '84920' });

3. External Ad Reply Preview (setAdReply) ​

Attach rich link preview metadata (image banner, title, source URL) to the message payload:

javascript
builder.setAdReply({
  title: 'Leaves Guardian Documentation',
  body: 'Enterprise Baileys Wrapper',
  thumbnailUrl: 'https://example.com/cover.jpg',
  sourceUrl: 'https://leaves-guardian.dev',
  previewType: 'PHOTO'
});

4. Channel Forwarding (setChannelForward) ​

Simulate forwarding context from a verified WhatsApp newsletter/channel:

javascript
builder.setChannelForward({
  channelJid: '120363000000000000@newsletter',
  channelName: 'Official Announcements'
});

5. Mentions and Quoting ​

javascript
builder
  .mention(['628123456789@s.whatsapp.net'])
  .quote(originalIncomingMessage);

Dispatching Builders ​

Builders can be sent in two equivalent ways:

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

const message = new TextMessage()
  .setBody('Hello world!');

await client.sendMessage(msg.chat.id, message);

Option B: Via .send() on the Builder Instance ​

javascript
const message = new TextMessage(client)
  .setBody('Hello world!');

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

Released under the MIT License.