So, this Whatsapp just irritates my dad.
Starting with my dad who is a business man and who gives loan to few people. Now, for asking them to pay EMI, he does this long process:
Save PhoneNumber -> Open Whatsapp -> Check if phone Number exist on Whatsapp -> Open Number -> Paste the already copied message -> Click send button.
Total time wasted for each message â approx 40â50 seconds.
Now, there exist a WhatsApp API which made me think if this whole messaging could be automated???
Lets jump to the chase:
This is the exact link which can be used to send number to anyone in the world if he/she exists on whatsapp:
https://wa.me/<number>?text=<text message>
Yehhh, I just found a way to automate, I will just loop up the link with a new number each time.
Now comes a burst of problems doing thisâŠ
- I had to open this link in google using Python.
- wa.me blocks you after certain usages. Atleast for me in my browser it stopped working after messaging like 50â70 people.
- Even if that many people is fine, it has two pages before the whatsapp opens, where some buttons need to be clicked in order to proceed further. Surprise is one of the button doesnât get clicked by selenium.
- Adding the message in the link itself and messaging 100s of people would make WhatsApp suspicious of spam and that would result in blocking on phone Number. And believe me it does does ban the phone numbers, my friends got banned while I was experimenting.
- Since I was using WhatsApp Web, it should not ask for scanning QR code for each number.
So, these challenges had to be sorted out before launching this script.
Let us solve the problems now one by one, one by oneâŠ
- Opening google could be solved by doing two tasks: Downloading google driver them adding selenium library in the script.
- wa.me is of no use, I just took off the exact WhatsApp web link which loads when we open a new number which looks something like this:Â https://web.whatsapp.com/send?phone=<number>
- Since, I just shifted from wa.me, the problem of clicking the button solved.
- Now, if we add the message in the link it self, WhatsApp will identify us, hence I used selenium to enter the text in the message box. Only thing I had to do is find the X-Path of the text box and that is:Â â//*[@id=âmainâ]/footer/div[1]/div[2]/div/div[2]â
- So, now I am just able to pass the keys to this text box like we do in other forms if you have ever used selenium. The code snippet looks like this:
- Images canât be sent.
- New lines could not be added using the link I am using above. Each time a new line â\nâ is used in the message, it just makes it two messages.
- My dad even after 100 tries of explaining him how to run the code, he still canâtđȘđȘđȘ.
driver.get("https://web.whatsapp.com/send?phone="+str(i)")
input_box = driver.find_element_by_xpath('//[@id="main"]/footer/div[1]/div[2]/div/div[2]')
for j in messages:
input_box.send_keys(j)
Ok, now I have successfully entered the message in the text box, but clicking the button using selenium wasnât happening, atleast I failed to do so. If any of the readers are able to, just comment below.
Hence, I used a simple technique which is clicking enter after the message is entered in the text box and the modified code looked something like this:
Yehhhh, now the message is sent successfully to the number specified. The only thing now left to do is loop withing the list of Phone Numbers and I think showing how to write a for loop will be waste of time and space.
Lucky us, once we scan the QR code, when the next link opens in a new window it wonât ask for it again. Hopefully WhatsApp doesnât fix that.
I think this is it, messaging bulk on whatsapp just became easier and hence, I thought of releasing a library and it is called Whatsall and the full code can be seen here.
I think now anyone can use this to send messages in bulk. Huhh problem solved, butâŠ
Again a list of problems come up:
And all I wanted to do was to make my dadâs work easier but it still remains the same. Hence, I decided to make an app
This app should be in such a way that it solves the above three problems. And well well well, it just addressed all the above problems and the code of the app is another timeâs story. Until then just use my app.
Link for the app:Â https://play.google.com/store/apps/details?id=com.divesh.whatsall.automessenger_free
Please copy the link - most likely the link get altered here...
I guess thatâs it for this particular blog. If you liked it, give it a thumbs up and in the next blog we will see how to make the whatsapp automation app.
Thank youâŠ