Hi peeps! Today’s blog is going to be very exciting, and you will learn how to Automate WhatsApp Messages with python. With just two (2) lines of code, we will do this. This blog is going to be very interesting, and you will learn a lot.
For automation, we are considering to use Python because its syntax is super easy to learn. Python is a high-level programming language, and you can do almost everything by using this. Another factor to choose python is that it is beginners friendly. Moreover, you need not to be a pro to do exciting things with python.
Read More: How to level Up Python?
Why use Automate WhatsApp Messages?
Automation is necessary so that we can utilize our precious time more efficiently. Perhaps you want a WhatsApp message to deliver at a particular time, but you could be busy or even at sleep at that time. Or you may want to know how you can automate WhatsApp messages just for the fun of it.
How to Automate WhatsApp Messages With Python
When you write your code, you may encounter many errors but do not worry. I will list below how you can resolve potential bugs. If the bugs you see are not mentioned here, search for a solution on Google. Bugs and errors are part of programming.
Now let’s dive in
- Install Latest Python Version if you don’t have it already.
- Open any code editor such as Visual studio / PyCharm and create a new Project file with the name WhatsApp.py or whatever you like.
- Copy the Pywhatkit installation link and go from here. Or you can also do it by just remembering this code “pip install pywhatkit”.
- Back in a code editor and am using Visual Studio and you can use any of your choices.
- Open a terminal and paste your paste the pywhatkit installation link and press enter. It will take some minutes before pywhatkit will install.
- Now write the following code in your Visual Code Studio IDE.
import pywhatkitpywhatkit.sendwhatmsg(‘+923205714104’, ‘Happy Birthday Jani…’,9, 7)
Note: Inside the bracket, write the phone number with the international code (+…) of the country you want to send the automated message. Then, write your message. Now write the message delivery time. The time here uses the 24hours clock. So instead of writing 12, 00 for 12 pm, you write 24, 00. Also, note the quotation marks.
- Run the code. You will get this type of message once the code runs successfully:
In 37804 Seconds WhatsApp will open and after 15 Seconds Message will be Delivered!
At the time you’d set, WhatsApp will automatically open in the default browser. The message you wrote will then appear inside the text box and send automatically after 15 seconds. If your internet connection is slow, your message will not send. It will remain inside a text box.
Errors You May Encounter
You may see the error messages I wrote below while trying to create WhatsApp messages automatically. I have included how you can resolve each error.
While installing Pywhatkit, you may see this error message:
Sometimes you may encounter flask is not present to direct your request.
Error Number 1
Flask is not present and you can’t process the request
Open terminal and type the following code and then press enter
pip install flask
Error Number 2
Headers library files were not found in the compression, the dependence required for pillow coverage from a source.
Upgrade the pipe and pillow. Generate the codes below separately:
python -m pip install - upgrade pip
python -m pip install –upgrade Pillow (this will also install pillow if not already installed)
Error Number 3
- If the phone number you want to send a message to doesn’t have a country code. You will get this error:
pywhatkit.mainfunctions.CountryCodeException: Country code missing from phone no
Include the country code for every phone number. For example, +92, +44, +91, +88.
You can automate WhatsApp messages with just two lines of python code. Use Visual Studio or any other IDE you are comfortable with. Install Pywhatkit library in your IDE. Import the Pywhatkit. Write your number including the message and set the time you want the message sent. You can also explore many more features in this library. So keep learning and keep exploring!