Most "WhatsApp bots" are decision trees. Press 1 for menu, press 2 for timings. The moment a customer types something real, like "can I get 2 kg paneer at 6?", they break.
In this tutorial we'll build an AI agent instead: a small Node.js service that reads a free-text WhatsApp message, decides what to do, calls your own functions (check the menu, create an order, make a payment link), and replies. It works in English, Hindi or Hinglish without extra code.
We'll use Express, the official WhatsApp Cloud API, and an LLM with tool calling. The core is about 150 lines.
How it works
Every incoming message goes through the same five steps:
The customer sends a WhatsApp message to your business number.
Meta's Cloud API sends it to your webhook (POST /webhook).
Your server passes the text, plus a list of tools, to the LLM.
The LLM either replies directly or asks to call a tool (get_menu, create_order, payment_link). Your code runs the tool and sends the result back.…