Programming is fun when you implement what you learn. While Learning python, I developed my first project in WhatsApp Auto Messenger using python.
Every one of us uses WhatsApp daily. Whatsapp is free and one of the most popular used platforms for messaging, video calls, and sharing data. It has made most of us so habituated that it has become one of the basic necessities of life.
On the other hand, Python is the most popular language for automation. So I thought let's give it a try. So I will walk you through how you can send automatic messages on WhatsApp by scheduling it beforehand in auto messenger using python programming.
So Let’s Get Started.
To start, I'm going to create a new python file and name it Whats.py (The extension for python files are .py)
To automate a python script to send WhatsApp Messages we have to import pywhatkit library.
What is pywhatkit Library?
Pywhatkit is a python library used for sending messages on WhatsApp Group or Contact. It has many more cool features like Converting an Image to ASCII Art, Sending Mails with HTML Code, etc. You can read more about it here at Pywhatkit Documentation.
To install this library. Type this on your terminal
pip install pywhatkit
2. Program:-
import pywhatkit
phone_no = input("Enter receiver(recipient) phone number :")
message = input("Enter message you want to send :")
# print("Schedule time below when to send WhatsApp message to recipient:")
time_in_hrs = int(input("- At What Hour :"))
time_in__min = int(input("- At What Minutes :"))
pywhatkit.sendwhatmsg(phone_no, message, time_in_hrs, time_in__min)
Let's dive in step by step on the code.
First import pywhatkit to automate the WhatsApp messages.
After that we give value to take the input from the user :
➢ phone no = input("Enter Receiver(recipient) Phone Number ")
➢ message = input("Enter Message you want to send :")
Then print the statement and gives a value to get the output.
➢ print("Enter Schedule Time to send WhatsApp message to the recipient:")
➢ time_in_hrs = int(input("- At What Hour :"))
➢ time_in_min = int(input("- At What Minutes :"))
After that, we use pywhatkit.sendwhatmsg to send the automated message to the recipient.
➢ pywhatkit.sendwhatmsg(phoneno, message, Time_hrs, Time_min)
At last the output of the program:
Enter Receiver(recipient) Phone Number: "+91931xxxxxxxxx"
Enter the Message You want to send:
"Hello, Good Morning"
Enter Schedule Time to send WhatsApp message to the recipient
At What Hour: 10
At What Minutes: 22
In a few Seconds, WhatsApp will open and after 15 Seconds Message will be Delivered!
Exit program.
How it works
1) First login to your WhatsApp web version by scanning the QR Code.
2) After that run the program on the console. by just providing the string format (receiver(recipient)
3) Phone number with country code, message you want to send to the receiver, schedule time in 24hrs format).
4) Then at the scheduled time, it opens on WhatsApp web on your default browser and sends your message to the receiver's phone number.
6. Summary :
Because of this Whatsapp automation top python project series project, we understand that we can set some particular time, and then we can easily automate Whatsapp to send messages to someone at a scheduled time.
With these simple steps, we can successfully send Automated WhatsApp messages using python. That’s it!
Simple, isn’t it? I hope you have found this useful. To learn more about python, data science projects follow edgrow blogs.
You can play around with the pywhatkit library and even explore more features.
Thank you for reading, We would love to connect with you on Twitter | LinkedIn.
Nikita is a passionate programmer and aspiring Data scientist. She is pursuing her Master's (MCA) and is an intern at Edgrow , where she is building some exciting python projects with source code.