DEV Community

Cover image for How to build a WhatsApp Chatbot with n8n, AWS, and OpenAI
Jose Luis
Jose Luis

Posted on

How to build a WhatsApp Chatbot with n8n, AWS, and OpenAI

If you want to build your own WhatsApp chatbot to receive text and voice messages, process them with AI, and reply automatically, this guide shows a practical way to do it using n8n + OpenAI + Meta + AWS.

๐Ÿง  What will you learn?

In this post you will see how to:

  • Connect OpenAI AI services with n8n
  • Connect WhatsApp Business Cloud services with n8n
  • Receive text and voice messages and reply automatically from an n8n workflow
  • Estimate basic operation costs

๐Ÿ› ๏ธ Implementation step by step

1. Prerequisites โœ…

Before you start, you need:

2. Import chatbot workflow ๐Ÿ’ฌ

Import the workflow from the n8n folder in the whatsapp-chatbot repository. Copy and paste the content of the whatsapp-chatbot.json file into n8n.

This workflow allows you to:

  • Receive text or voice messages from WhatsApp
  • Detect if the content is audio
  • Download and transcribe the audio
  • Run an OpenAI LLM model
  • Send the response back to WhatsApp

3. Configure OpenAI in n8n ๐Ÿง 

To run OpenAI Large Language Models (LLM) in n8n, you need an API Key to authenticate requests. Steps:

  1. Go to OpenAI Platform with your account
  2. In the side panel, open API Key and create a key
  3. In the n8n workflow, in the Transcribe Recording node, configure OpenAI credentials

4. WhatsApp Business API ๐Ÿ“ฒ

To send and receive voice and text messages from WhatsApp, you need to create an app in Meta Developer and configure it to get credentials for n8n.

Steps:

  1. Create an app in the Meta Developers portal
  2. Add the use case Connect with customers through WhatsApp
  3. Confirm app creation

Send messages to WhatsApp ๐Ÿ“ค

To enable sending messages from n8n, you need authentication credentials. Steps:

  1. In Meta Developer, open your app and go to the WhatsApp configuration. Copy the WhatsApp Business Account ID

  2. In Meta Business, go to system users. Select or create a user

  3. Assign the Meta Developer app to that system user

  4. Generate an access token. Set permissions to whatsapp_business_messaging

  5. In n8n workflow, in the Send Message (WhatsApp Business Cloud) node, create WhatsApp credentials using values from steps 1 and 4. Test the connection

Receive messages from WhatsApp ๐Ÿ“ฅ

We will use WhatsApp test numbers to receive messages. For real numbers, follow extra steps.

Each message triggers a Webhook in n8n. Steps:

  1. In Meta Developer, go to app settings and get App ID and App Secret

  2. In n8n workflow, in WhatsApp Business on Message node, create OAuth credentials with App ID and App Secret. Test connection

  3. Publish the n8n workflow so it is available online

  4. Copy the Production POST URL from the node (this is your webhook endpoint)

  5. In Meta Developer, set this URL in the WhatsApp configuration with a verification token. Test connection

5. Test the chatbot ๐Ÿค–

Use WhatsApp test phone numbers to run the chatbot workflow. Steps:

  1. In Meta Developer, go to WhatsApp API settings and copy the test number

  2. Send a message from your WhatsApp to that number

Costs ๐Ÿ’ฐ

OpenAI API ๐Ÿค–

The cost of OpenAI API depends on:

  • Model used
  • Number of tokens
  • Input vs output usage

Output is usually 3โ€“6 times more expensive than input.

Model Input ($/1M tokens) Output ($/1M tokens) Context Recommended use
GPT-5.4 $2.50 $15.00 ~1M tokens High complexity, agents
GPT-5.4 mini $0.75 $4.50 400K tokens Apps, SaaS, chatbots
GPT-5.4 nano $0.20 $1.25 ~400K tokens Classification, extraction

Monthly estimate ๐Ÿ“Š

WhatsApp conversation (1โ€“5 minutes):

  • Messages per conversation: 6โ€“12
  • Words per message: 8โ€“15
  • Total words: ~120

Conversion:

  • 1 token โ‰ˆ 0.75 words
  • 120 words โ‰ˆ 160 tokens
Type Tokens
User input 80
Model output 80
Total 160

Monthly scenario ๐Ÿ“…

Example: 10,000 conversations/month

Model Monthly cost
GPT-5.4 $14 USD
GPT-5.4 mini $4.2 USD
GPT-5.4 nano $0.4 USD

Meta API ๐Ÿ“ฑ

WhatsApp Business API uses a pricing model based on message categories:

  • Service
  • Utility
  • Authentication
  • Marketing

Service messages (user starts the chat) are free within a 24-hour window.

Monthly estimate ๐Ÿ“ˆ

  • 600 service messages โ†’ $0

Total Meta cost ๐Ÿ’ต: $0/month

n8n

n8n cost depends on infrastructure and number of workflow executions (conversations). Below table shows the comparation between Self-hosted using AWS cloud services and Cloud Starter:

Variable Self-hosted (AWS) Cloud Starter Cloud Pro
Base cost Low (infra + ops) Medium (~โ‚ฌ20โ€“โ‚ฌ30/mo) High (~โ‚ฌ50โ€“โ‚ฌ100+/mo)
Infrastructure Your responsibility Included Included
Executions Unlimited (depends infra) Limited (~5kโ€“10k/mo) Higher (~20kโ€“50k+/mo)
Scalability Manual Auto (limited) Auto (better)
Security Full control Managed by n8n Managed by n8n
Concurrency Depends on resources Limited Higher
Integrations All All All
Maintenance High (needs DevOps) Low Low
Multi-user Manual setup Limited Full (roles, teams)

Top comments (0)