Send WhatsApp interactive reply buttons and list messages in Node.js
Interactive messages let a user answer with a tap. They are service messages, so you can send them while the customer service window is open.
Reply buttons
Section titled “Reply buttons”Meta’s reply buttons page documents these limits:
| Field | Limit |
|---|---|
| Buttons | up to 3 |
Button label (title) |
20 characters, unique across the buttons |
Button id |
256 characters |
| Body | 1024 characters |
| Footer | 60 characters |
| Header | optional: text, image, video or document |
await client.messages.sendInteractiveButtons('15551234567', { header: 'Workshop details', // optional, text up to 60 characters body: 'Your gardening workshop is tomorrow at 9am. Need to reschedule?', footer: 'Lucky Shrub', // optional buttons: [ { id: 'change-button', title: 'Change' }, { id: 'cancel-button', title: 'Cancel' }, ],});The SDK checks these limits before it sends anything. A fourth button, an empty or duplicate id, a title over 20 characters or an over-long body or footer throws WhatsAppValidationError with no network call:
try { await client.messages.sendInteractiveButtons('15551234567', { body: 'Pick one', buttons: [ { id: 'a', title: 'A' }, { id: 'b', title: 'B' }, { id: 'c', title: 'C' }, { id: 'd', title: 'D' }, // a fourth button ], });} catch (error) { if (error instanceof WhatsAppValidationError) { // Thrown before any request is made. console.error(error.message); }}List messages
Section titled “List messages”Meta’s list messages page documents these limits:
| Field | Limit |
|---|---|
| Sections | up to 10 |
| Rows | up to 10 in total across all sections, at least 1 |
| Button label | 20 characters |
Row title |
24 characters |
Row description |
72 characters |
Row id |
200 characters |
Section title |
required by Meta, 24 characters |
| Header | text only, 60 characters |
| Footer | 60 characters |
| Body | 4096 characters |
await client.messages.sendInteractiveList('15551234567', { header: 'Choose shipping option', body: 'Which shipping option do you prefer?', footer: 'Lucky Shrub', button: 'Shipping options', // label of the button that opens the list sections: [ { title: 'I want it ASAP', rows: [ { id: 'priority_express', title: 'Priority Mail Express', description: 'Next day to 2 days', }, { id: 'priority_mail', title: 'Priority Mail', description: '1 to 3 days' }, ], }, { title: 'I can wait a bit', rows: [{ id: 'media_mail', title: 'Media Mail', description: '2 to 8 days' }], }, ],});The SDK checks the section count, the total row count, the button label, row titles and row descriptions. Two differences from Meta’s table are worth knowing:
- The SDK applies a 1024-character limit to the body of every interactive message, including lists, which is stricter than the 4096 that Meta lists for lists. For a longer list body, use
client.messages.sendRaw(see Raw sends). - The SDK does not check row
idlength or section titles, and the API remains the authority on both.
Read the user’s choice
Section titled “Read the user’s choice”When a user taps a button or picks a row, Meta sends a messages webhook with interactive.button_reply or interactive.list_reply. It contains the id you set, which is the value to branch on.
// The tap arrives as an inbound webhook message of type "interactive".declare const message: import('@solvejet/whatsapp-cloud-api').IncomingMessage;
if (message.type === 'interactive') { const { button_reply: button, list_reply: row } = message.interactive; if (button) console.log('Button tapped:', button.id, button.title); if (row) console.log('List row chosen:', row.id, row.title);}See Handling events for flattening a webhook delivery into messages, and Messaging for the other message types.
Independent open-source project. Not affiliated with, endorsed by or sponsored by Meta or WhatsApp. Released under the MIT licence. Source on GitHub.