Whatsapp makes adding bots really hard. Since it doesn't provide an API, and connecting directly to Whatsapp server results in your number getting detected quickly (thus banned), this implementation uses whatsapp web.
In order to do that we setup an emulator and send our QR image by simulating a fake webcam. This setup is complicated but guarantees that it doesn't get banned and also it can be fully automated.
- /search: gets results from Google (can also follow links from the first result page)
- /around: gets results around you from Google Maps, by providing your location previously.
- /url: Given a link it can get a screenshot of the page. If it's a video it will send the video.
- /tts: Text to speech in several languages
- /camera: Takes a picture using the server webcam and sends it.
- /video: Records a video using the server webcam, with customizable duration and fps.
- /play: plays audio files
-
Setup an Android Emulator (I used android-studio to create a Google Pixel with API 28, but other versions should work fine)
-
Install Whatsapp in the emulator and register it with a number (don't use your personal number as you can eventually get banned)
-
Install the Python libraries:
> pip install -r requirements.txt
-
Install v4l2loopback kernel module (linux required) and gst-launch-1.0.
-
Close the emulator and run
./run_emulator.sh
(you should adjust the name of the emulator) -
Run
python2 whatsappbot.py
to finally run the bot. -
The bot will put the QR on the fake webcam. Go to Whatsapp on the emulator and scan the QR in order to login into Whatsapp web.
-
The bot should be working. Next logins won't require scanning the QR again.
-
Some features require ffmpeg and espeak installed to work.
This is not very much tested and many steps can get broken, you will need to understand the code deeply in order to get it working. I built it for my personal use and some parts of the code are really dirty. But hey! it works :D (for me at least)