Skip to main content

WhatsApp

Send WhatsApp messages through Twilio or the WhatsApp Business API.

Providers

ProviderConfiguration KeyDescription
twilioAccount SID, Auth TokenTwilio WhatsApp API
whatsapp-businessAPI TokenMeta WhatsApp Business API

Configuration

Twilio

messaging({
whatsapp: {
provider: "twilio",
accountSid: process.env.TWILIO_SID,
authToken: process.env.TWILIO_TOKEN,
from: "whatsapp:+14155238886", // Twilio sandbox or your number
},
});

WhatsApp Business API

messaging({
whatsapp: {
provider: "whatsapp-business",
apiToken: process.env.WHATSAPP_API_TOKEN,
phoneNumberId: process.env.WHATSAPP_PHONE_ID,
},
});

Sending Messages

Text Message

await app.messaging.whatsapp.send({
to: "+1234567890",
body: "Your order has been shipped! Track it here: https://track.example.com/abc123",
});

Template Message (WhatsApp Business API)

WhatsApp Business API requires pre-approved templates for initiating conversations:

await app.messaging.whatsapp.sendTemplate({
to: "+1234567890",
template: "order_confirmation",
language: "en",
components: [
{
type: "body",
parameters: [
{ type: "text", text: "Alice" },
{ type: "text", text: "#1234" },
],
},
],
});

Media Message

await app.messaging.whatsapp.send({
to: "+1234567890",
body: "Here is your receipt:",
media: {
url: "https://example.com/receipt.pdf",
type: "document",
filename: "receipt.pdf",
},
});

API Reference

whatsapp.send(options): Promise<MessageResult>

OptionTypeRequiredDescription
tostringYesRecipient phone (E.164 format)
bodystringYesMessage text
fromstringNoOverride sender
mediaMediaObjectNoAttach media

whatsapp.sendTemplate(options): Promise<MessageResult>

OptionTypeRequiredDescription
tostringYesRecipient phone (E.164 format)
templatestringYesTemplate name
languagestringYesTemplate language code
componentsComponent[]NoTemplate variables

REST API

curl -X POST http://localhost:3000/messaging/whatsapp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer eyJhbGci..." \
-d '{
"to": "+1234567890",
"body": "Your order has been shipped!"
}'

Response (200):

{
"messageId": "wamid.abc123",
"status": "sent",
"channel": "whatsapp",
"to": "+1234567890"
}

Webhook for Incoming Messages

FluxKit can receive incoming WhatsApp messages via webhooks:

app.messaging.whatsapp.onMessage(async (message) => {
console.log(`From: ${message.from}`);
console.log(`Body: ${message.body}`);

// Auto-reply
await app.messaging.whatsapp.send({
to: message.from,
body: "Thanks for your message! We'll get back to you soon.",
});
});

The webhook endpoint is available at POST /messaging/whatsapp/webhook.