Skip to content
MessageBuilder
Documentation menu
AIRich

AIRich

15 primitives

AI-style rich responses: text, code, tables, images, video, products, posts, widgets, and follow-up suggestions.

Builders
v4.8/Baileys runtime
On this page

Builder for richResponseMessage: text, code, tables, images, video, products, posts, sources, widgets, footer actions, and follow-up suggestions. Every block can be assigned an ID and later replaced, inserted, or deleted.

15

primitives

2

payloads

∞

layouts

richResponseMessage

Usage

Every addX() call appends one or more nodes. Give an id to blocks that may change, then use replace or insertAt to mutate them later.

airich.js
javascript
import { AIRich, Enums } from './lib/MessageBuilder.js';

const rich = new AIRich(sock, {
  dynamic: true,
  unsupportedTypeAlert: true,
});

rich
  .setTitle('Assistant')
  .addText('Here is a summary of the article.')
  .addCode('javascript', 'const total = items.length;')
  .addTable([
    ['Metric', 'Value'],
    ['Orders', '128'],
    ['Revenue', '$4.2k'],
  ])
  .addImage('https://example.com/chart.png', {
    width: 640,
    height: 360,
    id: 'chart',
  })
  .addSuggest(['Explain in more detail', 'Make it shorter']);

await rich.send(jid);

Primitives

Fifteen content methods are available. All of them are chainable unless noted otherwise.

MethodPurposeTypename
addTextMarkdown text + inline entitiesGenAIMarkdownTextUXPrimitive
addFOATextLiteral textFOATextPrimitive
addCodeCode block with highlightingGenAICodeUXPrimitive
addTableTable with a header rowGenATableUXPrimitive
addSourceSource listGenAISearchResultPrimitive
addReelsHorizontal reels cardsGenAIReelPrimitive
addImageOne or more imagesGenAIImaginePrimitive
addVideoVideo + automatic metadataGenAIImaginePrimitive
addProductProduct cardsGenAIProductItemCardPrimitive
addPostSocial media post cardsGenAIPostPrimitive
addMetadataSmall metadata textGenAIMetadataTextPrimitive
addTipTip with a ⓘ prefixGenAIMetadataTextPrimitive
addWidgetThird-party widgetGenAI3PExtWidgetPrimitive
addFooterActionFooter action buttonsGenAIFooterActionPrimitive
addSuggestFollow-up suggestion pillsGenAIFollowUpSuggestionPillPrimitive

Methods

loadFrom

chainable
.loadFrom(msg)

Rebuilds the full state from an existing richResponseMessage, including sections, submessages, and extraPayload.

Parameter

ParameterTypeDefaultDescription
msgrequiredWAMessage—A rich response message.
Returnthis
  • Supports three structures: botForwardedMessage.message.richResponseMessage, botForwardedMessage.richResponseMessage, and a direct richResponseMessage.

setResponseId

chainable
.setResponseId(id)

Sets responseId manually.

Parameter

ParameterTypeDefaultDescription
idrequiredstring—Response ID.
Returnthis

refreshResponseId

chainable
.refreshResponseId()

Regenerates responseId using crypto.randomUUID().

Returnthis

setBotResponseId

chainable
.setBotResponseId(id)

Sets botResponseId manually.

Parameter

ParameterTypeDefaultDescription
idrequiredstring—Bot response ID.
Returnthis

refreshBotResponseId

chainable
.refreshBotResponseId()

Regenerates botResponseId.

Returnthis

addText

chainable
.addText(text, options)

Adds a markdown text block (GenAIMarkdownTextUXPrimitive) with hyperlink, citation, and LaTeX image support.

Parameter

ParameterTypeDefaultDescription
textrequiredstring—Markdown text.
options.hyperlinkbooleantrueParse [label](url).
options.citationbooleantrueParse [](url).
options.latexbooleantrueParse LaTeX images.
options.idstring—Unique node ID.
options.replacestring | [string, number]—Replace a target node.
options.insertAtstring | [string, number]—Insert after a target node.
Returnthis
example
rich.addText('Hello! This is a **rich response** example.', { id: 'greeting' });

addFOAText

chainable
.addFOAText(text, options)

FOA text variant (FOATextPrimitive) without inline entity parsing.

Parameter

ParameterTypeDefaultDescription
textrequiredstring—Literal text.
optionsobject—id, replace, insertAt.
Returnthis

addCode

chainable
.addCode(language, code, options)

Adds a code block using AIRich.tokenizer() for syntax highlighting.

Parameter

ParameterTypeDefaultDescription
languagerequiredstring—javascript, typescript, python, java, golang, c, cpp, php, rust, html, bash, css, markdown.
coderequiredstring—Source code.
optionsobject—id, replace, insertAt.
Returnthis
example
rich.addCode('javascript', 'const x = 42;\nconsole.log(x);', { id: 'code-1' });

addTable

chainable
.addTable(table, options)

Adds a table. The first row is the header; rows of different lengths are padded automatically.

Parameter

ParameterTypeDefaultDescription
tablerequiredArray<Array<string>>—Table rows; the first row is the header.
options.hyperlinkbooleantrueParse hyperlinks inside cells.
options.citationbooleantrueParse citations inside cells.
options.latexbooleantrueParse LaTeX images inside cells.
optionsobject—id, replace, insertAt.
Returnthis

addSource

chainable
.addSource(sources, options)

Adds a list of sources or references (GenAISearchResultPrimitive).

Parameter

ParameterTypeDefaultDescription
sourcesrequiredArray<string> | Array<Array<string>> | Array<object>—An array of strings is treated as one source [icon, url, title, subtitle]; an array of arrays is multiple sources; objects use { icon|favicon, url, title, subtitle }.
optionsobject—id, replace, insertAt.
Returnthis

addReels

chainable
.addReels(reelsItems, options)

Adds horizontally scrolling Reels cards.

Parameter

ParameterTypeDefaultDescription
reelsItemsrequiredobject | Array<object>—Fields: videoUrl/url, profileIconUrl/profile, thumbnailUrl/thumbnail, username/title, likes_count, shares_count, view_count, reel_source, is_verified.
optionsobject—id, replace, insertAt.
Returnthis

addImage

chainable
.addImage(imageUrl, options)

Adds one or more images (imagine_type IMAGINE). An array produces multiple sliding card sections.

Parameter

ParameterTypeDefaultDescription
imageUrlrequiredstring | Buffer | Array—URL, buffer, base64, or array.
options.widthnumber—Display width.
options.heightnumber—Display height.
options.statusEnums.IMAGINE_STATUS3 (READY)Image render status.
options.update_textstring—Status text, usually for GENERATING.
options.resolveUrlbooleanfalseForce reupload of the URL to WhatsApp servers.
optionsobject—id, replace, insertAt.
Returnthis
  • Do not pass an id when the array contains more than one image.

addVideo

chainable
.addVideo(videoUrl, options)

Adds a video (imagine_type ANIMATE). With autoFill enabled, size, duration, and thumbnail are computed automatically.

Parameter

ParameterTypeDefaultDescription
videoUrlrequiredstring | Buffer | object | Array—URL, buffer, array, or object { url, mime_type, file_length, duration, thumbnail }.
options.autoFillbooleantrueCompute file_length, duration, and thumbnail from the buffer.
options.statusEnums.IMAGINE_STATUS3 (READY)Video render status.
options.estimatedTimenumber—Estimated completion time in milliseconds for GENERATING.
optionsobject—id, replace, insertAt.
Returnthis

addProduct

chainable
.addProduct(data, options)

Adds product cards. A single object uses the Single layout; an array uses HScroll.

Parameter

ParameterTypeDefaultDescription
datarequiredobject | Array<object>—Fields: title, brand, price, sale_price, product_url/url, image_url/image, icon_url/icon.
optionsobject—id, replace, insertAt.
Returnthis

addPost

chainable
.addPost(data, options)

Adds social media post cards using the HScroll layout.

Parameter

ParameterTypeDefaultDescription
datarequiredobject | Array<object>—Fields: title, subtitle, username, profile_picture_url, is_verified, thumbnail_url, post_caption, likes_count, comments_count, shares_count, post_url, post_deeplink, source_app, footer_label, footer_icon, orientation, post_type.
optionsobject—id, replace, insertAt.
Returnthis

addMetadata

chainable
.addMetadata(text, options)

Adds small metadata text (GenAIMetadataTextPrimitive).

Parameter

ParameterTypeDefaultDescription
textrequiredstring—Metadata text.
optionsobject—id, replace, insertAt.
Returnthis

addTip

chainable
.addTip(text, options)

Like addMetadata, but automatically prefixed with the ⓘ symbol.

Parameter

ParameterTypeDefaultDescription
textrequiredstring—Tip text.
optionsobject—id, replace, insertAt.
Returnthis

addWidget

chainable
.addWidget(data, options)

Adds a third-party extension widget (GenAI3PExtWidgetPrimitive).

Parameter

ParameterTypeDefaultDescription
datarequiredobject | Array<object>—Fields: title, header, sections, actions [{ label, state, kind, tool_call_id, toast }], body.
options.layoutstringHScroll / SingleCard layout.
optionsobject—id, replace, insertAt, plus extra fields for newLayout().
Returnthis

addFooterAction

chainable
.addFooterAction(data, options)

Adds footer action buttons (GenAIFooterActionPrimitive).

Parameter

ParameterTypeDefaultDescription
datarequiredobject | Array<object>—Fields: text/cta_text, type/cta_type, url/cta_url.
options.layoutstringHScroll / SingleButton layout.
optionsobject—id, replace, insertAt.
Returnthis

addSuggest

chainable
.addSuggest(suggestion, options)

Adds follow-up prompt suggestion pills.

Parameter

ParameterTypeDefaultDescription
suggestionrequiredstring | Array<string>—One or more suggestions.
options.scrollbooleantrueArrays use HScroll when true and ActionRow when false.
options.layoutstring—Override the layout: Single, HScroll, ActionRow.
optionsobject—id, replace, insertAt.
Returnthis
example
rich.addSuggest(['Summarize this article', 'Translate it to English']);

build

async
.build(jid, options)

Assembles the complete botForwardedMessage.message.richResponseMessage, including the base64 unifiedResponse and fallback submessages.

Parameter

ParameterTypeDefaultDescription
jidrequiredstring—Destination JID.
options.forwardedbooleantrueMark the message as forwarded from a bot.
options.notificationbooleanfalseInclude sessionTransparencyMetadata.
options.includesUnifiedResponsebooleantrueInclude the base64 rich payload.
options.includesSubmessagesbooleantrueInclude fallback submessages.
options.quotedWAMessage—Message to quote.
options.quotedParticipantstring—Override the quoted participant in groups.
options.messageIdstring—Custom message ID.
ReturnPromise<WAMessage>
  • A footer set via setFooter is automatically appended as the final metadata section.

buildEdit

async
.buildEdit(targetJid, targetId, options)

Wraps an edit payload (protocolMessage type 14) to replace the content of an already delivered message.

Parameter

ParameterTypeDefaultDescription
targetJidrequiredstring—Target message JID.
targetIdrequiredstring—Target message ID.
options.msgobject—A previously built message; build() is called again when omitted.
ReturnPromise<WAMessage>

sendEdit

async
.sendEdit(jid, id, options)

Builds and sends an edit payload. jid and id default to the last message sent.

Parameter

ParameterTypeDefaultDescription
jidstring—Defaults to this._lastMessageKey.remoteJid.
idstring—Defaults to this._lastMessageKey.id.
options.msgobject—Message payload to use as the edit content.
ReturnPromise<WAMessage>
  • Throws an Error when jid or id is unavailable.

send

async
.send(jid, options)

Builds and sends the rich response. When includesUnifiedResponse and bypassDownload are enabled, it automatically calls sendEdit so the base64 payload syncs on the client immediately.

Parameter

ParameterTypeDefaultDescription
jidrequiredstring—Destination JID.
options.bypassDownloadbooleantrueSend a sync edit after the main message.
options.forwardedbooleantrueMark as forwarded.
options.includesUnifiedResponsebooleantrueInclude the rich payload.
options.additionalNodesArray[]Additional XMPP nodes.
ReturnPromise<WAMessage>
example
await new AIRich(sock)
  .setTitle('Assistant')
  .addText('Here is a summary of the article.')
  .addCode('javascript', 'const total = items.length;')
  .addSuggest(['Explain in more detail', 'Make it shorter'])
  .send(jid);

Static utilities

tokenizer

static
AIRich.tokenizer(code, lang)

Built-in syntax highlighting tokenizer for 13 languages. Produces DEFAULT, KEYWORD, METHOD, STR, NUMBER, and COMMENT tokens.

Parameter

ParameterTypeDefaultDescription
coderequiredstring—Source code.
langstring'javascript'Target language.
Return{ codeBlock: object[], unified_codeBlock: object[] }

toTableMetadata

static
AIRich.toTableMetadata(arr, options)

Normalizes a table: pads rows, marks the header, and extracts inline entities from every cell.

Parameter

ParameterTypeDefaultDescription
arrrequiredArray<Array<string>>—Table rows.
optionsobject—hyperlink, citation, latex (all default to true).
Return{ title, rows, unified_rows }

generateVerificationMetadata

static
AIRich.generateVerificationMetadata()

Generates verificationMetadata with a random signature and certificate chain so the payload is accepted by clients.

Returnobject

newLayout

static
AIRich.newLayout(name, data, extra)

Generic view_model helper that wraps primitives into a section.

Parameter

ParameterTypeDefaultDescription
namerequiredstring—Layout name, such as Single, HScroll, or ActionRow.
datarequiredobject | Array<object>—A primitive or list of primitives.
extraobject{}Merged into the root result.
Returnobject

Notes

Dual payload

Rich responses carry two representations: base64 sections in unifiedResponse for modern clients, and submessages as a fallback. Both can be disabled through build options when debugging.

Use IDs for updates

Assign an id to blocks that may change. When streaming, call addText with replace: "id" and then sendEdit to update content without sending a new message.

Not an official API

The richResponseMessage structure comes from reverse engineering and may change at any time. Test on your target devices before shipping to production.

Node management

For replace, insertAt, delete, peek, and assignId, see thenode management page.