WhatsApp Assistant Bot

Demo

A personal WhatsApp assistant bot that will help you search anything on the web:
script is automated with selenium, the bot will check the chat and reply on valid commands

If bot fails when you first run it, please check and update if the class attribute for Line 13 has changed:

MESSAGE_BUBBLE_CLASS_NAME = "_13mgZ"

1) Inspect the Whatsapp text bubble element
2) Extract the class attribute and update Line 13

TODOs

Features

Down the road

Step by Step Guide

I have been receiving a lot of requests about what to do when the bot starts running. Here is a step by step example:

  1. Once the bot is running, it should automatically open chrome and display the whatsapp web QR code. Once you scan it, you should be able to see a list of your conversations, choose the one you want to test with. QR Code Scan

  2. Line 293 of whatsapp_assistant_bot.py can be changed to read incoming messages (other person in conversation) vs outgoing messages (your own messages)

    text_bubbles = driver.find_elements_by_class_name("message-out")  # message-in = incoming, message-out = outgoing

    Incoming vs Outgoing

  3. Example of sending commands and the bot scanning for outgoing messages (my messages) Test outgoing

  4. Example of asking the bot to google something. Since the bot is running on your computer, chrome will be automated by selenium and you will see a chrome page open, a screenshot will be taken and attached to the chat. Test Google

What You'll Need

  1. Install Chromedriver and make sure the Setup is completed (add the path to the chromedriver executable)

Chromedriver

  1. Install Selenium from your command line Selenium
    $ pip3 install selenium

How to Run

Clone the repo

$ git clone https://github.com/jctissier/whatsapp-assistant-bot.git
$ cd whatsapp-assistant-bot
$ python3 whatsapp_assistant_bot.py

If you get an error at this stage, it's most likely due to Chromedriver not being installed properly. Repeat the first step.

Script is running properly if you see "Bot is active, scan your QR code from your phone's WhatsApp"

Valid Commands

The bot will always send back screenshots of the Chrome browser

/google {query}              # Search google text
/images {query}              # Search google images
/maps                        # Directions with Google Maps
    /origin {from where}     # Sub-menus from /maps
    /dest {to where}
    /mode {driving, walking, transit, bicycling}

How Selenium Automates the Bot

I was able to scan incoming/outgoing messages by inspecting the HTML and using selenium to access on class names and xpath Scan Messages

Testing

You can either create a bot account (as mentioned below) or you can use your own account to test it.

Flowchart for Main Features Flow Chart

How I Use It

I run the script from my home computer in Canada and I have a separate WhatsApp account running 24/7.

You can create a free WhatsApp account if you have a spare/old smartphone.

There is plenty more that can be done with this bot, but I only needed basic googling.

Comments

Author: Jean-Claude Tissier
MIT License

I created this bot for when I travel since I have unlimited WhatsApp everywhere in the world but no data plan. I needed a way to be able to find directions, search for touristy attractions and general googling necessities in a new city without having data.

Feel free to grab the code and let me know if you have questions.

PS: This bot is not meant for spamming and is only meant for personal use.