Build a WhatsApp AI agent with n8n, Make or your own code · Lime API
Wire incoming WhatsApp messages to an LLM and send its answer back: n8n, Make and Node.js versions, plus human handoff and anti-ban tips.
An AI agent on WhatsApp is three pieces joined together: something that hears the customer, something that thinks, and something that answers. With Lime API the first and last pieces are already built. You bring the thinking part, using the model and the tool you prefer.
To be clear about what Lime does: Lime does not ship its own chatbot that answers customers. It gives you the WhatsApp side (webhooks for incoming messages, sendMessage for replies, an inbox for your team) and lets you plug in any LLM. That keeps you in control of the model, the prompt, the cost and the data.
The architecture
- A customer sends a WhatsApp message to your linked number
- Lime POSTs an
incomingMessageReceived webhook to your URL - Your workflow passes the text (and recent history) to an LLM with your instructions
- The LLM returns an answer, or decides a human should take over
- Your workflow calls
sendMessage and the customer gets the reply
You can build this in n8n, in Make, or in about 40 lines of code. The logic is the same in all three.
Option 1: n8n
- Add the Lime API Trigger node, which registers its URL as the instance's webhook for you. (A generic Webhook node works too; paste its production URL in the Lime panel.)
- Enter your idInstance and apiTokenInstance as the credentials
- Add an IF node that lets through only
typeWebhook = incomingMessageReceived and chat IDs that do not end with @g.us (skip groups unless you want the bot in them) - Add an AI Agent node. Connect a chat model (OpenAI, Anthropic, Gemini or a local model) and a memory node keyed on
senderData.chatId, so every customer gets their own conversation history - Put your instructions in the system message: who you are, what you sell, prices, opening hours, what the bot must never promise, and when to hand off
- Finish with the Lime node (or an HTTP Request node) that calls
sendMessage with the chatId from the webhook and the agent's output
The incoming text is at messageData.textMessageData.textMessage. Messages with links arrive as extendedTextMessage, with the text at messageData.extendedTextMessageData.text. Handle both.
Option 2: Make
- Start a scenario with Lime's trigger for incoming messages, or a Custom webhook whose URL you paste in the Lime panel
- Add a filter: incoming messages only, private chats only
- Add an AI module (OpenAI, Anthropic Claude, Gemini or Make's own AI agent) with your instructions and the message text
- Add Lime's send message module with the sender's
chatId and the AI output
Lime's Make app has 45+ modules, so the same scenario can also look up the customer in your CRM, check an order, or send a PDF with sendFileByUrl before it replies. See all apps on the integrations page.
Option 3: your own code
If you want full control, here is a minimal Node.js server. It verifies the webhook token, ignores groups and non-text messages, asks your model for an answer, and sends it back.
import express from 'express'
const BASE = 'https://api.lime-api.com/waInstance' + process.env.LIME_ID
const TOKEN = process.env.LIME_TOKEN
const HOOK_SECRET = process.env.HOOK_SECRET // same value as webhookUrlToken in Lime
async function lime(method, body) {
const res = await fetch(BASE + '/' + method + '/' + TOKEN, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
})
return res.json()
}
// Call the LLM you prefer here. Give it your FAQ, prices and hours in the
// system prompt, plus recent messages from getChatHistory.
// Return the reply text, or null to leave the chat for a human.
async function generateReply(chatId, text) {
const history = await lime('getChatHistory', { chatId, count: 20 })
return askYourModel(history, text)
}
const app = express()
app.use(express.json())
app.post('/whatsapp', async (req, res) => {
if (req.get('authorization') !== 'Bearer ' + HOOK_SECRET) return res.sendStatus(401)
res.sendStatus(200) // acknowledge first, think later
const hook = req.body
if (hook.typeWebhook !== 'incomingMessageReceived') return
const chatId = hook.senderData.chatId
if (chatId.endsWith('@g.us')) return
const data = hook.messageData
const text = data.textMessageData?.textMessage ?? data.extendedTextMessageData?.text
if (!text) return
const reply = await generateReply(chatId, text)
if (reply) await lime('sendMessage', { chatId, message: reply })
})
app.listen(3000)
Two details matter here. First, the server returns 200 before calling the model. LLM calls can take several seconds, and you don't want the webhook to time out and be retried. Second, webhookUrlToken is sent as an Authorization: Bearer header, so a stranger who finds your URL cannot make your bot talk.
For production, add a queue per chat (so two fast messages from the same customer don't produce two parallel answers) and log every prompt and reply. If you are new to the API, start with the 2-minute quickstart.
The MCP alternative
There is a second way to give an AI agent WhatsApp abilities: Lime's MCP connector. Instead of you wiring each API call, the agent gets a set of tools (send_message, get_chat_messages, search_messages, check_whatsapp, schedule_message, create_auto_reply and more) and decides which to use.
n8n and Make AI agents can connect to any remote MCP server over Streamable HTTP. Paste your Lime MCP URL into the agent's MCP client, and the agent can, for example, read the last 20 messages of a chat before it answers, without you building that step.
The trade-off: webhooks plus sendMessage give you a predictable pipeline that is easy to test. MCP gives the agent more freedom, which is great for internal assistants and less suited to a bot that talks to every customer. Many teams use both: a webhook pipeline for customer replies, MCP for the staff assistant. Setup is in Connect Claude, ChatGPT and Gemini to WhatsApp.
Tips that make the agent feel human and keep the number safe
Simulate typing
An answer that lands 200 ms after the question feels like a machine. Turn on Simulate typing in the instance's protection settings: Lime shows "typing..." before each text message, for 1 to 8 seconds depending on the length. You can also call sendTyping yourself.
Hand off to a human
Decide upfront when the bot steps back: complaints, refunds, anything it is unsure about, or the customer asking for a person. In those cases the agent sends a short holding message (or nothing) and stops. The chat stays in Lime's shared inbox, where your team sees the full conversation and replies from the browser.
To keep the bot from talking over your team, record the idMessage of every message the bot sends. When an outgoing webhook shows a message in that chat that the bot did not send, a person has taken over. Pause the bot for that chat for a few hours.
Respect anti-ban limits
An agent that only replies to people who wrote first is low risk. Trouble starts when the same setup is used to cold-message lists. Keep Lime's protection on (random delays, daily limits, sending window), don't let the agent start conversations with numbers that never contacted you, and read How to avoid a WhatsApp ban.
Keep simple answers simple
Not every message needs an LLM. "What are your hours?" can be a keyword rule in Lime's built-in automations, with no model call and no cost. Use automations for fixed answers and outside-hours replies, and the agent for everything else. More on that in WhatsApp automation without code.
What it costs
On the Lime side: the API, webhooks, automations, the shared inbox and the MCP connector are included in every plan. Pro is $9.90 per number per month, with no per-message fees, so a busy bot costs the same as a quiet one. Your LLM provider bills you separately for tokens. Agencies running bots for clients can use the Agency plan at $7.50 per number per month (see WhatsApp API for agencies).
Start building
Create a free Developer account, link a number, and point the webhook at n8n, Make or your server. The free plan works with up to 3 destination numbers, enough to test the agent end to end. Register free or compare plans.