Send a scheduled message on Whatsapp with python

Let’s walk through how to schedule a message on WhatsApp with two lines of python. This is useful if you want to wish that special one ❤️ a happy birthday 🎁 or anniversary at a precise time, even while you’re away.

To get started, we need a few things:

  1. Python should be installed on your system. RealPython has an amazing guide for this.
  2. Any IDE of your choice.
  3. A browser with Whatsapp web signed in.

Now let’s get right into it. first, we install a python package called ” PyWhatkit ” by running this command in the IDE terminal or your system terminal pip install pywhatkit.

What is PyWhatKit

This is a Python library for sending scheduled WhatsApp messages, it comes with a bunch of features such as group messaging, shutting down your pc and a whole lot more. You can check out their Github page for more info.

For the purpose of this article, we would focus just on the WhatsApp messaging feature.

Once it’s done installing, create a new python file, give it whatever name you want & save it. (I saved mine as whatsappsender.py).

Now to the juicy part, the two-line wonder.

import pywhatkit

pywhatkit.sendwhatmsg("+234123456789", "I love you ❤️", 00,3 )

Walking through the code

Firstly, we import the package then use the “sendwhatmsg” function which takes in a few arguments;

  • The recipient’s number
  • The desired message
  • Time to send the message, the first integer is the hour, the second is the minute. In my case, it would send at exactly three minutes past midnight.

Running this file would open up WhatsApp web and send the message at the specified time.

Bonus

A bonus is having the script shutdown once it’s done, only available to windows & Linux users. To do this include this last line of code.

pywhatkit.shutdown(time=1)

The default time is twenty minutes but you could set it based on your preference.

Leave a Reply

Your email address will not be published.