Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whatsapp Automated Bot not able to search in WhatsApp Contact List

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:

  • Reads the contacts from an excel file
  • Set the time, when you want to send the message along with the message you want to send
  • Search that name and send message

Here are the problems that I'm unable to solve:

  1. If the name is not there in recent chats, it is not able to search it from the WhatsApp contact list and send
  2. Also I want to know how I can send images and videos

Since the code is pretty long, here is the link to it: https://github.com/harshitsidhwa/WhatsApp-bot-selenium

like image 519
skkrish Avatar asked Aug 16 '18 07:08

skkrish


People also ask

Are bots allowed on WhatsApp?

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.


1 Answers

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:

  1. 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).

  2. 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.

like image 161
Shaurya Uppal Avatar answered Nov 14 '22 03:11

Shaurya Uppal