In the previous post, we have already covered sending a automated whatsapp messages using python pywhatkit library. But using pywhatkit we can’t send Bulk messages in WhatsApp. So in this post, we will show you the best way to send Automated Messages on Whatsapp using Python, Excel & Whatsapp Web.

Why Bulk messages on whatsapp using Python?

Whatsapp is one the most popular messaging app that exists on planet earth in the 21st century and the beauty of this app is it’s free. Whatsapp also introduced automated messages sending using WhatsApp business API but for that, you need to have an approved business that is too costly and time taking.

How our Post is Different, For sending bulk Whatsapp messages ?

Well if you are reading this I would say, In this post, I will show you one of the simplest and best way of sending bulk messages in WhatsApp using python and excel. Our approach is totally different from other ways that exist on the internet as we are not using any heavy coding library and automation using selenium web drivers. We are just using 15 lines of code and one excel sheet to automate the whole stuff. I can assure you if you even don’t know ‘P’ of Python and ‘E’ of excel then also you would be able to send bulk messages in WhatsApp to your leads, friends, or customers.

Project Demo

Before starting and moving further I will suggest watching the project demo and step by step guide and further post follows the video to help you out.

Let’s Start with Setup & Configuration :

Requirements

  1. Python3
  2. Google Chrome
  3. Microsoft Excel and One Excel Sheet

Python Libraries Required

  • PyAutoGUI
    PyAutoGUI is a cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
    pip install PyAutoGUI
  • Pandas
    Panda package is required to read an Excel file into a pandas DataFrame.
    pip install pandas
  • Web Browser
    In Python, web browser module provides a high-level interface that allows displaying Web-based documents to users. The web browser module can be used to launch a browser in a platform-independent manner as shown below:
    import webbrowser
    webbrowser.open(‘http://www.python.org’)
  • Time
    Python time method sleep() suspends execution for the given number of seconds. The argument may be a floating-point number to indicate a more precise sleep time.
    time.sleep(t)

Project Schematic and Flow

Before getting deep dive into coding work let’s understand the flow process flow with step by step :

  • First We need to prepare an excel sheet which includes leads number and messages
    Bulk whatsapp message using excel
  • Now python script will import the excel sheet as a pandas data frame in form of a zipped list
import pandas as pd
data = pd.read_csv("leads.csv")
data_dict = data.to_dict('list')
leads = data_dict['LeadNumber']
messages = data_dict['Message']
  • Once leads and messages and zipped into one list, for-loop will start sending messages to each lead.
combo = zip(leads,messages)
first = True
for lead,message in combo:
  • In one for loop iteration, we are first calling the time function to sleep program for 4 seconds and then using the web.open() function. Web.open() is used for opening URLs in the browser.
time.sleep(4)
web.open("https://web.whatsapp.com/send?phone="+lead+"&text="+message)
  • Once the URL is opened in the browser then for the first time we are checking if it’s the first we are sleeping program for 6 seconds. The reason for first-time sleep is, web browser takes time to load a link for the first time as it stores values in the cache.
if first:
        time.sleep(6)
        first=False
  • Now once sleep time is over we are fetching page width and height using pyautogui size function
width,height = pg.size()
  • After fetching the size we click on the center of the screen using the pyautogui click function. This click is necessary to focus on WhatsApp web message sending section
pg.click(width/2,height/2)
  • Now our next step is to press enter using the pyautogui enter function to send a message on number
pg.press('enter')
  • After sending an automated message on Whatsapp we are again sleeping for a while and performing our last operation i.e. to close the browser tab using the pyautogui hotkey function.
 time.sleep(8)
    pg.hotkey('ctrl', 'w')

That’s all for whole 9 step detailed guide now let see the whole code together .

import pyautogui as pg
import webbrowser as web
import time
import pandas as pd
data = pd.read_csv("leads.csv")
data_dict = data.to_dict('list')
leads = data_dict['LeadNumber']
messages = data_dict['Message']
combo = zip(leads,messages)
first = True
for lead,message in combo:
    time.sleep(4)
    web.open("https://web.whatsapp.com/send?phone="+lead+"&text="+message)
    if first:
        time.sleep(6)
        first=False
    width,height = pg.size()
    pg.click(width/2,height/2)
    time.sleep(8)
    pg.press('enter')
    time.sleep(8)
    pg.hotkey('ctrl', 'w')

Now, if you Want to see the whole project structure together please fork/ clone the whole project from GitHub.

Conclusion

So at the ending of the post, we can conclude that you have learned the best and simplest way to send automated bulk messages in WhatsApp using WhatsApp web, python & excel. The best thing about our approach is, it’s not using any complex code like using any selenium web driver and web scraping etc.