Education logo

How to Send Whatsapp Messages Using Pywhatkit Module?

Application of Python’s Pywhatkit’s Module for Sending Auto-generated Whatsapp Messages!

By Sneha MehtaPublished about a year ago 3 min read

Sometimes we often forget to respond or send important messages on WhatsApp. Have you ever thought of sending auto-generated messages on WhatsApp? Well, now Python’s Pywhatkit module can assist you in automating WhatsApp messages through simple code.

What is Pywhatkit Module?

Python offers various libraries with extensive features. The Pywhatkit module is a library that allows you to send WhatsApp messages individually or in groups; it utilizes the web.whatsapp.com webpage to automate WhatsApp messages to any mobile number.

Pywhatkit module has features for playing youtube videos, performing Google searches, and converting handwritten text into images.

Installation of Pywhatkit Module

The Pywhatkit module is available on PyPI, and you can install it using the pip command. There may be a delay in installation as it downloads other relevant modules.

You can install Jupyter or Jupyterlab for the development environment or use a free text editor.

How to use the Pywhatkit module?

To use the Pywhatkit library, you need a Chrome browser and a logged-in WhatsApp web account to send auto-generated messages at a set time.

Executing Pywhatkit module:-

Download the stable Chrome driver from https://chromedriver.chromium.org/.

After downloading the Chrome driver, open the driver and search for the Chrome application file for Windows. The path should appear as C:/Users/.../chromedriver.exe.

If your path is valid after calling the function pywhatkit.add_driver_path, a black window will open and close along with Chrome.

Next, scan the QR code after running the pywhatkit.load_QR code function.

Now you need to run the Python script to send automated WhatsApp messages.

Send Whatsapp Messages using Pywhatkit Module

You have to log into your WhatsApp web account before using the Pywhatkit module.

Sending Message Instantly

The pywhatkit module sends messages instantly through sendwhatmsg.instantly() function. It involves a simple code:

Code:

pywhatkit.sendwhatmsg_instantly( phone no = "< +91xxxxxxxxxx>" , message = "Hi, where are you" )

Sending Message in Future

The pywhatkit library utilizes sendmsg() function set at a specific time. Here is the simple format to send individual messages.

Syntax: pywhatkit.sendmsg ( “whatsapp number” , “Message”, time in hours, time in minutes)

Things to remember while sending the message

The WhatsApp number should be in string format, and the country code must be included before the number.

Sending messages must be in string format.

Time in hours should be in a 24-hour format.

Time in minutes should be between 00-59 integers.

You should set the time at least 2-3 minutes from the current time while running the code otherwise, the module will print an error message.

Python code:

#import pywhatkit

#using Exception Handling to avoid unexpected errors

try:

#sending message to the receiver

#using pywhatkit

pywhatkit.sendwhatmsg ("+91xxxxxxxxxx" , "Hey, how are you" , 6 , 30 )

print ( "Message sent" )

except:

#handling exception

# and printing error message

print ( "error in sending message" )

Code explanation:

At first pywhatkit module is imported.

The message is sent as “Hey, how are you” to be sent at 6:30 am.

Exception Handling function is used in case of errors and prints output as “error in sending message”.

If the code is written perfectly and executed, the module prints output as “Message sent”.

Sending Messages in Whatsapp Groups

While sending messages in groups, the group id will be the suffix part of the group link. Messages will be sent using the sendwhatmsg_to_group function. It is very similar to sending WhatsApp messages individually, but here we use a group id instead of a phone number.

pywhatkit.Sendwhatmsg_to_group ( “Group_Id” , “Message” , time in hours , time in minutes )

Summing up

We hope that you have learned how to send Whatsapp messages individually and in groups. Python’s Pywhatkit module has other features such as video sorting, researching any topic, sending images, etc. Python is one of the most popular and in-demand programming languages at present. And to become a professional in Python programming language, it becomes of utmost importance to get in-depth knowledge of all the programming terminology.

In a nutshell, to learn more about Python and its applications in various data science projects, you can enroll in a Data Science and AI master program. This program can help you to understand Python and its libraries in a more easier and systematic way.

courses

About the Creator

Enjoyed the story?
Support the Creator.

Subscribe for free to receive all their stories in your feed. You could also pledge your support or give them a one-off tip, letting them know you appreciate their work.

Subscribe For Free

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

    SMWritten by Sneha Mehta

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2024 Creatd, Inc. All Rights Reserved.