Building a chatbot can be a fun and rewarding project, especially if you want to add automated functionality to your business or personal communications. In this guide, we will walk you through creating a chatbot for WhatsApp using the OpenAI language model behind ChatGPT. We are building a bot that automatically generates replies to WhatsApp messages.
This is the source code to build a WhatsApp bot using OpenAI bot and Node.js. The bot is able to understand natural language and provide information on various topics. It can be used to answer questions, provide advice, and even have conversations with users. With this source code, you can create a powerful robot that can be used for various purposes.
What is WhatsApp ChatBot?
A WhatsApp chatbot is an automated software that uses artificial intelligence or pre-programmed rules to engage your customers on the WhatsApp platform. Engati’s WhatsApp chatbots use AI and our proprietary Natural Language Processing (NLP) engine to interact with your customers intelligently.
Engati’s WhatsApp chatbots use AI and our proprietary Natural Language Processing (NLP) engine to interact with your customers intelligently. You can use them to answer customer questions about your products and services, share content, promote sales, and send notifications about orders, payments, shipping, etc.
WhatsApp business chatbots run on the WhatsApp Business API to intelligently communicate with your customers, employees, students, and other users without human intervention.
What Is ChatGPT?
ChatGPT is a powerful artificial intelligence bot developed by OpenAI. Its creators Altman, Musk, and other Silicon Valley investors created a non-profit organization engaged in artificial intelligence research in 2015 and presented it to the world on November 30, 2022. ChatGPT is a Chat Generative Pre-Trained Transformer. It is a powerful artificial intelligence robot capable of understanding human speech and producing in-depth writing that humans easily understand. ChatGPT’s use of a question-and-answer format makes it interesting.
Install ApkTool In Termux / Linux
Step 1:- Before installing any tool we first upgrade all our pre-installed packages in termux so that when we use Apk-Tool we will not face any problems. We will use the command below to upgrade packages in Termux. To avoid mistakes while installing WhatsApp Chatbot.
apt update -y && apt upgrade -y
Step 2:- GhatGPT this project is hosted on Github, we need to install Git in termux to download the project from the GitHub repository. Just type the command below and the Git package will be installed instantly.
apt install git -y
Step 3:- Enter the dependencies in this tool. This will add curl wget ruby and git to termux & Linux which will be used. Once you have this you can remove the name from the command while installing.
apt install nodejs -y
apt install nodejs-lts -y
apt install nano -y
Step 4:- Now all the dependencies are installed in your termux and now we can install GhatGPT Whatsapp Bot in termux using the below command. For the file size of this tool, copy and paste the command below and the tool will load in 10 seconds.
git clone https://github.com/OnlineHacKing/Whatsapp-ChatGPT
Step 5:- Now we need to change the Directory to the Whatsapp-ChatGPT folder, we can use the Cd command for this. If you don’t know about the cd command, it is highly recommended. Just type the below command in Termux and press Enter.
Step 6:- By running npm install commands, some requirement packages of node.js will be downloaded and the bot will run.
A Node.js client library that connects through the WhatsApp web browser application. The OpenAI Node.js library provides convenient access to OpenAI APIs from Node.js applications. We will use this library to implement our WhatsApp chatbot application in the following steps.
npm install Step 7:- Open the nano api.json file in a text editor and insert the following environment variable that contains the API key from your OpenAI account: Enit api.json file and add Openal API Key. and save this file. CURL +X and type Y and Enter nano api.json To get an API key for the OpenAI API, you will need to register a free OpenAI account on the OpenAI website (https://openai.com/):
To register an account, click the “Sign Up” button in the upper right corner of the home page, then follow the instructions to create a new account. Once you have created an account, you can obtain an API key in the “API” section of your account settings.
In the “API” section you will find a button labeled “Generate API Key”. Clicking this button will generate a new API key, which you can then use to request the OpenAI API from your Node.js application. Make sure you keep your API key safe and don’t share it with anyone else.
Then replace the text INSERT YOUR OPENAI API KEY in the api.json file with your personal API key.
Enit api.json file and add Openal API Key. and save this file. CURL +X and type Y and Enter
Step 8:- And type the Command to run this OpenAI ChatGPT Bot. following the command on the command line.
The output on the command line should then display the QR code correctly:
This QR code can then be used for verification via the WhatsApp mobile application. After scanning the QR code, you should see the following message:
How to scan QR in Whatsapp:
- Open WhatsApp
- Click 3 dot top right
- Click the Linked Devices Button and again click the link a device button. or scanning the QR code
Now the Chatbot is running and showing a list of messages. Use the # sign and write the question as a WhatsApp message. The response is then generated by OpenAI and automatically accepted as a reply to the original message:
And it is done! OpenAI and WhatsApp are perfectly integrated. The WhatsApp chatbot is up and running and automatically replies via WhatsApp messages.