Buttons and lists in WhatsApp AI agents
How to combine an AI agent with WhatsApp buttons and lists: when to use them, limits, how the customer’s choice arrives and confirming actions safely.
Free text gives the agent flexibility, but it also gives the customer a lot of room to err, be ambiguous and write what the model does not understand. Buttons and lists close the conversation into known options. Combining both, letting the agent chat and using buttons at decision points, makes the flow more reliable and cheaper.
When should you use buttons and lists instead of free text?
When the question has a few known possible answers: confirm or decline, choose among a few times, choose a topic. In those cases, a tap replaces typing, removes ambiguity and avoids a model call to interpret the answer.
- Confirmations: yes or no before an action, especially irreversible ones.
- Choosing among few options: time, type of service, contact method.
- Opening menu: three or four topics the agent can handle, plus an option to talk to a person.
- Way out to a person: a fixed talk-to-the-team button, which meets Meta’s requirement for a clear escalation path.
For open questions, such as describe the problem, free text remains right. The rule is to use buttons where there is a closed list, and not to force a menu where the customer wants to explain.
Remember too that the customer does not always tap. They may ignore the buttons and write a text answer, such as tomorrow is fine, or come back to an old menu days later. The agent must handle both paths: if text arrives where a button was expected, let the model interpret the message in the context of the pending question, and only then decide whether the choice is clear. A flow that only works with taps breaks on the first customer who types.
What are the limits of buttons and lists?
Quick-reply buttons accept up to 3 buttons, with a title of up to 20 characters. Lists open a menu with up to 10 rows in total. These limits come from Meta and Hub validates them before sending, returning 400 INVALID_MESSAGE if any is exceeded.
| Element | Limit | Note |
|---|---|---|
| Reply buttons | At most 3 | Labels unique among themselves |
| Button title | Up to 20 characters | More than that is rejected, not truncated, in Hub |
| Body text | Up to 1024 characters (Meta) | Required |
| Footer | Up to 60 characters (Meta) | Optional |
| Button id | Up to 256 characters (Meta) | Unique in the message |
| List | 10 rows in total, row title up to 24, description up to 72 | Row id unique across the whole message |
The button figures come from Meta’s reply buttons documentation and from the Hub guide, which validates the payload before sending. If an example diverges from Meta’s reference, Meta’s reference wins. Interactive messages are free-form content, so the same 24-hour window rule as text applies: outside it, only templates.
How does the agent decide to show buttons?
Through a tool. Instead of generating WhatsApp JSON, the model calls enviar_opcoes with the question and the options, and your code builds the payload and applies the limits. That keeps the format out of the model’s reach for mistakes.
// The agent asks for buttons; YOUR code builds and validates the payload
const enviarOpcoes = {
name: 'enviar_opcoes',
description: 'Shows the customer 2 to 3 buttons for a closed question (confirm, ' +
'choose among few options). Use instead of asking in text when the possible ' +
'answers are few and known.',
strict: true,
input_schema: {
type: 'object',
properties: {
pergunta: { type: 'string', description: 'Message text, up to 1024 characters' },
opcoes: {
type: 'array', minItems: 2, maxItems: 3,
items: {
type: 'object',
properties: {
id: { type: 'string', description: 'Stable identifier, e.g. confirm_2pm' },
titulo: { type: 'string', description: 'Label, up to 20 characters' },
},
required: ['id', 'titulo'], additionalProperties: false,
},
},
},
required: ['pergunta', 'opcoes'], additionalProperties: false,
},
}
function montarPayload(para, { pergunta, opcoes }) {
return {
to: para,
type: 'interactive',
interactive: {
type: 'button',
body: { text: pergunta.slice(0, 1024) },
action: { buttons: opcoes.map((o) => ({ type: 'reply', reply: { id: o.id, title: o.titulo.slice(0, 20) } })) },
},
}
}The division of roles is the point. The model decides that a closed question fits here and picks the options. The code guarantees what the platform requires: maximum buttons, label length, stable ids. The ids are the contract with your system, defined by you or validated against an allowed list, and not free text from the model.
Sending follows the usual rule: the send call with an Idempotency-Key derived from the incoming message. Remember the 202 response means accepted and queued. A later Meta refusal, such as a long title or repeated id, arrives afterwards as a failed message.status. The quickstart covers the send call.
How does the customer’s choice reach the agent?
As an ordinary message, in the message.received event, with type interactive and a null text field. There is no tap callback. The choice is in data.content.interactive, and the value your code should compare is the id, never the title.
// On receive: the choice is in content.interactive, and the text comes null
function lerEntrada(evento) {
const c = evento.data.content
if (c?.type === 'interactive' && c.interactive?.type === 'button_reply') {
return { tipo: 'botao', id: c.interactive.button_reply.id } // compare the ID, not the title
}
if (c?.type === 'interactive' && c.interactive?.type === 'list_reply') {
return { tipo: 'lista', id: c.interactive.list_reply.id }
}
if (c?.type === 'button') { // TEMPLATE button arrives here
return { tipo: 'botao-template', dados: c.button }
}
return { tipo: 'texto', texto: evento.data.text }
}
// Known ids become a direct action, without spending a model call
const ACOES = {
confirm_2pm: (ctx) => confirmSlot(ctx, '14:00'),
reschedule: (ctx) => askNewSlot(ctx),
talk_to_person: (ctx) => handoff(ctx, 'asked via button'),
}- Null text: the most common bug is a handler that reads only the text and discards the reply as if it were empty.
- Id, not title: the title is interface label and changes; the id is the contract.
- Template button: a reply to a template QUICK_REPLY button arrives with type button and the data in data.content.button, not in content.interactive. Handle both.
- Direct actions: a known id can run the action without going through the model, which cuts cost and variation.
The webhooks reference describes the event envelope; see webhooks.
How do you use buttons to confirm actions safely?
By making confirmation a step recorded by your code, in a separate turn, and not an interpretation by the model. For actions that cannot be undone, such as cancelling an order, the action tool returns a confirmation request, the agent shows the buttons and the action only happens when the confirmation id comes back.
- The confirm button carries the action and target in its id, such as cancel_1234, and your code checks that action was actually pending for that contact.
- Confirmations expire: ignore a tap on an old button whose action is no longer pending.
- Always offer the way out: a second no button, and an option to talk to a person.
- Record the confirmation with date and message id, which serves as evidence.
This complements the defense against prompt injection: a customer, or planted text, can convince the model to request the cancellation, but only the button tap, validated by the code, executes it.
Frequently asked questions
How many buttons can I send?
At most 3 quick-reply buttons, with a title of up to 20 characters each. For more options, use a list, which in Hub accepts up to 10 rows across all sections.
Why does my button reply arrive with null text?
Because the choice comes in data.content.interactive, not data.text. A text handler does not see it. Read the id in content.interactive.
Can I send buttons outside the 24-hour window?
Not as a free message. Outside the window, only an approved template, which can have its own quick-reply buttons.
Should the model generate the buttons JSON?
Prefer that it calls a tool with the question and options, and that your code builds and validates the payload with the platform’s limits.
Fontes
Documentação oficial da Meta, conferida em 31 de outubro de 2026.