Build a Grok bot for WhatsApp
Grok bots are having a moment. Here is how to put one on WhatsApp, where your customers already are: it reads each incoming message, asks Grok for an answer in your business's voice, and replies from your own number.
What you need
- A Flow API number linked to WhatsApp (7-day free trial)
- An xAI API key from console.x.ai
- Either n8n, or a small server that can receive a webhook
Fastest: built-in AI auto-reply
No n8n, no server. In the Flow API console open your number → AI auto-reply, choose Grok, paste your xAI API key, write your instructions and turn it on. Every incoming message wakes the bot: it reads the recent chat, shows "typing…" and replies. When you answer a chat yourself, the bot stays quiet there for 30 minutes.
Option A: no code, with n8n
- 1Add a Flow API Trigger (community node n8n-nodes-flowapi) set to Incoming Message. Activating the workflow sets your webhook automatically.
- 2Add an AI Agent node with the xAI Grok Chat Model and your xAI API key.
- 3In the agent's system message, describe your business, opening hours and tone, and tell it when to hand over to a person.
- 4Add a Flow API node: Send Text Message to {{ $json.chatId }} with the agent's output.
- 5Activate, then message your number from another phone.
Option B: 30 lines of Python
Set your number's Webhook URL in the Flow API console to this server's /whatsapp address, then run:
import os, requests
from flask import Flask, request
app = Flask(__name__)
SEND = "https://flowapi.pro/waInstance{idInstance}/sendMessage/{apiTokenInstance}"
PROMPT = "You are the WhatsApp assistant of Bright Dental Clinic. Answer briefly and kindly."
@app.post("/whatsapp")
def whatsapp():
n = request.get_json()
if n.get("typeWebhook") != "incomingMessageReceived":
return "ok"
chat = n["senderData"]["chatId"]
text = n["messageData"].get("textMessageData", {}).get("textMessage", "")
if not text or chat.endswith("@g.us"):
return "ok"
r = requests.post("https://api.x.ai/v1/responses",
headers={"Authorization": f"Bearer {os.environ['XAI_API_KEY']}"},
json={"model": "grok-4.3", "input": [
{"role": "system", "content": PROMPT},
{"role": "user", "content": text}]}, timeout=60).json()
reply = next(c["text"] for o in r["output"] if o["type"] == "message"
for c in o["content"] if c["type"] == "output_text")
requests.post(SEND, json={"chatId": chat, "message": reply}, timeout=30)
return "ok"Make it feel human
- Call sendTyping before the reply so the customer sees "typing…".
- Keep answers to a few short lines; WhatsApp is a chat.
- Give the bot a clear hand-off: "A team member will reply shortly" when it is unsure.
Let Grok act, not just answer
Instead of a fixed reply, give Grok the Flow API MCP link as a remote MCP tool. It can then read the conversation history, send your price list as a PDF or create a group with your team, on its own.
Questions
Does the bot need Meta approval or templates?
No. Flow API links your existing WhatsApp number as a device, so the bot replies with normal messages.
What does it cost to run?
Flow API is $10 per number per month. Grok usage is billed by xAI per token.
7 days free, no credit card. Then $10 per number per month.