As a WhatsApp Business Account owner, you have to deal with customer queries and requests. Doing so takes up an enormous amount of your day, leaving you looking for a solution – a chatbot. Specifically, one that uses ChatGPT to provide realistic and sensible answers to your customers’ questions. Keep reading to discover how to integrate WhatsApp with ChatGPT to create that chatbot.
What You Need to Learn How to Integrate ChatGPT into WhatsApp
To complete the integration, you need the following:
- A ChatGPT Application Programming Interface (API)
- A WhatsApp Business Account
- Pipenv
- Python 3.7 or above
- Go
How to Access the ChatGPT API
As long as you have an OpenAI account, you can get your hands on the ChatGPT API. Follow these steps:
Step 1: Head to the OpenAI Platform page and either sign in using your details or hit the “Sign Up” button to create an account. You can also create an account using your Google, Apple, or Microsoft accounts using the appropriate buttons.

Step 2: If you’re creating a new account, enter your name, company name—which is optional—and birthday in the textboxes, then hit “Agree.”

Step 3: Select “API” from the next screen:

Step 4: Select “Dashboard” from the top menu and head to “API Keys” on the left side of the screen.

Step 5: Click on “Start Verification” near the top-right of the screen and enter your phone number in the pop-up. Select “Send Code” to have OpenAI send the verification code to your phone.

Step 6: Enter the six-digit code you received and describe your usage case to OpenAI before hitting “Submit.”

Step 7: Select “Create new secret key” either using the top-right button or the one you’ll find in the center of the screen.

Step 8: Name the key and select “Create secret key.”

Step 9: Copy your secret key, paste it into a document you can access, and hit the “Done” button. You won’t be able to access this key again, so make sure you copy it so you can access it later.

Integrate ChatGPT with WhatsApp Using the API
Unfortunately, the answer to the question “Can we integrate ChatGPT with WhatsApp?” is “no” when dealing with standard WhatsApp accounts. You need to be a WhatsApp Business user, as this gives you access to the WhatsApp API needed to link ChatGPT to WhatsApp. Download the WhatsApp Business app from the Google Play or App Store and follow the steps in the store to install it.


With WhatsApp Business installed, you’ll need to use Pipenv to create a Python Script that allows you to integrate WhatsApp with ChatGPT.
Step 1: Download Pipenv. It’s recommended that you have Python 3.7 or above installed on your device to run this virtual environment management tool.

Step 2: From here, the following code comes from Denis Kuria of Makes Use Of. Enter it into Pipenv to install the OpenAI, Django, and Djangorestframework packages:
pipenv install django djangorestframework openai
Step 3: Create a new Django project with the following code:
django-admin startproject whatsapp
Step 4: Within the new WhatsApp directory you’ve just made, create a new Django app and name it “gpt” using the following code.
py manage.py startapp gpt
Step 5: Head to “whatsapp/settings.py” and add “gpt” to your list of “INSTALLED APPS.” Type ‘gpt’ at the bottom of the list, just above the “].”
Step 6: Go to “whatsapp/urls.py” and add the “gpt” app URL using the following code:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
...
path('api/', include('gpt.urls')), # gpt app URL
]
Step 7: Head to “gpt/views.py” and use this code to create a view for your ChatGPT API. Note the “openai.api_key” variable of the following code. The section in quotation marks after it is where you enter the secret key you generated using OpenAI:
from rest_framework.response import Response
import openai
from rest_framework.views import APIView
class OpenAIGPTView(APIView):
def get(self, request):
input = request.GET.get('q')
openai.api_key = "ENTER_OPENAI_API_KEY"
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": input}]
)
answer = completion['choices'][0]['message']['content']
return Response(answer)
How to Register Your New API
You now have an API endpoint, which will send a GET request that includes your customer’s input to ChatGPT, with Open AI’s generative model then creating a response. You need to register this endpoint and integrate it into WhatsApp.
Step 1: Create a “urls.py” file and enter the following to register your API:
from django.urls import path
from .views import *
urlpatterns = [
path('chat', OpenAIGPTView.as_view()),
]
Step 2: Use the following to run both the “runserver” and “migrate” commands on your API endpoint:
python manage.py migrate
python manage.py runserver
Step 3: If you haven’t already, download and install the most recent version of Go on your device. This will give you access to the “Whatsmeow” client.

Step 4: Clone the “Whatsmeow” client in Pipenv using the following code:
git clone
https://github.com/Huskynarr/whatsapp-gpt.git
Step 5: Head to the “whatsapp-gpt” repository and locate main.go. You should find the following line of code:
url := "http://localhost:5001/chat?q=" + urlEncoded
Replace the line with:
url := "http://127.0.0.1:8000/api/chat?q=" + urlEncode
Step 6: Save your changes and run the file you’ve created by typing “go run main.go” into Pipenv. You’ll be sent to a screen with a QR code.
Step 7: Open WhatsApp Business and head to “Settings,” followed by “QR Code” and “Scan Code.” Scan the QR code you’ve received and, after logging in, you have successfully managed to integrate WhatsApp with ChatGPT.
Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.