Python Bot: WA Bot

Before WhatsApp official API I've developed a Python WhatsApp Bot for automated chat who attended over a million messages.

Before WhatsApp official API was available I’ve developed a Python WhatsApp Bot + Exposed API for an automated chat who attended over a million messages of dozens of thousands costumers. It even become a new Startup inside our company.

Bot Key Features

  • The Core was written on Python with Selenium
  • Chromium Headless and Ubuntu Server
  • QR Code Reading and Session Management
  • Human Behavior Simulation
  • Search Contacts, Open Contacts
  • Send Text Message, Image and PDF Attachments
  • Auto-cleaning Option
  • Shared Session Information via AWS EFS for Scalability
  • API working in real time, exposed with Flask

Special Feature

Two very special features of the Bot was Human Behavior Simulation and Shared Session Management.

For Human Behavior Simulation we used minimal interference with JavaScript and used the most of the UI availiable; so, for instance, instead of opening a profile to send a text we made the bot search on search field, with time spaced key strokes, even simulating some human common mistakes, searched the costumer, clicked the photo as a normal user, typed the text letter by letter on the text field and so on… with every aspect of behavior controlled by a very broad timing configuration. With that kind of approach we avoided to be blocked as bot for more than two years.

Chromium on Selenium has some tricks around Session Management. but that was necessary because we wanted freedom to setup as many EC2 machines as we wanted. Using AWS EFS shared between the EC2 for Session Management we could scaleup from one to ten machines sending requests at the same time, without losing the stored WhatsApp Read QR Code. It made the service efficient and extremely stable in comparison with market alternatives.