I'm trying to implement a WhatsApp bot, which uses the chromedriver
and opens whatsapp web, and sends messages to the contacts. These are the steps of the program:
Here are the problems that I'm unable to solve:
Since the code is pretty long, here is the link to it: https://github.com/harshitsidhwa/WhatsApp-bot-selenium
It's forbidden to use WhatsApp chatbot for marketing and promotional notifications. It is best to use WhatsApp chatbots for customer service and non-promotional notifications. In such cases, you are more likely to get WhatsApp API access.
Python sending messages to contacts:
def send_message(target):
global message,wait, browser
try:
x_arg = '//span[contains(@title,' + target + ')]'
group_title = wait.until(EC.presence_of_element_located((By.XPATH, x_arg)))
group_title.click()
input_box = browser.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
input_box.send_keys(message + Keys.ENTER)
time.sleep(1)
except NoSuchElementException:
return
Here the variable target is the contact name whom you want to send a message. Variable message contains the text message you want to send to that contact. Variable browser is web driver variable.
I have already worked on WhatsApp Automation, in case of any help refer to the link: https://github.com/shauryauppal/PyWhatsapp
You have stated two problems:
You cannot access to contact names by contact list or archived contact list. The only way is recent chat contacts. For other contacts, you have to visit all contacts list select the target person then send messages. (Will implement soon).
Sending of Images, Files and Videos can be Implemented by PyAutoIt. Refer my repo, I have already implemented that.
Step1: AutoIt.exe Installation Link
Step2:
pip install PyAutoIt
Refer my code or this link for guidance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With