How to Connect an Autoresponder for WhatsApp With ChatGPT API: A Step-by-Step Guide
Connecting an autoresponder for WhatsApp with ChatGPT API lets your business answer WhatsApp messages automatically, day and night, with replies that sound like a helpful human rather than a fixed script. A customer asks about opening hours, delivery, or a price, and your bot reads the message, understands what they want, and replies in seconds.
This guide shows you how to connect an autoresponder for WhatsApp with ChatGPT API, step by step. It covers the two main routes, the official WhatsApp Business API and a no-code tool, what you need before you start, how to build the bot, how to test it, and how to launch it safely without breaking WhatsApp rules.
What You Need Before You Start
Before you build anything, make sure you have the four things that every WhatsApp autoresponder needs. Without them, you will get stuck at the first step.
- A WhatsApp Business account. A personal WhatsApp account cannot use the official API. You need a WhatsApp Business account, a business phone number that is not already used on a personal WhatsApp, and a Meta Business account.
- Access to the WhatsApp Business API. You can get it directly through Meta, or through a WhatsApp Business Solution Provider such as Twilio, 360dialog, WATI, Interakt, or respond.io. A provider is easier for most small businesses, because it handles hosting, phone number verification, and message templates.
- An OpenAI account and API key. Sign up at platform.openai.com, add a payment method, and create an API key. Keep that key secret, and never put it in a public file or a screenshot. You will also need to choose a model, such as GPT-4o or GPT-4o-mini, and set a spending limit.
- A place to run your bot. Your bot needs a server that is always online, with a public web address that WhatsApp can send messages to. That can be a simple Node.js or Python app on Render, Railway, Heroku, or a VPS, or a no-code automation tool such as Make or Zapier.
If you do not want to write code, a no-code provider is the right choice. If you want full control over the replies, the data, and the cost, build it yourself with the API. The rest of this guide follows the code route, and then explains the no-code alternative.
How a WhatsApp ChatGPT Autoresponder Works
The flow is simple once you see it as a loop. A customer sends a WhatsApp message. WhatsApp sends that message to your server through a webhook. Your server sends the message to the ChatGPT API, together with a system prompt that tells ChatGPT who it is, what your business does, and how it should reply. ChatGPT returns a reply, your server sends that reply back to WhatsApp, and WhatsApp delivers it to the customer.
| Step | What happens | Who does it |
|---|---|---|
| 1. Customer messages you | A WhatsApp message arrives | Customer and WhatsApp |
| 2. Webhook fires | WhatsApp sends the message to your server | WhatsApp Business API |
| 3. AI generates a reply | Your server asks ChatGPT for a reply | OpenAI ChatGPT API |
| 4. Reply is sent | Your server sends the reply back to WhatsApp | Your server and WhatsApp |
| 5. Conversation continues | Later messages use the same loop, with history | All of the above |
The system prompt is the most important part of the whole setup. It is the instruction you give ChatGPT before it sees any customer message. A good system prompt says who the bot is, what it can and cannot do, what tone to use, and when to hand over to a human. Without it, ChatGPT will give generic answers, make up prices, or promise things your business cannot do.
Step 1: Set Up the WhatsApp Business API
- Create a Meta Business account at business.facebook.com, and add your business details.
- Create a WhatsApp Business app in the Meta Developer portal, and add the WhatsApp product to it.
- Add a phone number. Use a number that is not already on WhatsApp, or remove it from WhatsApp first. Meta will send a verification code to that number.
- Set up a webhook. In the WhatsApp app settings, enter your server’s public webhook URL, for example https://your-server.com/webhook, and a verify token you choose yourself. Choose the messages field, so WhatsApp sends you incoming messages.
- Get a permanent access token. Create a system user in your Meta Business account, give it WhatsApp permissions, and generate a permanent token. Save it in a secure place, such as an environment variable on your server.
- Test with a test number. Meta gives you a free test phone number and a test message you can send from your own phone. Use it to confirm that messages reach your webhook before you go live.
If you use a provider such as Twilio or WATI, steps 1 to 6 are mostly done for you in the provider dashboard. You will still need to verify your business and your phone number, and you will get a webhook URL and an API key from the provider instead of from Meta directly.
Step 2: Get Your OpenAI API Key and Write a System Prompt
- Go to platform.openai.com, sign in, and open API Keys.
- Create a new secret key, copy it, and save it as an environment variable, for example OPENAI_API_KEY, on your server. Never commit it to a public code repository.
- Set a monthly spending limit and usage alerts, so a busy day cannot run up an unexpected bill.
- Write your system prompt. Here is a template you can adapt:
You are a helpful customer support assistant for [Business Name], a [type of business] in [city]. Answer in a friendly, short tone. Use only the information in the knowledge base below. If you do not know the answer, say you will check with a human and ask for the customer's name and phone number. Never make up prices, opening hours, or delivery times. If the customer is angry or asks for a refund, offer to connect them to a human agent.
Keep the prompt short and specific. Add your opening hours, your price list, your delivery areas, and your return policy in the knowledge base section, so ChatGPT has real facts to use. Update that section whenever your prices or hours change.
Step 3: Build the Bot Server
You can build the bot in Python or Node.js. The logic is the same in both: receive the webhook, send the message to ChatGPT, and send the reply back to WhatsApp.
Python example with Flask
This simplified example shows the main flow. In a real bot, you would add error handling, conversation history, and a database.
from flask import Flask, request
import requests, os
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def webhook():
data = request.json
message = data['entry'][0]['changes'][0]['value']['messages'][0]
phone = message['from']
text = message['text']['body']
reply = ask_chatgpt(text)
send_whatsapp(phone, reply)
return 'OK', 200
def ask_chatgpt(text):
response = requests.post('https://api.openai.com/v1/chat/completions',
headers={'Authorization': 'Bearer ' + os.environ['OPENAI_API_KEY']},
json={'model': 'gpt-4o-mini', 'messages': [
{'role': 'system', 'content': 'You are a helpful support assistant.'},
{'role': 'user', 'content': text}]})
return response.json()['choices'][0]['message']['content']
The send_whatsapp function should call the WhatsApp Business API with your access token, your phone number ID, and the customer’s phone number. The WhatsApp API expects a POST to https://graph.facebook.com/v18.0/PHONE_NUMBER_ID/messages, with a JSON body that contains the recipient, the message type, and the text. Check the Meta WhatsApp API documentation for the current version and format, because the version number changes over time.
If you are new to Python, start by confirming your setup with our guide on how to check the Python version on your computer, so you know which Python your bot will run on.
Step 4: Test the Autoresponder Before You Launch
Do not launch a WhatsApp bot without testing it with real messages. Test these cases first, and fix the system prompt for each one that fails.
- A simple question: What are your opening hours? The bot should give the correct hours, not invent them.
- A price question: How much is delivery? The bot should give the correct price or say it will check.
- A question it cannot answer: Do you sell a product you do not sell? The bot should say no, and offer a human.
- An angry customer: I want a refund. The bot should stay polite and offer a human agent.
- A message in another language: The bot should reply in the customer’s language if it can, or say it will get help.
- An out-of-hours message: The bot should say when you will reply, and not promise an instant human reply.
Also test what happens when the ChatGPT API is slow or down. Your bot should send a fallback message, such as Thanks for your message, we will reply shortly, rather than sending nothing at all. Log every conversation, and read the logs for the first week, so you can fix the prompt when the bot makes a mistake.
Step 5: Launch, Monitor, and Hand Over to Humans
When testing looks good, switch from the test number to your real business number, and turn the bot on for a small group of customers first. Watch the conversations for a day, fix the prompt, and then open it to everyone.
Set clear rules for handover. A bot should handle simple questions, such as opening hours, prices, delivery, and order status. It should hand over to a human for refunds, complaints, complex orders, and anything involving money or personal data. Add a keyword such as agent or human that any customer can type to reach a person, and make sure a human actually replies within the time you promise.
Monitor cost, too. Each ChatGPT reply costs a small amount, based on the model and the length of the conversation. Use a cheaper model such as GPT-4o-mini for simple replies, keep the conversation history short, and set a daily spending limit. For more on AI tools and how they work, see our guide to the Perplexity Comet web browser, which shows how AI is being built into everyday browsing.
No-Code Alternative: Use a Provider or Automation Tool
If you do not want to write code, you can connect WhatsApp to ChatGPT with a no-code tool. Providers such as WATI, Interakt, respond.io, and ManyChat have built-in AI reply features, or a ChatGPT integration, where you paste your system prompt and your OpenAI key, and the provider handles the webhook, the server, and the WhatsApp API for you.
Automation tools such as Make and Zapier can also do this. The flow is: WhatsApp Business, New Message, then OpenAI, Create a Completion, then WhatsApp Business, Send a Message. This is slower to set up than a built-in AI feature, but it gives you more control over the logic, such as only replying during business hours, or only replying to messages that contain certain words.
The no-code route costs more per month, but it is faster to launch and easier to maintain. The code route costs less per message, but you are responsible for hosting, updates, and fixing it when it breaks. Choose the route that matches your time, your budget, and your technical skills.
WhatsApp Rules You Must Follow
WhatsApp has strict rules for business messaging, and breaking them can get your number banned. You can only send a free reply to a customer within 24 hours of their last message. After 24 hours, you must use an approved message template, and you must pay for it. You cannot send marketing messages to people who have not agreed to receive them, and you must respect opt-out requests immediately.
Your bot must also be honest. It should say it is an automated assistant if a customer asks, and it should not pretend to be a human. Do not use the bot to collect passwords, payment details, or sensitive personal information on WhatsApp. If a customer shares that information, delete it and ask them to use a secure channel instead.
Frequently Asked Questions
Can I connect ChatGPT to WhatsApp for free?
You can test it for free with Meta’s test number and OpenAI’s free credits, but a live autoresponder is not free. You will pay for the WhatsApp Business API or a provider, and for OpenAI API usage, which is charged per message. A small business can often run it for a few dollars a month.
Do I need the WhatsApp Business API, or can I use normal WhatsApp?
You need the WhatsApp Business API for an official autoresponder. A normal WhatsApp account, or WhatsApp Business app, cannot connect to ChatGPT API directly, and using unofficial tools to automate a personal account can get your number banned.
How do I stop ChatGPT from making up answers on WhatsApp?
Give it a clear system prompt with real facts, tell it to say it does not know when it is unsure, and keep the knowledge base up to date. Test it with questions it cannot answer, and fix the prompt when it invents a price or a policy.
Can the autoresponder hand over to a human?
Yes, and it should. Add a keyword such as agent or human, and a rule that refunds, complaints, and complex orders go to a human. Make sure someone monitors the handover queue, or customers will wait with no reply.
Is it legal to use a WhatsApp autoresponder with ChatGPT?
Yes, if you follow WhatsApp’s business messaging rules, get consent for marketing messages, respect the 24-hour reply window, and handle personal data in line with privacy law in your country. Tell customers they are talking to an automated assistant, and give them a way to reach a human.
Connecting an autoresponder for WhatsApp with ChatGPT API is not a one-day project, but it is a practical one. Start with a clear system prompt, test it with real messages, hand over to humans when it matters, and keep the cost under control. Done well, it will answer your customers in seconds, day and night, and free your team to handle the conversations that really need a person.
