Skip to content

WhatsApp (Meta Cloud API)

This guide summarizes official Meta steps and shows how to relay messages to GeniStudio.

  • Meta Developer account and a Facebook app
  • A WhatsApp Business Account (WABA)
  • A phone number connected to your WABA

References: Meta docs — WhatsApp Cloud API Get Started and Webhooks.

  1. User messages your WhatsApp number.
  2. Meta sends a webhook event to your server.
  3. Your server forwards text to GeniStudio POST /api/v1/message.
  4. You send the AI response back via Meta Send API.
  • Create an app (Business type) and add WhatsApp product.
  • Get a temporary access token (later use a permanent token via system user).
  • Add a phone number in WhatsApp > API Setup.
  • Configure Webhook: subscribe to messages for your app.
import express from 'express';
import fetch from 'node-fetch';
const app = express();
app.use(express.json());
// Meta verification
app.get('/webhook', (req, res) => {
const verify_token = process.env.META_VERIFY_TOKEN;
const mode = req.query['hub.mode'];
const token = req.query['hub.verify_token'];
const challenge = req.query['hub.challenge'];
if (mode === 'subscribe' && token === verify_token) return res.status(200).send(challenge);
return res.sendStatus(403);
});
// Receive messages
app.post('/webhook', async (req, res) => {
const entry = req.body.entry?.[0];
const change = entry?.changes?.[0];
const msg = change?.value?.messages?.[0];
const from = msg?.from; // user phone
const text = msg?.text?.body;
if (text) {
const r = await fetch('https://message.geneline-x.net/api/v1/message', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': process.env.GENISTUDIO_API_KEY!,
},
body: JSON.stringify({
chatbotId: process.env.GENISTUDIO_CHATBOT_ID!,
email: `${from}@wa`,
message: text,
}),
});
const aiText = await r.text();
// Send back via WhatsApp Messages API
await fetch(`https://graph.facebook.com/v20.0/${process.env.WHATSAPP_PHONE_NUMBER_ID}/messages`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.META_TOKEN}`,
},
body: JSON.stringify({
messaging_product: 'whatsapp',
to: from,
type: 'text',
text: { body: aiText.slice(0, 4000) },
}),
});
}
res.sendStatus(200);
});
app.listen(3000);
  • Persist the conversation state using email derived from channel id.
  • Rotate tokens and secure your webhook.
  • For verified access and phone numbers, use Business Manager + Cloud API production steps.