Can can n8n connect to whatsapp?
Yes. n8n can connect to WhatsApp using the WhatsApp Cloud API, Twilio, or a webhook gateway and send messages automatically. This tutorial shows a simple Docker and Node.js workflow that calls the WhatsApp API from an n8n HTTP Request node and from Node.js.
What You Need
- n8n running in Docker or Node.js runtime.
- A WhatsApp Cloud API account (Facebook Business) or Twilio WhatsApp number.
- An access token and phone_number_id for the WhatsApp Cloud API.
- Basic knowledge of n8n nodes: Webhook and HTTP Request.
can n8n connect to whatsapp via the WhatsApp Cloud API
How to Install n8n with Docker
Start n8n in Docker on port 5678. This command runs n8n locally for testing.
docker run -it --rm -p 5678:5678 --name n8n
-e N8N_BASIC_AUTH_ACTIVE=true
-e N8N_BASIC_AUTH_USER=admin
-e N8N_BASIC_AUTH_PASSWORD=strongpassword
n8nio/n8n:latest
Step 1: Create a Webhook Trigger in n8n
Open n8n at http://localhost:5678. Create a new workflow. Add a Webhook trigger node. Set method to POST. Copy the webhook URL for testing.
Step 2: Add an HTTP Request Node to Call WhatsApp
Use the HTTP Request node to POST to the WhatsApp Cloud API. Set URL to your phone_number_id endpoint and add the Authorization header with Bearer token. Map the webhook body to the message payload.
POST https://graph.facebook.com/v15.0//messages
Headers:
Authorization: Bearer
Content-Type: application/json
Body (JSON):
{
"messaging_product": "whatsapp",
"to": "RECIPIENT_PHONE",
"type": "text",
"text": {"body": "Hello from n8n!"}
}
Step 3: Test the Workflow
Send a POST request to the n8n webhook URL with a test payload. The HTTP Request node will call WhatsApp Cloud API and deliver the message to the recipient.
curl -X POST 'http://localhost:5678/webhook/12345' \
-H 'Content-Type: application/json' \
-d '{"to":"RECIPIENT_PHONE","text":"Hi from webhook"}'
How to Send from Node.js (Optional)
If you need Node.js to trigger messages, use a small script that hits the WhatsApp API. Keep tokens in environment variables.
// send-whatsapp.js
const axios = require('axios');
const token = process.env.WHATSAPP_TOKEN;
const phoneId = process.env.WHATSAPP_PHONE_ID;
async function send(text, to){
const url = `https://graph.facebook.com/v15.0/${phoneId}/messages`;
await axios.post(url, {
messaging_product: 'whatsapp',
to,
type: 'text',
text: { body: text }
}, {
headers: { Authorization: `Bearer ${token}` }
});
}
send('Hello from Node.js', 'RECIPIENT_PHONE').catch(console.error);
Step-by-step Logic
- Run n8n and secure it with basic auth or reverse proxy.
- Create a Webhook node to receive triggers.
- Add an HTTP Request node with WhatsApp API URL and token.
- Map incoming data to the message body and send.
- Test and monitor delivery using the Facebook Graph API responses.
Update
To update n8n Docker image, pull the latest image and recreate the container. Stop the current container, then run the new image. Test workflows after updating.
docker pull n8nio/n8n:latest
docker stop n8n && docker rm n8n
# re-run the docker run command from above with your env vars
Security
Store access tokens in environment variables or n8n credentials, never in plaintext workflows. Use HTTPS in production behind a reverse proxy like Nginx. Limit webhook exposure with secrets or IP allow lists. Rotate tokens regularly and use least privilege on API apps.
Done
You now have a basic n8n workflow that can send WhatsApp messages using the WhatsApp Cloud API or Node.js. Expand the workflow to add templates, media, or Twilio integration as needed.