Creating a chatbot is not only a fun activity, it is also rewarding especially when you want to automate your business or personal communications.
In this guide, we will take you through the process of building a WhatsApp chatbot by leveraging OpenAI’s language model behind ChatGPT. We are developing a bot that automatically responds to WhatsApp messages using natural language.
$ads={1}
This is the source code for building a WhatsApp bot with openAI bot and NodeJS. The bot can deal with natural language and provide answers on different subjects. It can be employed to respond to questions, give suggestions, and even have chatter with users. Through these lines one can make a strong robot which can be used for a wide variety of purposes.
What is WhatsApp ChatBot?
WhatsApp chatbot is a piece of automated software that uses artificial intelligence or predefined rules to carry out conversations on the WhatsApp platform. Our WhatsApp chatbots utilize the power of AI coupled with the one-of-a-kind Natural Language Processing (NLP) engine for the intelligent engagement of your customers.
The WhatsApp chatbots use AI and our own NLP engine to facilitate intelligent interactions with your customers. Use them to answer customers questions about products and services, share content, do promotion, and notify about orders, payments, shipping, and so it on.
The intelligent chatbots of WhatsApp business run on the WhatsApp Business API and communicate automatically with your customers, staffs, students and other. WhatsApp users without human intervention.
$ads={1}
What Is OpenAI?
OpenAI started in 2015 in San Francisco as an initiative of Elon Musk Sam Altman, Greg Brockman, Wojciech Zaremba, Ilya Sutskever and John Schulman. To do the job, the mission was very simple but highly ambitious – it was to create safe and open AI tools that could empower (rather than eliminate) people.
What Is ChatGPT?
ChatGPT is the powerful artificial intelligence bot that belongs to OpenAI. Created by Altablum, Musk, and other Silicon Valley investors, the nonprofit organization engaged in artificial intelligence research and presented on November 30, 2022. ChatGPT is a Pre-Trained Transformer for Chat. It is the best artificial human language comprehension machine that is capable of human speech understanding and generating complex writings that are easily comprehended by humans. The question-and-answer approach utilized by ChatGPT makes it quite engaging.
Setup Requirements
Termux App
Minimum Space Required = 200 MB
Internet
Node js (npm)
Video : (Available soon)
Step – Download the Termux app
Uninstall the old Termux and install the upgraded latest Termux
Start by launching the F-Droid.org mobile site or application on your Android handset.
Search for Termux app.
Download it from your Android phone by clicking the Download
It will download it to your phone too.
Install ApkTool In Termux
$ads={2}
Step 1: Before installing any tool, we should update all our pre-installed packages so as not to get any problems using Apk-Tool in termux. Below command will be used to upgrade packages in termux. To be sure you will not make a mistake while installing WhatsApp Chatbot.
apt update -y && apt upgrade -y
Step 2: ChatGPT this project is hosted on Github, we have to install Git in termux and the project will be downloaded from GitHub repository. Simply go ahead and input the command below and instantaneously the Git package will be installed.
apt install git -y
Step 3: Enter the dependencies for this tool. By doing this we will add curl wget ruby and git to termux and Linux which will be used for further actions. Once you have that you can drop the name from the command while running package installer.
apt install nodejs -yapt install nodejs-lts -yapt install nano -y
Step 4: Now all dependencies are now installed in your termux and now we can install ChatGPT Whatsapp Bot in termux using the given below command. To get this tool’s file size, copy and paste the command below and in about 20 seconds, the tool will be already loaded.
$ads={2}
git clone https://github.com/OnlineHacKing/Whatsapp-ChatGPT
Step 5: Now we will have to switch to the directory Whatsapp-ChatGPT, this can be done by using the "cd" command. If you don’t know the "cd" command, it is a must learning Use the command below in Termux Terminal and press Enter.
cd Whatsapp-ChatGPT
Step 6: Scanning npm install commands, some requirements packages of node.js will be downloaded and the bot will run.
A Node.js client library that links to the WhatsApp web browser application. OpenAI Node.js library gives easy access to OpenAI APIs within Node.js apps. We will implement our chatbot application using this library in the subsequent steps.
npm install
Step 7: Open the nano api.json file in a text editor and type the following environmental variable that holds your OpenAI account API key:
Edit api's in api.json file and add Openal API Key, and save this file. CURLOPT_HTTPAUTH and CURLAUTH_.
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).
$ads={1}
Get OpenAI API
To sign up an account, click the “Sign Up”button on the top right corner of the home page, and then follow the instructions to create a new account. After an account is created, you can obtain API key in the “API” section of your account settings.
Under the sub heading “API” you will see a button named “Generate API Key”. Clicking on that button, you will create a new API key that can be used to call the OpenAI API from your Node.js application afterward. Be very careful with your API key as you never want to share it with any third party in any circumstances.
And replace the text INSERT YOUR OPENAI API KEY in the desktop/desktop.py/api.json file with your API key.
Open the json file thus api.json item and add Openal API Key and save this file. CURL +X and press Y Enter
Step 8: And then enter the command that will start this OpenAI ChatGPT bot. then entering the command at the command line.
node index.js
The output on the command line should then display the QR code correctly:Thus, it was the behaviour of the lamb, illustrating the peril of anticlimax, which made Aristotle reject it as a scene of reversal.
We are then able to validate the QR code by using the WhatsApp mobile application. After scanning the QR code, you should see the following message:
How to scan QR in Whatsapp
- Open WhatsApp
- Click to the three dots at the top right.
- Click the Link Devices Button and then click the link a device Button.
- Scan the QR code
The Chatbot is now running, showing a list of messages. Put the # character and make your question like a WhatsApp post. The response is then generated by OpenAI and automatically accepted as a reply to the original message: If the companies in
And it is done! OpenAI and WhatsApp are pretty well integrated. WhatsApp chatbot is already in the work overtime and responds via WhatsApp.
Notes: If the bot does not answer then restart the termux, restart the bot that that the bot answer.
$ads={2}
Additional information (optional)
On how to Run this What"s app Bot 24/7 ( 24 hours ) Online Free use replit.
Step 1: Next, go to replit.com website, create a new account (if you have no account on this website), or log in to the old one.
Deploying WhatsApp bot to Replit
Step 2: After clicking on Made with Replit button a new page will be opened, it is a website of replit. To create the Repl, you click on the Create Repl Button. Then, you select the language to be Node.js and enter any name.
$ads={2}
Run on Repl.it
Step 3: Downlaod Bot File from the github. whereas the bot file needs to be unzipped. If you are a Mobile User Press Play button or press 3 dots at the top. Upload all bot files.
Step 4: Display Popup Message will appear when Start button is clicked. Open the api.json file. Then, substitute the text INSERT YOUR OPENAI API KEY in the api.json file with your personal API key.
Step 5: After entering a valid API key there will appear a ‘start’ button. Click on the space bar and if already enabled hit the ‘stop’ and ‘start’ buttons and then open the terminal window and scan the QR code in WhatsApp.
Disclaimer
The data presented in the given article is of the author and the advertisers not the investment recommendation as they are intended for educational purpose only. By this you agree that the information provided does not comprise of any investment or financial advice from Analytics Insight or us. Both investors and professional advises must receive their own financial or professional independent advices. Do your own research as well as take advice from financial experts before you make a final investment decision. The Analytics Insight and the team are not liable for the investment viewpoints stated in this article.
Enjoyed this post? Never miss out on future posts on Tech Tutorials Hub by «following us on WhatsApp» or Download our App