DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for How to send WhatsApp messages for free and reliably with only 3 lines of code? Python
Aahnik Daw
Aahnik Daw

Posted on • Updated on

How to send WhatsApp messages for free and reliably with only 3 lines of code? Python

Wondering how to send WhatsApp messages using Python using only 3 lines of code? You have come to the right place!

You can do so by using a simple tool wappdriver.

Look!

Installation?

Its hassle-free.

Just pip install wappdriver

Why wappdriver?

  • fast and reliable
  • WhatsApp's website structure may change, the selectors can be updated over the internet dynamically, without changing code.
  • chrome Driver path setting is hassle-free
  • actively maintained
  • fast support, if you need help
  • send messages with bold, italics, or strikethrough
  • send emojis smiley
  • send images, videos, and gifs
  • send documents and files
  • can set a custom timeout, so that runs properly on old computers or with a slow internet connection
  • more features to be added

Know more

Requirements

Just Chrome Browser and Chrome Driver.

Documentation

Just go to https://aahnik.github.io/wappdriver. You will get all details.

Note

This code is in no way affiliated with, authorized, maintained, sponsored, or endorsed by WhatsApp or any of its affiliates or subsidiaries. This is an independent and unofficial software.

This project is distributed under the MIT License.

Questions or Suggestions?

If you have any questions, or if you want to discuss something with the community, please come to the wappdriver Discussion Forum.

Top comments (20)

Collapse
sankalpsriva profile image
sankalpsriva • Edited on

I added the wrong path how and then keep getting the error of "Chromedriver not loaded"
How do I change the path so it can work again?
EDIT: I found the GitHub discussion of changing your set PATH but now I am getting an error about unicode truncation after I made it into a raw string I get a permisson error.

Collapse
aahnik profile image
Aahnik Daw Author
Collapse
tranvytdt profile image
tranVyTDT

anyone have this error like me
Traceback (most recent call last):
File "test_whatsapp.py", line 1, in
from wappdriver import WhatsApp
File "/home/username/.local/lib/python3.8/site-packages/wappdriver/init.py", line 24, in
from .local import set_chrome_driver_path, update_selectors
File "/home/username/.local/lib/python3.8/site-packages/wappdriver/local.py", line 11, in
from verlat import latest
ImportError: cannot import name 'latest' from 'verlat' (/home/username/.local/lib/python3.8/site-packages/verlat/init.py)

Collapse
chepi_deleon profile image
JosΓ© Alfredo de LeΓ³n

I'm gettting the error: "ChromeDriver not loaded". Could you provide any help?

Collapse
aahnik profile image
Aahnik Daw Author

Please post the details in the discussion forum.

github.com/aahnik/wappdriver/discu...

Please provide additional details.

have you installed chrome driver ? the correct matching verison ?
have you entered the correct path when prompted ?

Collapse
anuradha profile image
Anuradha Fernando

Hi JosΓ©,
Set the ChromeDriver path when you call the webdriver.Chrome.
eg:
browser = webdriver.Chrome('/home/user/Python/ChromeDriver/chromedriver')
browser.get('twitter.com')

Collapse
ag422 profile image
Ag422

Can we also send messages to groups or only to people?

Collapse
aahnik profile image
Aahnik Daw Author

you can send messages to groups also. just put the name of group, in the to parameter

Collapse
aahnik profile image
Aahnik Daw Author • Edited on

You can send messages to Groups also. Just use the name of the group in the recipient's name.

Collapse
lcheuk profile image
lcheuk

It doesn't support if the name contains space.

Collapse
aahnik profile image
Aahnik Daw Author

can you show a screen recording ? or terminal output ?
it is expected to work

Collapse
daksh777 profile image
Daksh P. Jain

Do we need to be logged in WhatsApp web for it to work? I didn't quite understand how it sends the message. Also, what about contacts saved as numbers only (no name but only phone number)?

Collapse
aahnik profile image
Aahnik Daw Author • Edited on

Hi ! Thanks for asking. When you run the code shown, chrome will open whatsapp web. For the first time you need to scan QR code to login to whatsapp.

You can send only to saved contacts.

Otherwise whatsapp may block you for spamming.

For contacts saved only as phone number, it will work. Just put the phone number instead of name , in the to parameter of the send method

Collapse
daksh777 profile image
Daksh P. Jain

Amazing! Do we need to include the full number (with country code) like +1123456789 or only 123456789 will work?

Thread Thread
aahnik profile image
Aahnik Daw Author

exactly same as saved. Number must be saved

Collapse
pooriabt profile image
pooriabt

hii aahnik
i check your githubs link (full documentation), but it links to same page, im looking for a way to send some pdf files to some different people.

Collapse
amaboula profile image
amaboula

Hello I have this error

cannot import name 'WhatsApp' from partially initialized module 'wappdriver' (most likely due to a circular import)

Collapse
aahnik profile image
Aahnik Daw Author

did you name your file wappdriver.py ? Dont do that. Learn more about imports.

And by the way, wappdriver is not more maintained. See the github repo for notice.

Collapse
jessmorais profile image
jessmorais

Hi, Do I have to scan my QR code every time that I want to send a message?
Why do you use chrome driver?
Thank you :)

Collapse
aahnik profile image
Aahnik Daw Author • Edited on

you have to scan the QR code only for the first time. The session will be saved on your computer.

Chrome driver is used to take actions such as clicking and typing in google chrome.

For asking questions and discussing, you can come to the discussion forum of wappdriver

github.com/aahnik/wappdriver/discu...

Some comments have been hidden by the post's author - find out more

🌚 Life is too short to browse without dark mode