Welcome back to another brand new post of Sai Ansul's Blog.
Today we are gonna find out How to schedule WhatsApp message using just 2 lines of code , yes you heard it right just 2 lines of code.
So lets start,
We will divide the process in 3 parts
- Creating a project
- Installing pywhatkit
- 2 lines of code
First of all you need to a python interpreter for this project in your device.
Then you need to go to your Browser and search for pywhatkit.
Then we again need to go to the project created.
And open Terminal and paste this.
Now lets proceed towards the part 3 that is to code
Now we need write in the first line as
Then this part is divided into 2 parts
- Part 1: Message to a personal chat
- Part 2: Message to a group
So first lets learn how to send a automated message to a personal chat
Now to need to type
Inside the bracket you need to pass all the parameters like, phone number with country code, message and the timing in the format of
Check the sample code out
pywhatkit.sendwhatmsg( '+911234567890', 'HI IM SAI ANSUL',15, 25)
I have written the country code as
+91 and then the phone number of the receiver, and the write your message with in
'MESSAGE',, then select the time according to the 24 hours format where I have chosen at 15hours and 25 minutes.
and that it ,and press on the execution button and you'll see the message like this.
And now you don't have to do anything just keep the browser open and it will automatically open
WhatsApp Web before 20 seconds of the time given, and it will keep the message typed as soon as the time is reached it will send the message.
So now let us know how to send a automated WhatsApp message to a group.
The process is very similar and simple to the previous one.
Just what you have to do is rather putting the number of the recipient, you need to put the group id. and change the command to
You can find the group id by going into the group info and then click on invite via link and then you need to put the prefix of that. The suffix of the link is the group id code.
import pywhatkit pywhatkit.sendwhatmsg_to_group('CBURAqngjD54UzFHg6CGi7','HELLO',16 ,47 )
The parameters are:
phone_num (required) - Phone number of target with country code
message (required) - Message that you want to sendwhatmsg
time_hour (required) - Hours at which you want to send message in 24 hour format
time_min (required) - Minutes at which you want to send message
wait_time (optional, val=20) - Seconds after which the message will be sent after opening the web
print_waitTime (optional, val=True) - Will print the remaining time if set to true
Some common errors:
CountryCodeException - Check if the phone number passed into the parameter has country code
Message not getting delivered - Check internet speed and increase wait_time to 30 or above CallTimeException - The web takes some time to load so some delay is required, make sure the seconds left is greater than the wait_time
SyntaxError - Make sure the first two parameters are string and the rest are int
So now this was how to send a automated WhatsApp message to a personal chat or a group using just 2 lines of code.
That is it for today guys! I hope you liked the article and got to know something new.
Stay tuned for some more interesting blogs coming up soon.
If you like my content and want to support my efforts please like👍🏻, share📲 & subscribe to the newsletter to be get notified whenever I post a new blog.