Project Title
Automate WhatsApp for sending messages to any particular person or group in WhatsApp.
Getting Started
It's not totally automated as the QR scan should be scanned manually. Everything is working fine with code as you soon run the code chrome will pop up and open WhatsApp web and scan the QR code from your phone. then type the contact name in the console box and the message you want to send and the number of times you wanna send.
prerequisites
Selenium Library
Chrome driver
installing
install selenium
python3 -m pip install selenium
Download and install chromedriver
download chrome driver here
code :
import web driver from selenium
from selenium import webdriver
creating an obect to open chrome and set the path inside () of chrome driver
driver = webdriver.Chrome('/Users/rauna/Downloads/chromedriver')
passing the WhatsApp url
driver.get('https://web.whatsapp.com/')
getting data from user
name = input('enter the name of user')
msg = input('enter your message')
count = int(input("enter the count"))
input('enter after scanning QR code')
saving the defined contact name from your WhatsApp chat in user variable
user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(name))
user.click()
name of span class of contatct
msg_box = driver.find_element_by_class_name('_13mgZ')
for i in range(count):
msg_box.send_keys(msg)
button = driver.find_element_by_class_name('_3M-N-')
button.click()
snippet from above code:
user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(name))
you can see why [@title = "{}"] because user providing the name of the contact person you wanna send the message screenshot
msg_box = driver.find_element_by_class_name('_13mgZ')
('_13mgZ') is the class name of typing box you can see the image below
button = driver.find_element_by_class_name('_3M-N-')
('_3M-N-') is the class name of send button as you can see in image below
check out GitHub for a better understanding link is here:
https://github.com/cyber-hoax/automatewhatsapp
Top comments (9)
This thing bothers me a lot too. I have good news and bad news for you.
The good news is, twillo has an API for WhatsApp.
The bad news is, you need to pay for this service.
So, I didn't bother messing around with the API. 😓
yeah i recently post a blog with twilio too it would pleasure if you can look into it :)
here's the link dev.to/cyberhoax/send-and-receive-...
I can feel that bro!
pypi.org/project/whatsappchatbot/ have tried to create a chatbot .. check it out if you're interested
sure i will :)
now the official WhatsApp Business API is avaiable.
still pricey as hell and too much bureaucratic
Couldn't agree more 😅
totally agree !