DEV Community

Cover image for How I Created Whatsapp bot to talk with my friends?
Arpit Vasani
Arpit Vasani

Posted on • Edited on

How I Created Whatsapp bot to talk with my friends?

Index

🤔 Why?

The title seems kinda rude and lazy. Right? But if you think about the situation I am in then you'll understand. Here in India it's important to be socially active than being alive. If you don't reply or send a few "good morning" messages in a few groups, People would think you are actually dead. and taunt you for being busy and not spending time with them.😤

Now, the thing with me and social media is, I want to use it on my time not when they send me a notification. So, there are situations Where I reply to a post after 4-5 days and by that time my reply would not matter, as that moment would have been gone. Let's consider about posting. For example birthdays anniversaries etc... But the thing is I don't want to be that guy who replies after 4-5 days. We all have 24 hours and I try my best to allocate it to all the things and priorities I have at my disposal. I'd get disappointed if someone replies to me after a week so I don't want to be that guy for them.

So, I have come up with my programming skills to solve/automate this scenario which will save my screen time.🤩

🤨 How?

How did I got inspired?

I was looking to do an automation on the web and just like Google's top result, Selenium popped up in my mind but, as a JavaScript enthusiast, I choose JS as my ally. As an matter of fact, I found few modules in npm for Selenium but wasn't really impressed by that😐.

While searching for that I stumbled upon this video from google IO 2018 and then this one which got me thinking like

this

How I did it?

First, I learned about a few tricks from this post


then, I realized that relying on DOM is not a good idea🤨. What if classes or selectors I have used got updated in the page🤔? So I decided not to use DOM. (But I ended up using it any way for other feature🤷‍♂️. Will write about it in another post. Stay Tuned.......😎)

Just like a production issue solved before the deadline😏, I found one repo which gives programmable access to the WhatsApp which works the same way as I want it.

Enough show me the code

Here are the overall steps and gist. I have added a link to the repo as well.

  1. First I created a puppeteer browser window and opened Whatsapp like this

code screenshot

  1. Then, I created a json file to manage messages and it's equivalent reply and also to add some configs.

code screenshot

  1. Next, I added a function inside inject.js which would be called every time I get a new message

code screenshot

Final results

With the few garnishing with libraries like Ora, Cli-progress and qrcode-terminal on the top

Garnishing giphy meme

I got this

preview of wbot

Here is the full code

GitHub logo vasani-arpit / WBOT

A simple Web based BOT for WhatsApp™ in NodeJS 😜. Working as of 📅 Feb 4th, 2024

WBOT

Support me on Patreon Buy me a book PayPal

A simple Nodejs BOT for whatsapp web

PreviewFeaturesDownloadsHow to?Technologies UsedWhy?GoalsdeployFAQ

🔍 Preview

Quick preview

Screenshot gif

⚡ Features

  • 🎨 Highly customizable json
  • 💯 Totally Free for personal use
  • 🔒 Complete Privacy. Your data stays with you always
  • 💻 Download media files automatically
  • 👥 Multiple instances

⬇ Downloads ⬇

Supported Platforms

Following platforms are supported by Wbot:

macOS: The minimum version supported is macOS 10.9.

Windows: Windows 7 and later are supported.

Linux:

  • Ubuntu 12.04 and later
  • Fedora 21
  • Debian 8

How to start the BOT?

STEPS

After downloading, extract the zip file and open the bot.json file and in the third line change the value of "headless" from true to false. Now, navigate to the location of the WBOT folder in your terminal…

✌ Conclusion

This is what technology is all about. Identify the problem and fix the problem with the tools/tech. Isn't it?
There are so many possibilities with the combination of the tools like Google Puppeteer and NodeJS. We just need to be self aware enough to look for solution to the problem we have in day to day life.


!! Reward me with your comments below🎁..... You are awesome !!

Thanks starline for the background vector

P.S: This is the first time I am sharing/writing over the internet. Feel free to point out mistakes so that I can improve that for my next post.

Top comments (14)

Collapse
 
noriste profile image
Stefano Magni

I did something similar (yours is better) for the Xmas greetings 😁
github.com/NoriSte/whatsapp-messag...

Collapse
 
arpitvasani profile image
Arpit Vasani

Awesome !! 👍👍

Collapse
 
zed_m profile image
Amine Hammou

You Indians are freaks

Collapse
 
arpitvasani profile image
Arpit Vasani

Ha ha ... 🤣😂

Collapse
 
aore profile image
Emmanuel Oreoluwa

My next project surely
thanks

Collapse
 
nicolalc profile image
Nicola

That's crazy! I've tried it and, what a heck! Great job dude!

I have only a question, how can you handle the window style?

Collapse
 
arpitvasani profile image
Arpit Vasani

Thanks !! 😁
Google's puppeteer handles that by default.

Collapse
 
nicolalc profile image
Nicola • Edited

Yes I did it finally, and also I've touched the dark styling, this is a partial result:

wpdark

Thread Thread
 
arpitvasani profile image
Arpit Vasani

oh... The dark mode. I love it. There is a dark-mode branch in the WBOT repo which you can refer. You may want to look at userstyles.org/styles/137361/fully... this may save you some time.

Collapse
 
joshianand0478 profile image
Anand Joshi

It’s just a excellent plus handy little bit of information. Appreciation for sharing.

Collapse
 
diasboldrin profile image
diasboldrin

Congrats man.... How could I deploy this service?

Collapse
 
zerquix18 profile image
I'm Luis! \^-^/

Any risks of getting banned?

Collapse
 
arpitvasani profile image
Arpit Vasani • Edited

Replying to someone is not against their policy. So no you will not get banned. There is nothing wrong in being cautious.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.