Automate WhatsApp using Python

Search for a command to run...

Hello, I am messaging developers such as yourself, who has previously created Hashnode articles covering WhatsApp. I have an opportunity for you, to work with education researchers from the University of Massachusetts Amherst. We are creating a WhatsApp call-to-action responses for users' input, and we would like to have you as a consultant on the project. If interested, DM me. Thanks.
well this is interesting! but what if we had to send multiple messages??
Hello I have question in pywhatkit .
I am working on a project that will send one message to everyone. I got success in text but not attachment. Pls help I am using pywhatkit actually it is app. Now I want to interegate how to send attachment in it that will send to bulk sender.
How did you make those screenshots with the orange background? It looks sweet!
Thankyou!
Great!
The series content will mostly cover Technical Python tutorials and my recent learnings and experience in Python.
Hello world! In this Blog article, we will learn how to Turn any image to an ASCII art. We will see the implementation in Python. Check out the Repository for Ultimate Resource in python. Drop a star if you find it useful! Got anything to add? Open a...
All you need to know about Hacktoberfest 2021

Hello reader! Well, Hacktoberfest is something, you are gonna hear a lot about in the coming month. You can refer to my YouTube video Tutorial to see a working tutorial for better understanding and a step-by-step guide of the same. https://www.yo...

Hello reader! In this Blog post, I will share some useful code snippets and functions in Python. Give it a read. Let's get started! 1. Memory The method getsizeof can be used to retrieve the size of any object. Here's an example of the same. import...

Hello reader! Whenever a client sends a request to the server, the response always contains a status code. You might not see it always but it's returned at every client-server interaction. Well, even if you are not a programmer, you would still know...

Hello reader! Microsoft subsidiary GitHub launched Copilot to power pair programming with AI. In this blog post, I will share all you need to know about it. You can refer to my YouTube video Tutorial to see a working tutorial for better understandin...

Hello world!
In this Blog article, we will learn how to Automate WhatsApp. We will make use of web.whatsapp.com webpage to automate messages and we will see the implementation in Python.
Check out the Repository for Ultimate Resource in python. Drop a star if you find it useful! Got anything to add? Open a PR on the same!
You can refer to my YouTube video Tutorial to see a working tutorial for better Understanding and a step by step Guide of the same.
1. What is WhatsApp?
3. Basics of pywhatkit Module
4. Automate WhatsApp using Python
Let's get started!
I do not think WhatsApp needs an introduction but for those who do now know, WhatsApp is a free, multiplatform messaging app that lets you make video and voice calls, send text messages, and more — all with just a Wi-Fi connection.
If you wish to know more about it, you can refer to WhatsApp Wikipedia Page.
PyWhatKit is a Python library with various helpful features. It is an easy to use library which does not requires you to do some additional setup.
This module has lots of other cool features as well. Feel free and go ahead to explore them or if you wish I can write an article about them.
If you wish to know more about it, you can refer to pywhatkit Module Documentation.
getpass() prompts the user for a password without echoing. The getpass module provides a secure way to handle the password prompts where programs interact with the users via the terminal.
Now that you are familiar with WhatsApp and have acquired basic knowledge of pywhatkit and getpass module, we can move forward to the coding section.
You can find all the code at my GitHub Repository. Drop a star if you find it useful.

In order to access the Python library, you need to install it into your Python environment
pip install pywhatkit
Now, we need to import the package in our python script. Use the following command to do so.
import pywhatkit as kt
Now that we have imported the library using the command import pywhatkit as kt, let's proceed and automate whatsapp.
Before we move forward make sure you have an active session or previously used web.whatsapp.com webpage in your browser.

We will make use of sendwhatmsg method for the same. Let's understand the parameters to be used:
phone_num: A mandatory parameter
message: A mandatory parameter.
default value = 20 i.e. post 20 Seconds the message will be sent after opening the webdefault value = True i.e. will print the remaining time if set to true.Let's display a welcome message and let's capture the target phone number here.
print("Let's Automate Whatsapp!")
p_num = 'the taget phone number goes here!'
#or you can use getpass module to capture cell num
import getpass as gp
p_num = gp.getpass(prompt='Phoneumber: ', stream=None)
Let's capture the message. I am storing it in msg.
msg = "I love Python"
Finally, let's call sendwhatmsg method.
kt.sendwhatmsg(p_num, msg, 10, 25)
NOTE: This module follows the 24 hrs time format.
OUTPUT:
In 360 seconds web.whatsapp.com will open and after 60 seconds message will be delivered.
Also, you should try and provide atleast 4-5 minutes future time from the current time when running the script otherwise if you set the time 1-2 minute prior current time, then the module might give error.
Post successful run, the WhatsApp web will open and the message will be sent to the targeted mobile number. You can use this script to automate WhatsApp to send Birthday or Anniversary greetings to your friends and family, send daily morning message to your parents or use it for other business idea. You can send bulk messages or you can easily create a list of phone number and message on which you can add a ‘For loop’.
Now that you have understood it all, you can write the same in 2 lines of code.

With these steps, we have successfully Automate WhatsApp using python. That's it!
Simple, isn't it? Hope this tutorial has helped. I would strongly recommend you to Check out the YouTube video of the same and don't forget to subscribe my Channel.
You can play around with the pywhatkit library and even explore more features.
You can find all the code at my GitHub Repository. Drop a star if you find it useful.
Thank you for reading, I would love to connect with you at Twitter | LinkedIn.
Do share your valuable suggestions, I appreciate your honest feedback!
You should definitely check out my other Blogs:
See you in my next Blog article, Take care!