Skip to content
MessageBuilder
Documentation menu
ButtonV2

ButtonV2

Legacy

Builder for the legacy buttonsMessage format. Up to three simple quick replies.

Builders
v4.8/Baileys runtime
On this page

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.

For new features, use Button. ButtonV2 is kept for clients that do not support native flow.
buttonsMessage

Basic usage

button-v2.js
javascript
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

ParameterTypeDefaultDescription
msgrequiredWAMessage—A message containing buttonsMessage.
Returnthis
  • Throws an Error when msg.buttonsMessage is missing.

addButton

chainable
.addButton(displayText, buttonId)

Adds a simple quick reply button (type 1).

Parameter

ParameterTypeDefaultDescription
displayTextrequiredstring—Button text.
buttonIdstringcrypto.randomUUID()Button ID.
Returnthis
example
new 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

ParameterTypeDefaultDescription
objrequiredobject—A Baileys button object.
Returnthis

setRawThumbnail

chainable
.setRawThumbnail(thumbnail)

Sets the thumbnail directly from a raw base64 string, without fetching or resizing.

Parameter

ParameterTypeDefaultDescription
thumbnailrequiredstring—Base64 image data.
Returnthis

setThumbnail

chainable
.setThumbnail(path)

Sets the thumbnail from a URL or Buffer. The image is downloaded and resized to 300×300 during build.

Parameter

ParameterTypeDefaultDescription
pathrequiredstring | Buffer—Image URL or buffer.
Returnthis

setMedia

chainable
.setMedia(obj)

Fully overrides the media/header field, replacing the default dummy locationMessage.

Parameter

ParameterTypeDefaultDescription
objrequiredobject—Header media object.
Returnthis

build

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

ParameterTypeDefaultDescription
jidrequiredstring—Destination JID.
options.messageIdstring—Custom message ID.
ReturnPromise<WAMessage>

send

async
.send(jid, options)

Builds and sends through relayMessage with the standard native flow node.

Parameter

ParameterTypeDefaultDescription
jidrequiredstring—Destination JID.
options.messageIdstring—Custom message ID.
options.additionalNodesArray[]Additional XMPP nodes.
ReturnPromise<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.