cft

How to send custom WhatsApp messages to your contacts at once in bulk ?

I wanted to send custom wishes to everyone in my contacts with an image, just like the one mentioned below, and writing this message for around 400+ contacts on my phone is not humane. Then I thought to use some pre-existing python libraries to perform this task.


user

Sai ankit

9 months ago | 1 min read

I wanted to send custom wishes to everyone in my contacts with an image, just like the one mentioned below, and writing this message for around 400+ contacts on my phone is not humane. Then I thought to use some pre-existing python libraries to perform this task.

Step 1: Get all your contacts details as CSV

You can export contacts from your google contacts and save them as CSV. Also, do remove all the unnecessary columns from the CSV and keep only the name and phone number column in the output CSV.

Prerequisites for your system

  1. Install python3

2. Install pandas and pywhatkit
pip3 install pandas pip3 install pywhatkit

Step 2: Run this following script to clean the content ( i.e, phone number to make it acceptable for WhatsApp script )

import pandas as pd

data = pd.read_csv("final.csv")

for i, j in data.iterrows():

j["phone_number"] = "+91" + j["phone_number"].replace("-","").replace(" ","").replace("(","").replace(")","")

data.to_csv('send.csv')

This cleans different formats of phone numbers in your contact list.

Step 3 : The actual script to send WhatsApp messages

from time import sleep

import pywhatkit as pw

import pandas as pd

df = pd.read_csv("data.csv")

for i, j in df.iterrows():

print(j["phone_number"])

pw.sendwhats_image("+" + str(j["phone_number"]), "image.jpg", "Wishes " + j["name"])

sleep(3)

pw.sendwhats_image("+" + str(j["phone_number"]), "image.jpg", "Wishes " + j["name"])

This is the actual command that sends the message to each contact. Note that this script only sends images in jpg format, not any other types. The first argument is the phone number. The second argument is the image location. The third argument is the caption for the image being sent. Ensure the script and image are inside the same folder or use the image’s relative location in the second argument position.

TADA Wait for one hour to send at least 250 messages

Upvote


user
Created by

Sai ankit


people
Post

Upvote

Downvote

Comment

Bookmark

Share


Related Articles