Builder for buttonsMessage, the older button format that some clients still support. Use it for backward compatibility with simple quick replies. For new features, use Button instead.
Confirm your order
Order #1042 ships today. Is the delivery address correct?
ButtonV2 · up to 3 buttons
Basic usage
import { ButtonV2 } from './lib/MessageBuilder.js';
await new ButtonV2(sock)
.setTitle('Confirmation')
.setBody('Your order ships today.')
.addButton('Yes', 'yes')
.addButton('No', 'no')
.send(jid);Methods
loadFrom
chainable.loadFrom(msg)Rebuilds the builder state from an existing buttonsMessage.
Parameter
| Parameter | Type | Default | Description |
|---|---|---|---|
msgrequired | WAMessage | — | A message containing buttonsMessage. |
this- Throws an Error when msg.buttonsMessage is missing.
addButton
chainable.addButton(displayText, buttonId)Adds a simple quick reply button (type 1).
Parameter
| Parameter | Type | Default | Description |
|---|---|---|---|
displayTextrequired | string | — | Button text. |
buttonId | string | crypto.randomUUID() | Button ID. |
thisnew ButtonV2(sock)
.setBody('Confirm your order')
.addButton('Yes', 'yes')
.addButton('No', 'no')
.send(jid);addRawButton
chainable.addRawButton(obj)Adds a raw button object for non-standard schemas.
Parameter
| Parameter | Type | Default | Description |
|---|---|---|---|
objrequired | object | — | A Baileys button object. |
thissetRawThumbnail
chainable.setRawThumbnail(thumbnail)Sets the thumbnail directly from a raw base64 string, without fetching or resizing.
Parameter
| Parameter | Type | Default | Description |
|---|---|---|---|
thumbnailrequired | string | — | Base64 image data. |
thissetThumbnail
chainable.setThumbnail(path)Sets the thumbnail from a URL or Buffer. The image is downloaded and resized to 300×300 during build.
Parameter
| Parameter | Type | Default | Description |
|---|---|---|---|
pathrequired | string | Buffer | — | Image URL or buffer. |
thissetMedia
chainable.setMedia(obj)Fully overrides the media/header field, replacing the default dummy locationMessage.
Parameter
| Parameter | Type | Default | Description |
|---|---|---|---|
objrequired | object | — | Header media object. |
thisbuild
async.build(jid, options)Assembles the buttonsMessage. If setMedia was not called, the header is built from a dummy locationMessage (headerType 6) with the thumbnail as jpegThumbnail.
Parameter
| Parameter | Type | Default | Description |
|---|---|---|---|
jidrequired | string | — | Destination JID. |
options.messageId | string | — | Custom message ID. |
Promise<WAMessage>send
async.send(jid, options)Builds and sends through relayMessage with the standard native flow node.
Parameter
| Parameter | Type | Default | Description |
|---|---|---|---|
jidrequired | string | — | Destination JID. |
options.messageId | string | — | Custom message ID. |
options.additionalNodes | Array | [] | Additional XMPP nodes. |
Promise<WAMessage>- Throws Error("ButtonV2 requires at least one button") when no button has been added.
Notes
When should I use ButtonV2?
Only when the target client truly does not support interactiveMessage. For a modern experience, Button is more flexible and is not limited to three quick replies.
The image header trick
buttonsMessage has no native media header. The library uses a dummy locationMessage so the thumbnail still appears. This behavior is intentional, not a bug.
The image header uses locationMessage
When setMedia() is not called, the library creates a dummy locationMessage withheaderType: 6. The thumbnail is sent as jpegThumbnail. This is a compatibility trick, not a bug.