← Back to Blog
AI Chatbot

WhatsApp Business API Chatbot with GPT-4 and LangChain

Share

WhatsApp has 2.7 billion active users. A GPT-4 chatbot on WhatsApp Business API can handle customer support, lead qualification, appointment booking, and order tracking — 24/7, in any language. This is our production guide to building one, from Meta verification to multi-turn memory and CRM handoff.

Step 1: Meta Business Verification

The first and most frustrating step. To access the WhatsApp Business API, your business must pass Meta's verification process. This requires a valid business address, government-registered business name matching your Facebook Business Manager, and (for higher message limits) a business website with clear contact information.

  1. Create a Meta Business Manager account at business.facebook.com
  2. Add your business details and complete Business Verification (upload government ID)
  3. Create a WhatsApp Business Account (WABA) within Business Manager
  4. Register your phone number — it cannot be currently active on regular WhatsApp
  5. Submit for phone number display name approval (usually 1–2 business days)
⚠️

Your phone number cannot be migrated back to regular WhatsApp once registered with the API. Use a dedicated number. We recommend buying a VoIP DID from Twilio or Telnyx for this purpose.

Step 2: Webhook Setup with Node.js

WhatsApp sends incoming messages to your webhook URL via HTTP POST. Your server must respond with 200 OK within 5 seconds, or the delivery is marked as failed. For GPT-4 calls that take longer, acknowledge immediately and process asynchronously.

app.post('/webhook', async (req, res) => { res.sendStatus(200); // Acknowledge immediately const { entry } = req.body; const message = entry[0]?.changes[0]?.value?.messages?.[0]; if (!message || message.type !== 'text') return; const userId = message.from; const userText = message.text.body; // Load conversation history from Redis const history = await redis.get(`chat:${userId}`) || []; // Get GPT-4 response const response = await chain.invoke({ input: userText, history: history, }); // Send WhatsApp reply await sendWhatsAppMessage(userId, response.output); // Save updated history to Redis await redis.set(`chat:${userId}`, JSON.stringify(history), 'EX', 86400); });

Step 3: LangChain for Memory and RAG

Raw GPT-4 is stateless — it has no memory of previous messages. LangChain's ConversationBufferWindowMemory solves this by maintaining the last N turns of conversation. For knowledge-base queries (product FAQs, policy documents), add a Pinecone vector store and use ConversationalRetrievalChain to combine memory with RAG retrieval.

Step 4: Template Messages for Proactive Outreach

To send the first message to a user (outbound), you must use pre-approved Message Templates. Templates are submitted to Meta for approval and typically take 24–48 hours. Once approved, you can send templated messages for appointment reminders, order confirmations, and payment alerts. Free-form responses are only allowed within a 24-hour session window after the user messages you first.

Step 5: Human Handoff

Every production chatbot needs a human escalation path. We implement a keyword-based trigger ("speak to human", "agent", "help") that pauses the AI and routes the conversation to a live agent via Intercom, Zendesk, or a custom agent desk. The full conversation history is passed to the agent so they have full context.

A WhatsApp GPT-4 chatbot built properly — with verified business account, async webhook handling, LangChain memory, and clean human handoff — can deflect 60–80% of tier-1 support volume. Our team has built 30+ WhatsApp AI chatbots and can guide you through the full process including Meta verification.

Share
Let's Talk

Need Help With Your Project?

The same engineers who wrote this article will work on your project. Free consultation.