Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Script to automate sending WhatsApp messages #116

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions System-Automation-Scripts/WhatsApp-message-automation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Automate-sending-WhatsApp-messages

- This script can be used to send messages to your contacts on WhatsApp from your Command line!!

## Working ##
- The URL, https://web.whatsapp.com/ needs to be opened and initiate.

![Image](qrcode.PNG)

- On the right side there is a QR code which needs to be scanned in order to open WhatsApp over the web.

![Image](search.PNG)

- The icon circled in the image is can be used to look for contacts/groups
- The script is automated to click on the search button (circled button)

![Image](frequent.PNG)

- On clicking the button, it opens into the above image.
- Further, the name can be typed into the search bar. The ENTER key will be pressed by the script.
- The chat of the entered contact will be opened.

![Image](abcd.PNG)

- The script looks as shown below
- Messages can be sent to more than one contact,
- More than one message can be sent to the same contact

![Image](script.PNG)

![Image](confirm.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
#Import and dependencies

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys

#Constants
three = 3
twenty-five = 25
one = 1

#Here the process of automation is achieved by using the framework Selenium.
#Selenium is a portable framework for testing and automating web applications web applications

#Path to chromedriver.exe
chrome_path = r"C:\Users\giril\AppData\Local\Programs\Python\Python36-32\chromedriver.exe"

#Initiating and setting up the driver
driver = webdriver.Chrome(chrome_path)

URL = "https://web.whatsapp.com/"
driver.get(URL)

#The script is made to wait, to ensure that the page is loaded
time.sleep(twenty-five)

def send_messages():

chats = int(input("Enter the number of personal chats/groups you would want to message "))

for chat in range(chats):

#This is used to enable the user to search for the contact
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[3]/div/header/div[2]/div/span/div[2]/div').click()

name = input("Enter name to whom you want to send a message ")
time.sleep(three)

#On entering the contact, the name is entered into the search bar
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div[1]/span/div/span/div/div[1]/div/label/div/div[2]').send_keys(name)
time.sleep(three)

#The contact's chat will be opened
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div[1]/span/div/span/div/div[1]/div/label/div/div[2]').send_keys(Keys.ENTER)

#This enables the user to send more than one message to the same contact
done = one
while done:
message = input("Enter the message you want to enter ")

#The cursor is positioned and the chat box is activated
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]').send_keys(message)
time.sleep(three)

#On clicking the send button, a message is sent to the contact
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[4]/div/footer/div[1]/div[3]/button').click()

print("Would you want to send another message to the same contact ?")

done = int(input("Enter 1 to continue, 0 to stop "))

print("All messages sent successfully")

send_messages()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions System-Automation-Scripts/automate-whatsapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
#Import and dependencies

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys

#Constants
three = 3
twenty-five = 25
one = 1

#Here the process of automation is achieved by using the framework Selenium.
#Selenium is a portable framework for testing and automating web applications web applications

#Path to chromedriver.exe
chrome_path = r"C:\Users\giril\AppData\Local\Programs\Python\Python36-32\chromedriver.exe"

#Initiating and setting up the driver
driver = webdriver.Chrome(chrome_path)

URL = "https://web.whatsapp.com/"
driver.get(URL)

#The script is made to wait, to ensure that the page is loaded
time.sleep(twenty-five)

def send_messages():

chats = int(input("Enter the number of personal chats/groups you would want to message "))

for chat in range(chats):

#This is used to enable the user to search for the contact
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[3]/div/header/div[2]/div/span/div[2]/div').click()

name = input("Enter name to whom you want to send a message ")
time.sleep(three)

#On entering the contact, the name is entered into the search bar
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div[1]/span/div/span/div/div[1]/div/label/div/div[2]').send_keys(name)
time.sleep(three)

#The contact's chat will be opened
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div[1]/span/div/span/div/div[1]/div/label/div/div[2]').send_keys(Keys.ENTER)

#This enables the user to send more than one message to the same contact
done = one
while done:
message = input("Enter the message you want to enter ")

#The cursor is positioned and the chat box is activated
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]').send_keys(message)
time.sleep(three)

#On clicking the send button, a message is sent to the contact
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[4]/div/footer/div[1]/div[3]/button').click()

print("Would you want to send another message to the same contact ?")

done = int(input("Enter 1 to continue, 0 to stop "))

print("All messages sent successfully")

send_messages()