Send WhatsApp Message Using Python - Only 2 Line of Code
We can automate WhatsApp and send WhatsApp message using python by running a small python script. Today, we will learn the simplest way of doing so using the pywhatkit module which utilizes the web.whatsapp.com webpage to automate message sending to any number on WhatsApp.
Now let’s install/setup pywhatkit module and write the code to send WhatsApp message automatically.
Install pywhatkit module
pip install pywhatkit
This command will download the pywhatkit module. It will take some time as it will download some related modules too.
Let’s send message
To use this python module to send messages automatically on WhatsApp at a set time, we need a chrome browser and you must have your WhatsApp logged into web.whatsapp.com website.
Code
import pywhatkit as kit
kit.sendwhatmsg("+919*********", "I love python!", 18, 2)
In the above code, we have specified the mobile number on which we want to send the message, then the message, and then the time at which the message has to be sent. This module follows the 24 hrs time format, hence the time 18:2 is 06:2 PM.
Output
In 702 seconds web.whatsapp.com will open and after 60 seconds message will be delivered
Also, you should provide atleast 4-5 minutes future time from the current time while running the script, because if you will set the time 1-2 minute from current time, then the module will give error.
Hope you enjoyed this code. Share it with your friends and must try this pythonic way to send WhatsApp message.
You may also like,