If you’ve ever tried to build a WhatsApp integration or an AI customer support bot using the official Meta Cloud API, you probably know the pain:
- Submitting business registration documents and utility bills.
- Waiting days or weeks for Facebook Business Manager verification.
- Having to pre-submit and pay for every single template message.
- Dealing with the strict 24-hour customer service window.
For indie hackers, developers, and early-stage startups who just want to connect a phone number, listen for incoming messages, and reply with AI or an automated notification, that setup is complete overkill.
In this guide, we will build a working WhatsApp message sender and an auto-reply AI webhook in Node.js in under 5 minutes using Wapio (a developer-first WhatsApp API that connects via QR in seconds with zero Meta bureaucracy).
Prerequisites
- Node.js 18+ installed
- A WhatsApp number you want to connect
- A free account on Wapio.io
Step 1: Connect Your Number via QR in 15 Seconds
- Head over to wapio.io and create a free account.
- In the dashboard, click Create Session.
- Scan the generated QR code using WhatsApp on your phone (Linked Devices -> Link a Device).
Your session is now connected! You will see your API Key and your Session ID in the dashboard.
Step 2: Send a WhatsApp Message with 10 Lines of Code
You don’t need heavyweight SDKs. Wapio exposes clean REST endpoints. Here is how to send a WhatsApp text message using native fetch:
// send-message.js
const API_KEY = "YOUR_WAPIO_API_KEY";
const SESSION_ID = "YOUR_SESSION_ID";
async function sendWhatsAppMessage(to, message) {
const response = await fetch("https://api.wapio.io/api/send-message", {
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
"Content-Type": "application/json",
"x-session-id": SESSION_ID
},
body: JSON.stringify({
to: to, // Phone number with country code, e.g. "+1234567890"
text: message
})
});
const data = await response.json();
console.log("Message sent:", data);
}
// Test send
sendWhatsAppMessage("+1234567890", "Hello from Node.js! 🚀");
Run it:
node send-message.js
Boom. Your message lands directly in the recipient’s WhatsApp chat with zero template restrictions.
Step 3: Handle Incoming Messages (Webhooks)
To make a two-way bot, you need to listen for incoming messages.
When someone texts your connected number, Wapio fires an instant HTTP POST webhook to your server.
Here is a minimal Express server to receive messages:
// webhook-server.js
import express from "express";
const app = express();
app.use(express.json());
app.post("/webhook", (req, res) => {
const { event, data } = req.body;
// Listen for new incoming messages
if (event === "messages.upsert") {
const message = data.messages?.[0];
const sender = message?.key?.remoteJid;
const text = message?.message?.conversation || message?.message?.extendedTextMessage?.text;
// Ignore messages sent by yourself
if (!message?.key?.fromMe && text) {
console.log(`📩 Received message from ${sender}: ${text}`);
// Handle the message (e.g. call an LLM or auto-reply)
}
}
// Always return 200 OK immediately
res.sendStatus(200);
});
app.listen(3000, () => console.log("Webhook server running on port 3000"));
To test locally, expose port 3000 using ngrok:
ngrok http 3000
Then paste your https://your-ngrok-url/webhook URL into the Webhooks tab inside your Wapio dashboard.
Step 4: Turn It Into an AI WhatsApp Bot
Now, let’s connect an LLM (like OpenAI GPT-4o, Claude, or Groq) so your WhatsApp number acts as an autonomous 24/7 assistant.
import express from "express";
import OpenAI from "openai";
const app = express();
app.use(express.json());
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const WAPIO_API_KEY = process.env.WAPIO_API_KEY;
const SESSION_ID = process.env.WAPIO_SESSION_ID;
async function replyWhatsApp(to, replyText) {
await fetch("https://api.wapio.io/api/send-message", {
method: "POST",
headers: {
"Authorization": `Bearer ${WAPIO_API_KEY}`,
"Content-Type": "application/json",
"x-session-id": SESSION_ID
},
body: JSON.stringify({ to, text: replyText })
});
}
app.post("/webhook", async (req, res) => {
res.sendStatus(200); // Acknowledge fast
const message = req.body.data?.messages?.[0];
const isFromMe = message?.key?.fromMe;
const userText = message?.message?.conversation || message?.message?.extendedTextMessage?.text;
const senderPhone = message?.key?.remoteJid;
if (!isFromMe && userText && senderPhone) {
// 1. Ask the AI for a response
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: "system", content: "You are a friendly customer support AI on WhatsApp. Keep answers concise." },
{ role: "user", content: userText }
]
});
const aiReply = completion.choices[0].message.content;
// 2. Send the AI reply back over WhatsApp
await replyWhatsApp(senderPhone, aiReply);
}
});
app.listen(3000, () => console.log("AI WhatsApp Bot ready!"));
Best Practices & Safety Tips
If you’re building with WhatsApp, keep these two rules in mind:
- Inbound Support & Customer Communication (100% Safe): When customers message you first (for support, booking, order tracking, or AI chat), you can reply freely without fear of bans.
- Cold Outbound Outreach: If you’re doing outbound messages to new leads, warm up your phone number first, send in small batches, add randomized delays (10–30s between messages), and never blast thousands of spam messages.
Conclusion
You don’t need weeks of Meta verification or painful enterprise contracts to build customer support bots, appointment reminders, or CRM notifications on WhatsApp.
- Explore Wapio: wapio.io
- API Docs: wapio.io/docs
Are you currently building any automations on WhatsApp? Drop your questions or use cases in the comments below! 👇
Top comments (0)