brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
whatsapp-bot-builderBuilds WhatsApp bots and integrations using the WhatsApp Business API (Cloud API). Use when the user wants to create a WhatsApp bot, send template messages, handle incoming messages, build interactive lists and buttons, process media, or automate customer communication via WhatsApp. Trigger words: whatsapp bot, whatsapp business api, whatsapp integration, w…
Independent GitHub snapshot · Automated classification · Original documentation governs
Builds WhatsApp bots using the official Cloud API (hosted by Meta). Covers account setup, webhook configuration, sending and receiving messages, template messages for outbound campaigns, interactive components (buttons, lists, flows), media handling, and production deployment. Does NOT use unofficial libraries — only the official WhatsApp Business Platform.
Required credentials:
WHATSAPP_TOKEN=EAAxxxxxxx # Permanent System User token
WHATSAPP_PHONE_ID=123456789 # Phone Number ID
WHATSAPP_BUSINESS_ID=987654321 # Business Account ID
WHATSAPP_VERIFY_TOKEN=my_secret # Webhook verification token (you choose this)
WhatsApp sends incoming messages via webhooks:
const express = require('express');
const app = express();
app.use(express.json());
// Webhook verification (GET)
app.get('/webhook', (req, res) => {
const mode = req.query['hub.mode'];
const token = req.query['hub.verify_token'];
const challenge = req.query['hub.challenge'];
if (mode === 'subscribe' && token === process.env.WHATSAPP_VERIFY_TOKEN) {
res.status(200).send(challenge);
} else {
res.sendStatus(403);
}
});
// Incoming messages (POST)
app.post('/webhook', (req, res) => {
const entry = req.body.entry?.[0];
const change = entry?.changes?.[0];
const message = change?.value?.messages?.[0];
if (message) {
handleMessage(message, change.value.metadata.phone_number_id);
}
res.sendStatus(200); // Always respond 200 quickly
});
Register webhook URL in Meta Developer Console → WhatsApp → Configuration.
Subscribe to: messages, message_status, message_template_status_update.
Text message:
async function sendText(to, text) {
await fetch(`https://graph.facebook.com/v21.0/${PHONE_ID}/messages`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${TOKEN}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
messaging_product: 'whatsapp',
to: to, // Phone number with country code: '14155552671'
type: 'text',
text: { body: text }
})
});
}
Interactive buttons (max 3):
{
messaging_product: 'whatsapp',
to: to,
type: 'interactive',
interactive: {
type: 'button',
body: { text: 'How can I help you?' },
action: {
buttons: [
{ type: 'reply', reply: { id: 'support', title: '🛠 Support' } },
{ type: 'reply', reply: { id: 'sales', title: '💰 Sales' } },
{ type: 'reply', reply: { id: 'info', title: 'ℹ️ Info' } }
]
}
}
}
Interactive list (up to 10 items per section, 10 sections):
{
type: 'interactive',
interactive: {
type: 'list',
body: { text: 'Choose a product category:' },
action: {
button: 'View Categories',
sections: [{
title: 'Electronics',
rows: [
{ id: 'phones', title: 'Phones', description: 'Latest smartphones' },
{ id: 'laptops', title: 'Laptops', description: 'Work and gaming' }
]
}]
}
}
}
Template messages are required for initiating conversations (outbound). They must be pre-approved by Meta.
Creating templates:
{{1}}, {{2}}, etc.Sending a template:
{
messaging_product: 'whatsapp',
to: to,
type: 'template',
template: {
name: 'order_confirmation',
language: { code: 'en_US' },
components: [{
type: 'body',
parameters: [
{ type: 'text', text: 'ORD-12345' },
{ type: 'text', text: '$49.99' }
]
}]
}
}
Send image:
{
messaging_product: 'whatsapp',
to: to,
type: 'image',
image: {
link: 'https://example.com/photo.jpg', // Public URL
caption: 'Your order receipt'
}
}
Receive media: Extract messages[0].image.id, then:
// Get media URL
const media = await fetch(`https://graph.facebook.com/v21.0/${mediaId}`, {
headers: { 'Authorization': `Bearer ${TOKEN}` }
}).then(r => r.json());
// Download the file
const file = await fetch(media.url, {
headers: { 'Authorization': `Bearer ${TOKEN}` }
});
Supported: images (5MB), video (16MB), audio (16MB), documents (100MB), stickers.
WhatsApp charges per 24-hour conversation window:
The 24h window opens when you first reply or send a template. All messages within that window are one conversation.
Input: "Build a WhatsApp bot for our e-commerce store. Customers can check order status, request returns, and talk to a human agent."
Output: A Node.js webhook server with:
Input: "Create a WhatsApp bot for a dental clinic. Patients book appointments, get reminders, and can reschedule."
Output: A Node.js app with:
wa_id (WhatsApp ID) not phone number for user identificationsent, delivered, read, failed) for tracking