Skip to content
MessageBuilder
Documentation menu
Button

Button

Popular

Builder for interactiveMessage with native flow buttons: quick reply, CTA, copy, call, reminder, address, location, and lists.

Builders
v4.8/Baileys runtime
On this page

Builder for interactiveMessage with native flow buttons: quick reply, CTA URL, copy code, call, reminder, address, location, and nested lists. This is the primary choice for modern interactive menus.

quick_replycta_urlcta_copycta_callsingle_selectaddress_messagesend_location
9 button types

Basic usage

Chain setters and adders, then call send(). Every method returns the same instance.

button.js
javascript
import { Button } from './lib/MessageBuilder.js';

const button = new Button(sock)
  .setBody('Pick an option below.')
  .setFooter('MessageBuilder v4.8')
  .addReply('Hello', 'hello')
  .addUrl('Open website', 'https://example.com', true)
  .addCopy('Copy code', 'MB-4.8');

await button.send(jid);

Methods

loadFrom

chainable
.loadFrom(msg)

Rebuilds the builder state from an existing interactiveMessage, such as an incoming message you want to edit or resend.

Parameter

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

setImage

chainable
.setImage(path, options)

Sets an image on the message header.

Parameter

ParameterTypeDefaultDescription
pathrequiredstring | Buffer—Image URL or raw buffer.
optionsobject{}Merged into the media object, for example caption or jpegThumbnail.
Returnthis
example
button.setImage('https://example.com/banner.jpg', { caption: 'Today’s menu' });

setDocument

chainable
.setDocument(path, options)

Sets a document on the message header.

Parameter

ParameterTypeDefaultDescription
pathrequiredstring | Buffer—Document URL or buffer.
optionsobject{}Additional media options.
Returnthis

setMedia

chainable
.setMedia(obj)

Fully overrides the header media object. Useful for media types without a dedicated helper.

Parameter

ParameterTypeDefaultDescription
objrequiredobject—A Baileys media object such as videoMessage or productMessage.
Returnthis
  • Must be a plain object; arrays or null throw a TypeError.

clearButtons

chainable
.clearButtons()

Removes every button already added without touching the body, footer, or media.

Returnthis

setParams

chainable
.setParams(obj)

Fully overrides messageParamsJson on nativeFlowMessage. Normally populated by addSelection and similar methods.

Parameter

ParameterTypeDefaultDescription
objrequiredobject—Native flow parameter object.
Returnthis

addButton

chainable
.addButton(name, params)

Generic method for adding any native flow button manually. Every addX helper is built on top of it.

Parameter

ParameterTypeDefaultDescription
namerequiredstring—Native flow name, such as 'quick_reply' or 'cta_url'.
paramsrequiredobject | string—Parameter object; automatically JSON.stringify’d when an object is passed.
Returnthis
example
button.addButton('quick_reply', { display_text: 'Hello', id: 'hello' });

addSelection

chainable
.addSelection(title, options)

Adds a list button (single_select) and makes it the active selection for the following makeSection and makeRow calls.

Parameter

ParameterTypeDefaultDescription
titlerequiredstring—List button label.
optionsobject{}Merged into buttonParamsJson, for example initial sections.
Returnthis
example
button
  .addSelection('View menu')
  .makeSection('Food')
  .makeRow('Fried rice', '$8', 'Spice level adjustable', 'fried-rice');

makeSection

chainable
.makeSection(title, highlight_label)

Adds a new section to the active list and makes it the target for the next makeRow calls.

Parameter

ParameterTypeDefaultDescription
titlestring''Section title.
highlight_labelstring''Small label shown next to the section title.
Returnthis
  • Throws an Error when no selection is active.

makeRow

chainable
.makeRow(header, title, description, id)

Adds one row to the active list section.

Parameter

ParameterTypeDefaultDescription
headerstring''Row header text.
titlestring''Primary row title.
descriptionstring''Secondary description.
idstring''ID returned when the row is selected.
Returnthis
  • Throws an Error when no selection and section are active.

addReply

chainable
.addReply(display_text, id, options)

Adds a quick reply button.

Parameter

ParameterTypeDefaultDescription
display_textrequiredstring—Text shown on the button.
idrequiredstring—ID returned when the button is pressed.
optionsobject{}Additional fields for buttonParamsJson.
Returnthis

addCall

chainable
.addCall(display_text, id, options)

Adds a call button (cta_call).

Parameter

ParameterTypeDefaultDescription
display_textrequiredstring—Button text.
idrequiredstring—Action ID.
optionsobject{}Additional fields.
Returnthis

addReminder

chainable
.addReminder(display_text, id, options)

Adds a reminder button (cta_reminder).

Parameter

ParameterTypeDefaultDescription
display_textrequiredstring—Button text.
idrequiredstring—Action ID.
optionsobject{}Additional fields.
Returnthis

addCancelReminder

chainable
.addCancelReminder(display_text, id, options)

Adds a cancel-reminder button (cta_cancel_reminder).

Parameter

ParameterTypeDefaultDescription
display_textrequiredstring—Button text.
idrequiredstring—Action ID.
optionsobject{}Additional fields.
Returnthis

addAddress

chainable
.addAddress(display_text, id, options)

Adds an address request button (address_message).

Parameter

ParameterTypeDefaultDescription
display_textrequiredstring—Button text.
idrequiredstring—Action ID.
optionsobject{}Additional fields.
Returnthis

addLocation

chainable
.addLocation(options)

Adds a send-location button (send_location).

Parameter

ParameterTypeDefaultDescription
optionsobject{}Location button parameters.
Returnthis

addUrl

chainable
.addUrl(display_text, url, webview_interaction, options)

Adds a link button (cta_url).

Parameter

ParameterTypeDefaultDescription
display_textrequiredstring—Button text.
urlrequiredstring—Link destination.
webview_interactionbooleanfalseOpen in an in-app webview when true.
optionsobject{}Additional fields, also merged into the button object.
Returnthis
example
button.addUrl('Open documentation', 'https://example.com/docs', true);

addCopy

chainable
.addCopy(display_text, copy_code, options)

Adds a copy-code button (cta_copy).

Parameter

ParameterTypeDefaultDescription
display_textrequiredstring—Button text.
copy_coderequiredstring—Text copied to the clipboard.
optionsobject{}Additional fields.
Returnthis

toCard

async
.toCard()

Assembles the card object (body, footer, header with media, nativeFlowMessage) without wrapping it in a full WhatsApp message.

ReturnPromise<object>

build

async
.build(jid, options)

Assembles a complete WAMessage from the current builder state. The message is not sent.

Parameter

ParameterTypeDefaultDescription
jidrequiredstring—Destination JID.
options.messageIdstring—Custom message ID.
optionsobject—Other options passed to generateWAMessageFromContent.
ReturnPromise<WAMessage>

send

async
.send(jid, options)

Builds and sends through client.relayMessage(), adding the biz > interactive > native_flow XMPP node required by WhatsApp.

Parameter

ParameterTypeDefaultDescription
jidrequiredstring—Destination JID.
options.messageIdstring—Custom message ID.
options.additionalNodesArray[]Additional XMPP nodes.
optionsobject—Other options passed to relayMessage.
ReturnPromise<WAMessage>
example
const msg = await new Button(sock)
  .setBody('Pick an option below.')
  .setFooter('MessageBuilder v4.8')
  .addReply('Hello', 'hello')
  .addUrl('Open website', 'https://example.com')
  .send(jid);

console.log(msg.key.id);

paramsList

Button.paramsList is a static object, not a method. It documents the advanced parameter schemas for a few button types.

TypeFields
limited_time_offer
text: stringurl: stringcopy_code: stringexpiration_time: number
bottom_sheet
in_thread_buttons_limit: numberdivider_indices: number[]list_title: stringbutton_title: string
tap_target_configuration
title: stringdescription: stringcanonical_url: stringdomain: stringbuttonIndex: number

Notes

The native flow node is required

Without the biz > interactive > native_flow node, a message may send successfully but WhatsApp will not render the buttons. send() adds this node automatically.

Practical limits

WhatsApp limits how many buttons render cleanly. When you have many options, use single_select (a list) instead of stacking quick replies.

See the animation

Open the playground to edit button text, add list sections, and copy the generated code.