How to integrate ChatGPT with WhatsApp for customer support

Use the power of ChatGPT  to provide streamlined support to customers on WhatsApp. Here's how to integrate ChatGPT into WhatsApp .

How to integrate ChatGPT with WhatsApp for customer support Picture 1

Many businesses today use messaging apps like WhatsApp to communicate with customers. This led to a spike in automating customer interactions with chatbots.

Take for example the ChatGPT chatbot, a massive OpenAI language model that you can integrate with WhatsApp to automate customer interactions by providing quick and accurate responses to guest requests.

How to access ChatGPT API

Before integrating with WhatsApp, you need to have a basic understanding of ChatGPT and ChatGPT API. ChatGPT is a large language model that takes text-based queries and returns human-like responses. OpenAI provides a simple API interface for programmers to access and use ChatGPT's GPT 3.5 & 4 modules.

To access the ChatGPT API key, you need to navigate to the OpenAI API platform. After logging in, click on the profile icon. Then, click the View API keys option .

 

How to integrate ChatGPT with WhatsApp for customer support Picture 2

Next, click Create new secret key to generate a new API key.

How to integrate ChatGPT with WhatsApp for customer support Picture 3

Enter the required details, for example the name of the key.

How to integrate ChatGPT with WhatsApp for customer support Picture 4

A secret key will be prompted.

How to integrate ChatGPT with WhatsApp for customer support Picture 5

 

Copy and store the key in a safe place for later use.

Set up a WhatsApp Business account

To integrate ChatGPT with WhatsApp, you must set up a WhatsApp Business account. Note, WhatsApp Business is different from normal WhatsApp. This account will allow you to access the WhatsApp Business API, which you will integrate with the ChatGPT API.

You can use a third-party service like the Kommunicate chatbot, WhatsApp, or a Python script to integrate ChatGPT with WhatsApp. This tutorial focuses on integrating ChatGPT with a Python script. It will then give you an overview of the integration using a WhatsApp chatbot.

Use Python script to integrate WhatsApp with ChatGPT API

Before you start programming, create a virtual environment for your application using Pipenv as follows:

pipenv install django djangorestframework openai

This command will install the django , djangorestframework , and openai packages . Then create a new Django project.

django-admin startproject whatsapp

Navigate to the whatsapp folder and create a Django app named gpt :

py manage.py startapp gpt

In whatsapp/settings.py file , add new app, gpt on installed apps list as follows:

INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'gpt', ]

In the whatsapp/urls.py file , add the gpt app URL . This action will lead to the URLs you will create on the gpt app :

from django.contrib import admin from django.urls import path, include urlpatterns = [ . path('api/', include('gpt.urls')), # gpt app URL ]

On the gpt/views.py file , add the following block of code to create the ChatGPT API viewer:

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)

The view sets up an API endpoint, waiting for a GET query with query parameter q including user input. It then uses OpenAI's gpt-3.5-turbo model to generate a response based on the provided input and return the result as the API output.

Next, create the file urls.py and register the API view window by adding the following line of code:

from django.urls import path from .views import * urlpatterns = [ path('chat', OpenAIGPTView.as_view()), ]

 

Run the migrate and runserver commands as follows:

python manage.py migrate python manage.py runserver

Test the /api/chat endpoint by sending a GET query to http://localhost:8000/api/chat?q=Hello .

Result:

How to integrate ChatGPT with WhatsApp for customer support Picture 6

Next, install Go if you don't already have it installed on your computer.

Clone the Whatsmeow client with the command below:

git clone https://github.com/Huskynarr/whatsapp-gpt.git

Navigate to the repository , whatsapp-gpt , and on this file, main.go update this line:

url := "http://localhost:5001/chat?q=" + urlEncoded

Wall:

url := "http://127.0.0.1:8000/api/chat?q=" + urlEncode

Save changes and run this file:

go run main.go

This app will prompt you with a QR code to login to your WhatsApp account.

Result:

How to integrate ChatGPT with WhatsApp for customer support Picture 7

Navigate to the WhatsApp mobile app and navigate to Settings > QR code > Scan code to add the linked device and scan the QR code that appears on your terminal.

Once logged in, this app will start listening for incoming notifications. If someone sends a notification, the received message generates a GET query to the API with the message as a query parameter and sends a response back to the sender on WhatsApp.

Result:

How to integrate ChatGPT with WhatsApp for customer support Picture 8

Use WhatsApp chatbot to integrate application with ChatGPT API

Another way to integrate ChatGPT into WhatsApp notifications is to use a WhatsApp chatbot. After signing up for the WhatsApp Business API, use a chat builder like OpenDialog to create a chat thread. Then you test the chatbot and add it to your mobile.

Integrate OpenAI API with WhatsApp Chatbot

To integrate WhatsApp chatbot with OpenAI templates, use API key from OpenAI. Although this method is easier when you have a chatbot, you should only choose it when you are comfortable with the possible risks.

 

Configure automatic responses

For better customer service, configure automatic responses to provide fast and accurate customer message responses. These responses will personalize customers by name and provide relevant responses to customer queries.

Testing WhatsApp chatbot

Like all AI API system, testing is key before you implement WhatsApp chatbot. This ensures it works as expected. API testing tools like Postman and Curl can help you test chatbot responses.

In this case, the Django REST framework provides a browseable API to help test the API query and response.

Measure success and fine-tune

After implementing a WhatsApp chatbot, it is important that you measure its success and usage over time. This helps you fine-tune it accordingly. Analytics tools like OpenDialog and Rasa can help track metrics like response time, retention rates, and customer satisfaction.

Above is how to integrate ChatGPT into WhatsApp . Hope the article is useful to you.

5 ★ | 1 Vote

May be interested

  • These features make it easier to master WhatsAppThese features make it easier to master WhatsApp
    whatsapp is one of the most popular messaging apps on mobile devices. to better understand whatsapp as well as how to use it. in the article below, network administrator will introduce you 10 good tips to help you understand whatsapp in the palm.
  • Instructions for creating stickers using ChatGPTInstructions for creating stickers using ChatGPT
    users can combine the sticker creation feature available on some high-end phones to create their own stickers on chatgpt, from images uploaded by users.
  • How to automate document creation with ChatGPT in Microsoft WordHow to automate document creation with ChatGPT in Microsoft Word
    thanks to a handy add-on, you can seamlessly integrate the power of chatgpt into microsoft word, making your document creation process more efficient.
  • How to use WhatsApp to chat, call, message your friendsHow to use WhatsApp to chat, call, message your friends
    currently, many ott applications are really thriving, not only in vietnam market because of its simplicity and convenience completely free of charge. previously, we showed you how to use 2 ott applications: zalo and viber. today, we will guide you to add a very famous application, which is whatsapp. let's refer to offline.
  • 10 Essential Chrome Extensions to Use ChatGPT10 Essential Chrome Extensions to Use ChatGPT
    when using chatgpt regularly, especially if you're on the free version, some chrome extensions can significantly improve your experience.
  • 8 tips to enhance security for WhatsApp8 tips to enhance security for WhatsApp
    if you spend a lot of time chatting with friends and family on whatsapp, you will have big problems if someone enters your account or reads the conversation and knows all the information about you.
  • How to register for ChatGPT's new plugin featureHow to register for ChatGPT's new plugin feature
    chatgpt plugins are software components integrated into the chatgpt platform. they provide chatgpt with additional information and allow chatgpt to perform specific actions on the user's behalf.
  • Is GitHub Copilot or ChatGPT better for programming?Is GitHub Copilot or ChatGPT better for programming?
    github copilot and chatgpt are two of the most popular ai programming support tools available. they use the same gpt large language model and are capable of generating, recommending, and testing code. so which one should you use?
  • WhatsApp can become a web browserWhatsApp can become a web browser
    according to the information of androidworld page, after analyzing some of the code in the latest whatsapp version, the experts discovered some commands that whatsapp can add the ability to surf the web when using the application.
  • Things to keep in mind when using WhatsApp on the WebThings to keep in mind when using WhatsApp on the Web
    whatsapp application now has a version for both computers and mobile devices. all messages you send and receive are fully synchronized on your phone and computer, so you can view all messages on both devices.