Skip to content

A personal WhatsApp assistant bot that will help you search anything on the web (Google, Images, Google Maps)

License

Notifications You must be signed in to change notification settings

jctissier/whatsapp-assistant-bot

Repository files navigation

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

  • Search Google
  • Search Google Images
  • Directions from Google Maps
    • User can set {origin}, {destination} and {travelmode}

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

  • Bot can poll 1 conversation
  • Bot can poll multiple assigned conversations
  • Search Google
  • Search Google Images
  • Search Google Maps
  • Google Maps directions from user's location

Down the road

  • Remotely access the QR code
  • Image to text analysis w/ Pytesseract
  • Flask server running headless Chrome

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

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

  2. 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"

  • Scan your QR Code QR Code
  • Select a chat and start sending commands

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.

  • In the function chat_history(), set the first line of the function to "message-out"
    • This allows the bot to only scan for messages sent by yourself
    • You can send commands to yourself and the bot will respond (no need for a spare account)
  • "message-in" forces to bot to scan for incoming messages from the other person

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.

  • Charge the device 24/7, have it on Wifi and download WhatsApp on it (SIM card is not needed)
  • When they ask you to verify your WhatsApp and need a number to text
    • Download one of the many apps on app store which allows you to get a temporary phone number
      • For example, I use textPlus - FREE
      • Generate a free number and use it to verify your bot account
    • For the verification, ask for a call, answer the call and set the password
    • Account should now be created, you can now message the bot to that particular number that was generated with the app

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.

About

A personal WhatsApp assistant bot that will help you search anything on the web (Google, Images, Google Maps)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages