I Built a WhatsApp AI Agent with n8n | Free Source Code
Connect WhatsApp to an AI agent in n8n. Set up the Meta WhatsApp Cloud API, a permanent access token and webhooks, then let OpenAI reply to every message automatically. Import-ready workflow included.
- Published
- Video length7 min
- No code
- Official WhatsApp API
- Permanent token
- OpenAI powered
- Import-ready workflow
- Replies in seconds
Features
- Replies to WhatsApp messages automatically with AI
- Uses the official Meta WhatsApp Cloud API with a free test number
- Permanent system user access token, so it doesn't expire after 24 hours
- n8n WhatsApp Trigger listens for incoming messages in real time
- AI Agent node powered by an OpenAI chat model
- Replies go back to the same number that sent the message
- Easy to extend with memory and tools
- Ready-to-import n8n workflow JSON
About this project
In this video I build a WhatsApp AI agent that reads every incoming message and replies on its own, using n8n, OpenAI and the official WhatsApp Cloud API from Meta. No third-party WhatsApp tools and no code.
We start in Meta for Developers: create a Business app, add the WhatsApp product and get a free test number. Then we go into Meta Business Suite to create a system user, assign the app and WhatsApp account to it, and generate a permanent access token with the right WhatsApp permissions, so the agent doesn't stop working when a temporary token expires.
In n8n the workflow is three nodes: a WhatsApp Trigger that receives messages, an AI Agent powered by an OpenAI chat model, and a WhatsApp Send Message node that replies to the same number. I connect the WhatsApp OAuth and API credentials, add the OpenAI key, subscribe the app to message webhooks and test the whole flow live from a real phone.
The finished workflow is available as a JSON file. Import it into your own n8n account, add your credentials and your WhatsApp AI agent is running in minutes.
Who it's for
Business owners, freelancers and automation builders who want an AI assistant that answers customers on WhatsApp around the clock.
What you will learn
- How to create a Meta Business app and add the WhatsApp product
- How to get a free WhatsApp test number and add recipient numbers
- How to create a system user and generate a permanent access token
- Which WhatsApp permissions the token needs
- How to connect WhatsApp OAuth and WhatsApp API credentials in n8n
- How to set up an AI Agent with an OpenAI chat model
- How to subscribe to WhatsApp message webhooks
- How to test the full flow from your phone
Requirements
- An n8n account (n8n Cloud or self-hosted)
- A Meta (Facebook) account with a Meta Business portfolio
- An OpenAI API key with credits
- A phone with WhatsApp for testing
- No coding experience needed
Built with
Setup instructions
- Create a free n8n account at n8n.io (or open your self-hosted n8n)
- Create a new workflow, open the ⋯ menu and choose Import from File, then pick the JSON file
- In Meta for Developers, create a Business app, add WhatsApp and note your test Phone Number ID and WhatsApp Business Account ID
- In Meta Business Suite, create a system user, assign the app and WhatsApp account, and generate a permanent token with whatsapp_business_messaging and whatsapp_business_management
- WhatsApp Trigger node: create a WhatsApp OAuth credential with your App ID as Client ID and App Secret as Client Secret
- Send Message node: create a WhatsApp API credential with the permanent token and Business Account ID, then pick your sender phone number
- OpenAI Chat Model node: add your OpenAI API key and choose a model
- In your Meta app, open Webhooks and subscribe to the messages field
- Publish the workflow and send a WhatsApp message to your test number



Reviews & comments
Reviews & comments
Built it yourself? Tell others how it went, or ask a question.
Leave a review