diff --git a/System-Automation-Scripts/WhatsApp-message-automation/README.md b/System-Automation-Scripts/WhatsApp-message-automation/README.md new file mode 100644 index 00000000..a845de07 --- /dev/null +++ b/System-Automation-Scripts/WhatsApp-message-automation/README.md @@ -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) diff --git a/System-Automation-Scripts/WhatsApp-message-automation/abcd.PNG b/System-Automation-Scripts/WhatsApp-message-automation/abcd.PNG new file mode 100755 index 00000000..4df6ffe5 Binary files /dev/null and b/System-Automation-Scripts/WhatsApp-message-automation/abcd.PNG differ diff --git a/System-Automation-Scripts/WhatsApp-message-automation/automate-messages.py b/System-Automation-Scripts/WhatsApp-message-automation/automate-messages.py new file mode 100755 index 00000000..8313889c --- /dev/null +++ b/System-Automation-Scripts/WhatsApp-message-automation/automate-messages.py @@ -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() diff --git a/System-Automation-Scripts/WhatsApp-message-automation/confirm.png b/System-Automation-Scripts/WhatsApp-message-automation/confirm.png new file mode 100755 index 00000000..23ae660b Binary files /dev/null and b/System-Automation-Scripts/WhatsApp-message-automation/confirm.png differ diff --git a/System-Automation-Scripts/WhatsApp-message-automation/frequent.PNG b/System-Automation-Scripts/WhatsApp-message-automation/frequent.PNG new file mode 100755 index 00000000..f349bd8a Binary files /dev/null and b/System-Automation-Scripts/WhatsApp-message-automation/frequent.PNG differ diff --git a/System-Automation-Scripts/WhatsApp-message-automation/qrcode.PNG b/System-Automation-Scripts/WhatsApp-message-automation/qrcode.PNG new file mode 100755 index 00000000..b3e42727 Binary files /dev/null and b/System-Automation-Scripts/WhatsApp-message-automation/qrcode.PNG differ diff --git a/System-Automation-Scripts/WhatsApp-message-automation/script.PNG b/System-Automation-Scripts/WhatsApp-message-automation/script.PNG new file mode 100755 index 00000000..e8f26619 Binary files /dev/null and b/System-Automation-Scripts/WhatsApp-message-automation/script.PNG differ diff --git a/System-Automation-Scripts/WhatsApp-message-automation/search.PNG b/System-Automation-Scripts/WhatsApp-message-automation/search.PNG new file mode 100755 index 00000000..8d2c2d2c Binary files /dev/null and b/System-Automation-Scripts/WhatsApp-message-automation/search.PNG differ diff --git a/System-Automation-Scripts/automate-whatsapp.py b/System-Automation-Scripts/automate-whatsapp.py new file mode 100755 index 00000000..8313889c --- /dev/null +++ b/System-Automation-Scripts/automate-whatsapp.py @@ -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()