[
  {
    "path": "README.md",
    "content": "# Python Automated Bulk WhatsApp Messages\n\nIt is a python script that sends WhatsApp message automatically from WhatsApp web application with saved contact numbers. It can be configured to send advertising messages to customers. It read data from an excel sheet and send a configured message to people.\n\n## Contact me over Telegram: https://t.me/inforkgodara\n\n## Note\nThis is for saved contact numbers only if you want to send whatsapp bulk messages to unsaved or without saving the contact numbers. You may prefer another repository.\n* Repository: https://github.com/inforkgodara/whatsapp-bulk-messages-without-saving-contacts\n\n## Important\n* WhatsApp Business released API on May 2022, no longer needed this repository. You can accomplish your same requirements through WhatsApp Business APIs.\n\n## Prerequisites\n\nIn order to run the python script, your system must have the following programs/packages installed and the contact number should be saved in your phone (You can use bulk contact number saving procedure of email). There is a way without saving the contact number but has the limitation to send the attachment.\n* Python 3.8: Download it from https://www.python.org/downloads\n* Selenium Web Driver: Either you can use repo driver else you can download it https://chromedriver.chromium.org/downloads\n* Google Chrome : Download it from https://www.google.com/chrome\n* Pandas : Run in command prompt **pip install pandas**\n* Xlrd : Run in command prompt **pip install xlrd**\n* Selenium: Run in command prompt **pip install selenium** \n\n## Approach\n* User scans web QR code to log in into the WhatsApp web application.\n* The script reads a customized message from excel sheet.\n* The script reads rows one by one and searches that contact number in the web search box if the contact number found on WhatsApp then it will send a configured message otherwise It reads next row. \n* Loop execute until and unless all rows complete.\n\nNote: If you wish to send an image instead of text you can write attachment selection python code.\n\n## Legal\n* This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by WhatsApp or any of its affiliates or subsidiaries. This is an independent and unofficial software. Use at your own risk. Commercial use of this code/repo is strictly prohibited.\n\n## Code\n```\n# Program to send bulk customized message through WhatsApp web application\n# Author @inforkgodara\n\nfrom selenium import webdriver\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.common.keys import Keys\nfrom selenium.webdriver.common.action_chains import ActionChains\nfrom selenium.common.exceptions import NoSuchElementException\nimport pandas\nimport time\n\n# Load the chrome driver\ndriver = webdriver.Chrome()\ncount = 0\n\n# Open WhatsApp URL in chrome browser\ndriver.get(\"https://web.whatsapp.com/\")\nwait = WebDriverWait(driver, 20)\n\n# Read data from excel\nexcel_data = pandas.read_excel('Customer bulk email data.xlsx', sheet_name='Customers')\nmessage = excel_data['Message'][0]\n\n# Iterate excel rows till to finish\nfor column in excel_data['Name'].tolist():\n    # Locate search box through x_path\n    search_box = '//*[@id=\"side\"]/div[1]/div/label/div/div[2]'\n    person_title = wait.until(lambda driver:driver.find_element_by_xpath(search_box))\n\n    # Clear search box if any contact number is written in it\n    person_title.clear()\n\n    # Send contact number in search box\n    person_title.send_keys(str(excel_data['Contact'][count]))\n    count = count + 1\n\n    # Wait for 3 seconds to search contact number\n    time.sleep(3)\n\n    try:\n        # Load error message in case unavailability of contact number\n        element = driver.find_element_by_xpath('//*[@id=\"pane-side\"]/div[1]/div/span')\n    except NoSuchElementException:\n        # Format the message from excel sheet\n        message = message.replace('{customer_name}', column)\n        person_title.send_keys(Keys.ENTER)\n        actions = ActionChains(driver)\n        actions.send_keys(message)\n        actions.send_keys(Keys.ENTER)\n        actions.perform()\n\n# Close Chrome browser\ndriver.quit()\n```\nNote: The script may not work in case if the HTML of web WhatsApp is changed.\n\nFind it on youtube. https://youtu.be/NcWXpsczl3c\n"
  },
  {
    "path": "script.py",
    "content": "# Program to send bulk customized message through WhatsApp web application\n# Author @inforkgodara\n\nfrom selenium import webdriver\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.common.keys import Keys\nfrom selenium.webdriver.common.action_chains import ActionChains\nfrom selenium.common.exceptions import NoSuchElementException\nimport pandas\nimport time\n\n# Load the chrome driver\ndriver = webdriver.Chrome()\ncount = 0\n\n# Open WhatsApp URL in chrome browser\ndriver.get(\"https://web.whatsapp.com/\")\nwait = WebDriverWait(driver, 20)\n\n# Read data from excel\nexcel_data = pandas.read_excel('Customer bulk email data.xlsx', sheet_name='Customers')\n\n# Iterate excel rows till to finish\nfor column in excel_data['Name'].tolist():\n    # Assign customized message\n    message = excel_data['Message'][0]\n\n    # Locate search box through x_path\n    search_box = '//*[@id=\"side\"]/div[1]/div/label/div/div[2]'\n    person_title = wait.until(lambda driver:driver.find_element_by_xpath(search_box))\n\n    # Clear search box if any contact number is written in it\n    person_title.clear()\n\n    # Send contact number in search box\n    person_title.send_keys(str(excel_data['Contact'][count]))\n    count = count + 1\n\n    # Wait for 2 seconds to search contact number\n    time.sleep(2)\n\n    try:\n        # Load error message in case unavailability of contact number\n        element = driver.find_element_by_xpath('//*[@id=\"pane-side\"]/div[1]/div/span')\n    except NoSuchElementException:\n        # Format the message from excel sheet\n        message = message.replace('{customer_name}', column)\n        person_title.send_keys(Keys.ENTER)\n        actions = ActionChains(driver)\n        actions.send_keys(message)\n        actions.send_keys(Keys.ENTER)\n        actions.perform()\n\n# Close chrome browser\ndriver.quit()"
  }
]