DEV Community

Cover image for Using ChatGPT to reply my Whatsapp ?
ogoh cyril
ogoh cyril

Posted on

 

Using ChatGPT to reply my Whatsapp ?

With the advent of artificial intelligence (AI) and natural language processing (NLP), communication has become more seamless than ever before. One such development in this field is the creation of large language models, such as ChatGPT, which can be used to reply to WhatsApp messages. In this article, we will discuss how ChatGPT can be used to reply to WhatsApp messages and the benefits of doing so.

WHAT IS CHATGPT ?
ChatGPT is a state-of-the-art language model developed by OpenAI that has been trained on a large corpus of text data. It is capable of understanding natural language and can generate responses that are coherent and relevant to the conversation.

To use ChatGPT to reply to WhatsApp messages, you will need to integrate it with a messaging app.

There are different ways to integrate ChatGPT with WhatsApp, but one common method is to use a chatbot platform like Twilio or Dialogflow.
These platforms allow you to create a bot that can receive messages from WhatsApp and respond to them using ChatGPT, But neither are free and allow 100% customisation.

BUILDING THE BOT
We are gonna be using Venom to handle the request form Whatsapp, Shout out to the team of maintainer keeping this project alive and free for anyone to use.

To create a bot, you will need to follow these steps:

  • Sign up to OpenAI.
  • Install Venom-bot on your pc npm i venom-bot
  • Integrate ChatGPT with the bot by using its API.
  • Connect the bot to WhatsApp and reply using incoming messages as it prompt.

Step 1

Get your private key from your private setting here

Open AI api keys page

Step 2

Create a dir and install venom-bot and openai packages

$~ mkdir my-bot && cd my-bot
$~ npm init -y
$~ npm i venom-bot openai dotenv

Once the installation is completed we open our IDE and
create a file to help get the response from chatGPT

// File name chatGPT.js
const { Configuration, OpenAIApi } = require("openai");
require('dotenv').config()


const configuration = new Configuration({
  apiKey: process.env.CHAT_GPT_KEY,
});
const openai = new OpenAIApi(configuration);




 exports.response = async (prompt) =>{
  return await openai.createCompletion({
        model: "text-davinci-003",
        prompt: prompt,
        temperature: 0.5,
        max_tokens: 60,
        top_p: 1,
        frequency_penalty: 0.5,
        presence_penalty: 0.28,
        stop: ["You:"],
      })
    }
Enter fullscreen mode Exit fullscreen mode

Now any call to response () return a string response from chatgpt

Then Our main file which contain the Whatsapp bot and the integration

//main.js
const venom = require('venom-bot');
const { response } = require("./chatgpt");

venom
  .create({
    session: 'session-name', //name of session
    multidevice: true // for version not multidevice use false.(default: true)
  })
  .then((client) => start(client))
  .catch((erro) => {
    console.log(erro);
  });

function start(client) {
  client.onMessage((message) => {
// This ignore messages from group and story 
    if (message.body && message.isGroupMsg === false && message.from !== 'status@broadcast') {
        response(message.body).then(data => {
            console.log(data.data.choices[0]);
            client
            .sendText(message.from, data.data.choices[0].text)
            .then((result) => {
              console.log('Result: ', result); //return object success
            })
            .catch((erro) => {
              console.error('Error when sending: ', erro); //return object error
            });
          }).catch(err =>{
            console.log(err);
          })
    }
  });
}

Enter fullscreen mode Exit fullscreen mode

Once you have set up the bot run,

$~ node main
Enter fullscreen mode Exit fullscreen mode

it will be able to reply to WhatsApp messages using ChatGPT. The bot can be customized to respond to specific types of messages or questions, depending on your needs.

Venom Running

Screenshot Of the Bot Replies

Rply 1

Not Sure I could rizz someone as chatGPT does

rep 2

I was laughing when I saw this

Using ChatGPT to reply to WhatsApp messages has several benefits. Firstly, it can save time and effort by automating responses to common questions or inquiries. This can be particularly useful for businesses that receive a large number of messages from customers or clients. Secondly, it can improve the quality of responses by generating coherent and relevant replies that are tailored to the context of the conversation. Finally, it can provide a more seamless and interactive experience for users by allowing them to receive instant responses without the need for human intervention.

In conclusion, ChatGPT can be a powerful tool for replying to WhatsApp messages. By integrating it with a chatbot platform, you can create a bot that can understand natural language and generate responses that are coherent and relevant to the conversation. This can save time, improve the quality of responses, and provide a more seamless and interactive experience for users.

Top comments (22)

Collapse
 
grey41 profile image
Griff Polk

We may never know if chatbots are talking to us the way they are lying!

Collapse
 
cyril_ogoh profile image
ogoh cyril

Yea πŸ˜‚πŸ˜‚

Now imagine I trained it with my previous messages

Collapse
 
grey41 profile image
Griff Polk

OHHH GODDDD

Collapse
 
acidop profile image
Zeeshan πŸŽ–

Yeah love this! We're going to use this to handle our business inquiries. Thanks a lot πŸš€

Collapse
 
cyril_ogoh profile image
ogoh cyril

Yea it’s all depends on how you train and model the input

But to be on a safer side
Use the twillo approach of integrating Chatgpt
It might cost you tho

You welcome πŸ€—

Collapse
 
acidop profile image
Zeeshan πŸŽ–

Alright I will take a look into this

Collapse
 
cyril_ogoh profile image
ogoh cyril

I know right its awesome

Collapse
 
cyborglaksh profile image
Lakshgupta

Bot Lying. Was it trained to do so coz it might save some breakups xD.

Collapse
 
cyril_ogoh profile image
ogoh cyril

πŸ˜‚πŸ˜‚ yea I guess so

Collapse
 
feranmiodugbemi profile image
feranmiodugbemi

Thanks, Really needed this

Collapse
 
cyril_ogoh profile image
ogoh cyril

Thanks you enjoyed it 😊

Collapse
 
grey41 profile image
Griff Polk

OOOOOOHHH!!! He lied oOOoOo but he WAS using a chatbot to reply so aaaaaaaaaaaaaaaaaaaaa

Collapse
 
cyril_ogoh profile image
ogoh cyril

πŸ˜‚πŸ˜‚πŸ˜‚ yea I told him later
Image description

Collapse
 
soultoluene profile image
SOULTOLUENE

Nice

Collapse
 
cyril_ogoh profile image
ogoh cyril

😊 Thank

Collapse
 
simonfalke profile image
simonfalke

This is NOT ChatGPT. This is using the text-davinci-003 GPT-3 language model. ChatGPT is based on GPT-3 but they’re not the same. ChatGPT has the ability to remember the discussion topics, and the general context. GPT-3, a language model, does not. And you didn’t even include the fact that using this language model is paid, while ChatGPT is free and currently does not have any public APIs. GPT-3 has existed for quite a while now, and you’re just riding off the fame of ChatGPT.

Stop misinforming people.

Collapse
 
ugbedeochigbo profile image
Javadroid

Rextz

Collapse
 
paulwababu profile image
paulsaul621 • Edited

bro.. if your sad you couldn't get it to run you can follow my blog πŸ˜‚
dev.to/paulwababu/make-chatgpt-rep...

Collapse
 
victorokpaire10 profile image
Victor Okpaire

How can I use it on a mobile phone

Collapse
 
paulwababu profile image
paulsaul621

You need a server side solution.
dev.to/paulwababu/make-chatgpt-rep...