Make WhatsApp Group Chat More Fun

Ferry Djaja
6 min readNov 30, 2020

In this blog, I am going to share how you can make your WhatsApp Group chat more fun.

I have been using WhatsApp app a lot. I using it to communicate with my families, friends, colleagues or anyone that is also in WhatsApp. I also created a group chat in WhatsApp for my internal family member, my bigger families and with colleagues and friends.

Sometimes the group chat can be very quite, none of us post a single chat message in a single day. I was thinking why not create a bot to post a daily chat summary activity by end of the day. The bot that I am talking about here is not the official WhatsApp bot but rather than to use the NodeJS app to create a bot from the WhatsApp Web feature.

The summary activity could be the total number of messages sent by end of the day, the people who are participate (send messages) most. You also can send a daily quote picture every morning or evening. Anything you can think of to break the silent.

Let’s get the required hardware and software components to get started.

Hardware Components

I am using a Raspberry Pi 4 with memory 4 GB and 32 GB SD card to host the NodeJS app and Xiaomi Android TV Box. I think you can use Raspberry Pi 3 with less memory.

Since both the Raspberry Pi and Android box run all the time, I expect the system will run 24/7 without any issue. Unlike if you are using an Android phone, you need to make sure the phone will not go to the “Doze” mode when the phone is unused for long periods of time.

Software Components

For Raspberry Pi’ OS, I am using the default from the https://www.raspberrypi.org/software/. Just follow the instruction how to install it on your Raspberry Pi. It should be quite straight forward.

We need a WhatsApp client which we need to install on the Xiaomi box. I am using WhatsApp Business 2.20.205.13 (arm-v7a) from Apkmirror.com.

Download the APK and install into the Xiaomi box. You also need a dedicated number for WhatsApp and add this number to a WhatsApp group that you have created. I don’t have any issue or difficulty to install and run the app. It went smoothly with that version.

After the basic components have been installed and configured properly, now we need to install the required libraries to run the NodeJS app.

Install Libraries and Configure the App

Install the NodeJS app with the following steps:

  • Figure out which version of the ARM architecture your Raspberry Pi has, uname -a.
cd node-v14.15.1-linux-arm7l
rm CHANGELOG.md
rm LICENSE
rm README.md
  • Install sudo cp -R * /usr/local/

Once you installed, we verify that the NPM is at least version 3+.

  • Check version, npm --version.
  • If it is less than 3, upgrade it sudo npm install npm -g
  • Also check the node version, node --version.

And now install the whatsapp-web.js from https://github.com/pedroslopez/whatsapp-web.js/

npm i whatsapp-web.js

Please note that Node v10.18.1+ is required due to Puppeteer.

Once it is installed, find this file /util/Constant.js and update the puppeteer parameter with the following:

Next is to create an account in PubNub. We need this service to send a WhatsApp message at a specific time (using Linux cronjob). For example, if you want this app to send a morning or evening quote. You can use other approach like MQTT (RabbitMQ, Kafka, etc.) that you need to install and configure in Raspberry Pi, but I found with this PubNub, I don’t need to maintain and configure so many libraries. I am just using PubNub service directly and is fast and reliable. So is up to you if you want to use other method.

Once you registered with PubNub, create an app and get the Public Key and Subscribe Key, we will use it later in our app.

Also install the additional libraries:

npm i pubnub fs qrcode-terminal

WhatsApp Web

After we installed the required libraries, let’s activate the WhatsApp Web and scan the QR code. You probably don’t want to have to scan a QR code every time you restart your bot. This can be done by saving the session info you get from the authenticated event and later passing it as an option while instantiating the client.

This is my code implementation:

Add the number into the WhatsApp group and run the above code and send message to that group. You will get the group Id information. Take note of that, we will use it later in Main app.

Main App

And here is the main app, it needs input WhatsApp group ID and session.json that you get from the above code earlier, the PubNub Publish Key and Subscribe Key.

We need to run the Main App in the background. Install PM2

npm install -g pm2

And start the app.

pm2 start sendwa.js

We can check the status with this command:

pm2 list

And further details with this command:

pm2 show sendmsg

We will add the PubNub listener to check to the incoming command from the scheduled cronjob which we will go through later. It listens to the channel “wa” and command “create”.

Send Scheduled Message

We will use the cronjob in Raspberry Pi to send the summary by end of the day — for example at 9pm everyday.

Create a shell script run.sh to execute the sendadhocmsg.js.

/usr/local/bin/node /home/pi/sendadhocmsg.js

And add it in the cron job.

We will send the PubNub command “create” in channel “wa” to trigger the Main app which will send the message to the group.

That’s all about it. I hope with this simple approach, you can create more fun and break the silent in your group chat. Happy coding and stay safe !!

--

--