GithubHelp home page GithubHelp logo

kalebu / alright Goto Github PK

View Code? Open in Web Editor NEW
364.0 11.0 108.0 524 KB

Python wrapper for WhatsApp web-based on selenium

Home Page: https://www.youtube.com/watch?v=yitQTt-NukM

License: MIT License

Python 100.00%
whatsapp-web pywhatsapp python-whatsapp whatsapp-api whatsapp-bulk-sender whatsapp-business-api

alright's Introduction

Python wrapper for WhatsApp web made with selenium inspired by PyWhatsApp

Downloads Downloads Downloads

Youtube demo

Why alright ?

I was looking for a way to control and automate WhatsApp web with Python, I came across some very nice libaries and wrapper implementations including;

So I tried pywhatkit, a really cool one well crafted to be used by others but its implementations require you to open a new browser tab and scan QR code everytime you send a message no matter if its to the same person, which was deal breaker for using it.

Then I tried pywhatsapp which is based on yowsup and thus requiring you to do some registration with yowsup before using it of which after bit of googling I got scared of having my number blocked, so I went for the next option

I then went for WebWhatsapp-Wrapper, it has some good documentation and recent commits so I had hopes that it would work. But unfortunately it didn't for me, and after having a couple of errors I abandoned it to look for the next alternative.

Which is PyWhatsapp by shauryauppal. This was more of CLI tool than a wrapper which suprisingly worked well and it's approach allows you to dynamically send whatsapp message to unsaved contacts without rescanning QR-code everytime.

So what I did is more of a refactoring of the implementation of that tool to be more of wrapper to easily allow people to run different scripts on top of it instead of just using it as a tool. I then thought of sharing the codebase to people who might have struggled to do this as I did.

Getting started

You need to do a little bit of work to get alright running, but don't worry I got you, everything will work well if you just carefully follow through the documentation.

Installation

We need to have alright installed on our machine to start using it which can either be done directly from GitHub or using pip.

Installing directly

You first need to clone or download the repo to your local directory and then move into the project directory as shown in the example and then run the command below;

git clone https://github.com/Kalebu/alright
cd alright
alright > python setup.py install 
....

Installing from pip

pip install alright --upgrade

Setting up Selenium

Underneath alright is Selenium which is what does all the automation work by directly controlling the browser, so you need to have a selenium driver on your machine for alright to work. But luckily alright uses webdriver-manager, which does this automatically. You just need to install a browser. By default alright uses Google Chrome.

What you can do with alright?

When you're running your program made with alright, you can only have one controlled browser window at a time. Running a new window while another window is live will raise an error. So make sure to close the controlled window before running another one

Unsaved contact vs saved contacts

Alright allows you to send the messages and media to both saved and unsaved contacts as explained earlier. But there is a tiny distinction on how you do that, you will observe this clearly as you use the package.

The first step before sending anything to the user is first to locate the user and then you can start sending the information, thats where the main difference lies between saved and unsaved contacts.

Saved contacts

To saved contact use method find_by_username() to locate a saved user. You can also use the same method to locate WhatsApp groups. The parameter can either be;

  • saved username
  • mobile number
  • group name

Here an Example on how to do that

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.find_by_username('saved-name or number or group')

Unsaved contacts

In sending message to unsaved whatsapp contacts use find_user() method to locate the user and the parameter can only be users number with country code with (+) omitted as shown below;

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.find_user('255-74848xxxx')

Now Let's dive in on how we can get started on sending messages and medias

Sending Messages

Use this if you don't have WhatsApp desktop installed

To send a message with alright, you first need to target a specific user by using find_user() method (include the country code in your number without the '+' symbol) and then after that you can start sending messages to the target user using send_message() method as shown in the example below;

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.find_user('2557xxxxxz')
>>> messages = ['Morning my love', 'I wish you a good night!']
>>> for message in messages:  
        messenger.send_message(message)    

Send Direct Message [NEW]

Recommended

This is newly added method that makes it a bit simpler to send a direct message without having to do the find_user or find_by_username, It works well even if you have or not have WhatsApp installed on your machine. It assumes the number is a saved contact by default.

>>> messenger.send_direct_message(mobile, message, saved=True)

It does receive the following parameters;

  1. mobile[str] - The mobile number of the user you want to send the message to
  2. message[str] - The message you want to send
  3. saved[bool] - If you want to send to a saved contact or not, default is True

Here is an example on how to use it;

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> >>> messenger.send_direct_message('25573652xxx', 'Hello')
2022-08-14 17:27:57,264 - root -- [INFO] >> Message sent successfuly to 
2022-08-14 17:27:57,264 - root -- [INFO] >> send_message() finished running!
>>> messenger.send_direct_message('25573652xxx', 'Who is This ?', False)
2022-08-14 17:28:30,953 - root -- [INFO] >> Message sent successfuly to 255736524388
2022-08-14 17:28:30,953 - root -- [INFO] >> send_message() finished running!

Sending Messages1

This Send Message does NOT find the user first like in the above Send Message, AND it does work even if you have the Desktop WhatsApp app installed. Include the country code in your number withour '+' symbol as shown in the example below;

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messages = ['Morning my love', 'I wish you a good night!']
>>> mobNum = 27792346512
>>> for message in messages:  
        messenger.send_message1(mobNum, msg)

Multiple numbers

Here how to send a message to multiple users, Let's say we want to wish merry-x mass to all our contacts, our code is going to look like this;

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> numbers = ['2557xxxxxx', '2557xxxxxx', '....']
>>> for number in numbers:
        messenger.find_user(number)
        messenger.send_message("I wish you a Merry X-mass and Happy new year ")

You have to include the country code in your number for this library to work but don't include the (+) symbol

If you're sending media either picture, file, or video each of them have an optional parameter called which is usually the caption to accompany the media.

Sending Images

Sending Images is nothing new, its just the fact you have to include a path to your image and the message to accompany the image instead of just the raw string characters and also you have use send_picture(), Here an example;

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.find_user('mobile')
>>> messenger.send_picture('path-to-image-without-caption')
>>> messenger.send_picture('path-to-image',"Text to accompany image")

Sending Videos

Similarly, to send videos just use the send_video() method;

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.find_user('mobile')
>>> messenger.send_video('path-to-video')

Sending Documents

To send documents such as docx, pdf, audio etc, you can use the send_file() method to do that;

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.find_user('mobile')
>>> messenger.send_file('path-to-file')

Check if a chat has unread messages or not

This method checks if a chat, which name is passed as a query parameter, has got unread messages or not.

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.check_if_given_chat_has_unread_messages(query="Chat 123")

Get first chat

This method fetches the first chat in the list on the left of the web app - since they are not ordered in an expected way, a fair workaround is applied. One can also ignore (or not ignore) pinned chats (placed at the top of the list) by passing the parameter ignore_pinned to do that - default value is ignore_pinned=True.

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.get_first_chat()

Search chat by name

This method searches the opened chats by a partial name provided as a query parameter, returning the first match. Case sensitivity is treated and does not impact the search.

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.search_chat_by_name(query="Friend")

Get last message received in a given chat

This method searches for the last message received in a given chat, received as a query parameter, returning the sender, text and time. Groups, numbers and contacts cases are treated, as well as possible non-received messages, video/images/stickers and others.

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.get_last_message_received(query="Friend")

Retrieve all chat names with unread messages

This method searches for all chats with unread messages, possibly receiving parameters to limit the search to a top number of chats or not, returning a list of chat names.

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.fetch_all_unread_chats(limit=True, top=30)

DISCLAIMER: Apparently, fetch_all_unread_chats functionallity works on most updated browser versions (for example, Chrome Version 102.0.5005.115 (Official Build) (x86_64)). If it fails with you, please consider updating your browser while we work on an alternatives for non-updated broswers.

logout from whatsapp

You can sign out of an account that is currently saved

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> messenger.logout()

Well! thats all for now from the package, to request new feature make an issue.

Contributions

alright is an open-source package under MIT license, so contributions are warmly welcome whether that be a code , docs or typo just fork it.

When contributing to code please make an issue for that before making your changes so that we can have a discussion before implementation.

Issues

If you're facing any issue or difficulty with the usage of the package just raise one so that we can fix it as soon as possible.

Please, be as much comprehensive as possible! Use as many screenshots and detailed description sets as possible; this will save us some time that we'd dedicate on asking you for "a more detailed descriptiton", and it'll make your request be solved faster.

Give it a star

Was this useful to you ? Then give it a star so that more people can manke use of this.

Credits

All the credits to:

alright's People

Contributors

abdulmelikbekmez avatar ajauish avatar avicennajr avatar badi95 avatar bryanbetancur avatar chandansgowda avatar chetan6780 avatar danm1-cmyk avatar euriconicacio avatar federicocacciari avatar fierylion avatar frangmz avatar kalebu avatar leggewie avatar leotrubach avatar mohammad-sky avatar olichuuwon avatar reydeargentina avatar thecjman avatar tr1ms avatar vadolasi avatar vanshkela avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alright's Issues

how to disable open WhatsApp application

everytime i run the code (from the examples), a web browser (Chrome) opened and then ask me to open whatsapp application (https://api.whatsapp.com wants to open this application)
if I canceled, then the browser do nothing, otherwise the whatsapp application is opened and alright gave me error:
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

Unexpected indent

See the error log:

python3 main.py
Traceback (most recent call last):
  File "(...)/main.py", line 1, in <module>
    from alright import WhatsApp
  File "(...)/python3.8/site-packages/alright/__init__.py", line 207
    for i in ctrl_element:
    ^

Apparently, there is a wrong indent in __init__.py.

Use Existing Open Chrome Window with Whatsapp Web

I believe loading whatsapp window again and again consumes alot of resources over my Pi. Is it possible to use already open window and send message? How about copying message to clip-board and pasting it using selenium in existing window?

Btw v v v good code. I made it work with Chromium browser instead of chrome. Works like a charm.

Multi-Line Text Message

How to send a multi-line text message, the Keys.SHIFT+Keys.ENTER command translates to weird characters

Sending message without opening browser

Is it possible to send the messages while whatsapp-web tab is closed? Of course I would open it to read the qr code. But once that is done, I would close the tab. Is it possible to send the message even then?

Failed to create data directory

Hello, I am having this issue, not sure others having the same issue or not but I just want to let you know this
image
image

After surfing on the web and trying different solution it still giving the same issue, so I have commented line 26 in init.py, Now its opening what's app but not sending messages.

error 'no such element: Unable to locate element'

i fixed self.browser.find_element_**by_xpath**('//div[@id="main"]/header/div[1]/div[1]/div[1]/span').get_attribute("data-testid")
to self.browser.find_element(**By.XPATH**,'//div[@id="main"]/header/div[1]/div[1]/div[1]/span').get_attribute("data-testid")
and i gets this error: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@id="main"]/header/div[1]/div[1]/div[1]/span"} (Session info: chrome=105.0.5195.54)

Link preview

Sorry, I'm developing for fun and I don't know much about github, so please forgive my ignorance.

I have an idea to be added to alright (nice job, by the way @Kalebu ):

A function to send a link with link preview.

First I added another wait in init:
self.wait2 = WebDriverWait(self.browser, 5)

Then the new function:

    def send_link(self, message):
        try:
            inp_xpath = '//*[@id="main"]/footer/div[1]/div[2]/div/div[1]/div/div[2]'
            lnk_xpath = '//*[@id="main"]/footer/div[2]/div[1]/div[5]/div[1]/div[1]'
            input_box = self.wait.until(
                EC.presence_of_element_located((By.XPATH, inp_xpath)))
            input_box.send_keys(message + Keys.SPACE)
            try:
                input_box2 = self.wait2.until(
                    EC.presence_of_element_located((By.XPATH, lnk_xpath)))
            except: 
                pass
            input_box.send_keys(" " + Keys.ENTER)
            print(f"Message with link sent successfuly to {self.mobile}")
        except (NoSuchElementException, Exception) as bug:
            print(bug)
            print(f'Failed to send a message with link to {self.mobile}')

        finally:
            print("send_link() finished running ")

It waits for 5 seconds for the preview to load, if it didn't load, then it sends the message anyway without preview.

send_picture closes too quickly, making it unable to send the image

Right now send_picture closes too quickly, resulting in the image not being sent

I have temporarily resolved it myself using the following time.sleep:

            self.find_attachment()
            # To send an Image
            imgButton = self.wait.until(EC.presence_of_element_located(
                (By.XPATH, '//*[@id="main"]/footer//*[@data-icon="attach-image"]/../input')))
            imgButton.send_keys(filename)
            self.send_attachment()
            time.sleep(5)
            print(f"Picture has been successfully sent to {self.mobile}")```

I'm not too sure how selenium works but it would be great if we could wait for the image to send before moving to the next person

Not really an issue, just general improvements

Hiya, folks.

Just created a PR with two main improvements to the code:

  • Removed the close_browser method and created the more efficient close_when_message_successfully_sent method, making it useful to close the browser when the message is successfully sent.
  • Added CLI logging capability, implemented as a replacement to print errors. Professional approach, expanding its possibilities to further handlers if needed (for example, logging not only into the stream but into a file, through a TCP socket, or even meshed with SysLog if necessary - please, refer to the logging package docs for more info, it's REALLY useful).
  • Added multiline support, as per issue #42.

Over my free time in the following days, I'll be working on the identification of opened browser instances and their usage instead of a mandatory "no other opened browser" requirement for a nice and smooth execution of the code.

PS: @Kalebu, please check your Twitter inbox, sent you some info that may be of your interest.

nCKbr.

Chrome failed to start: exited abnormally

I tried to run in ubuntu with GUI installed and chrome installed, but it failed to start the chrome browser with following error:

Traceback (most recent call last): File "sample.py", line 5, in <module> messenger = WhatsApp() File "/usr/local/lib/python3.8/dist-packages/alright/__init__.py", line 33, in __init__ browser = webdriver.Chrome( File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__ super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog", File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chromium/webdriver.py", line 92, in __init__ RemoteWebDriver.__init__( File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 275, in __init__ self.start_session(capabilities, browser_profile) File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 365, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 430, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

Here is my code:
`from alright import WhatsApp
import time

msg = "hey I'm done its tuesday"
messenger = WhatsApp()
messenger.send_message1(628964323xxx, msg)`

The code is work on my Mac, any suggestion on this?

Thanks

Typos and addition in README.md

There is a typo in "sending images" section, the code should be

from alright import WhatsApp

and we should let know users include country code in find_user() before they write the code.
I want to correct this type and add the above message, can I do it?

Other Browsers

I am using Brave browser. Is it possible to open whatsapp web page in a Brave tab? Or, do I have to install Chromium?

Thanks.

messenger.find_user not working with whatsapp web

Hi,
I tried to send a whatsapp message using the alright module but when I ran the code, Goggle Chrome was launched but asks me if I want to open the whatsapp app instead of sending the message via whatsapp web as expected.
Thanks for help.

Here is my code

messenger = WhatsApp()
messenger.find_user('12345678')
messenger.send_message('Test of alright module')

image

How to send image with caption

Is my first time making a coment in github, i am sending an "improvement" of "send_picture()". It is how to send a picture with text on it:

def send_picture(self, picture, message): try: filename = os.path.realpath(picture) self.find_attachment() # To send an Image imgButton = self.wait.until(EC.presence_of_element_located( (By.XPATH, '//*[@id="main"]/footer//*[@data-icon="attach-image"]/../input'))) imgButton.send_keys(filename) inp_xpath = '//*[@id="app"]/div[1]/div[1]/div[2]/div[2]/span/div[1]/span/div[1]/div/div[2]/div/div[1]/div[3]/div/div/div[2]/div/div[2]' input_box = self.wait.until(EC.presence_of_element_located(( By.XPATH, inp_xpath))) input_box.send_keys(message + Keys.ENTER) self.send_attachment() print(f"Picture has been successfully sent to {self.mobile}") except (NoSuchElementException, Exception) as bug: print(bug) print(f'Failed to send a picture to {self.mobile}')

Error Message?

>>> messenger.find_by_username('username') Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> messenger.find_by_username('username') TypeError: find_by_username() missing 1 required positional argument: 'username'

error sending message

hello sir,
i install your app in my ubuntu machine , and it work , when i use class of find user it work and get the specific user, but when i send message i get exception error.
message of exception is:
element not interactable

Alright with Edge

Can i use the alright with the edge?
i'm trying to use it, but everytime is shown to me a new error

There's the code:

from alright import WhatsApp
from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from webdriver_manager.microsoft import EdgeChromiumDriverManager

driver = webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager().install()))
messenger = WhatsApp()

(I made it at the company that i work, but there i was using google. I felt the problem that u are being showed, about the xpath, and made what the people on de issues said, and worked. But now, i brought it to my house and i don't use google chrome, just edge)

send_message1() is not working

It looks like one of the xpath are broken. I don't know which one. Throws UnboundLocalVariable error on line 249 of __init.py__ file

WhatsApp Desktop

Hi, when sending files or media, it opens WhatsApp Desktop and so stop. I saw that you fix this with send_message1, is it possible to fix this for all the others possibilities?

Thanks

Doesn't work on raspberry pi

Hello there, I'm migrating from pywhatkit and I loved your package, but there seems to be a problem whil I was working on a raspberry pi, the chrome driver installation is not being recognised by alright, how do I deal with this issue, please let me know asap.

Crashes during messanger creation

Hi! I'm facing with issue!
Can't start. Thank you advance!

messenger = WhatsApp()
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\Python39\lib\site-packages\alright-1.1-py3.9.egg\alright_init_.py", line 27, in init
File "C:\Program Files\Python39\lib\site-packages\selenium-4.0.0b4-py3.9.egg\selenium\webdriver\chrome\webdriver.py", line 69, in init
super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Program Files\Python39\lib\site-packages\selenium-4.0.0b4-py3.9.egg\selenium\webdriver\chromium\webdriver.py", line 93, in init
RemoteWebDriver.init(
File "C:\Program Files\Python39\lib\site-packages\selenium-4.0.0b4-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 248, in init
self.start_session(capabilities, browser_profile)
File "C:\Program Files\Python39\lib\site-packages\selenium-4.0.0b4-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 339, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Program Files\Python39\lib\site-packages\selenium-4.0.0b4-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 400, in execute
self.error_handler.check_response(response)
File "C:\Program Files\Python39\lib\site-packages\selenium-4.0.0b4-py3.9.egg\selenium\webdriver\remote\errorhandler.py", line 236, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot create default profile directory
Stacktrace:
Backtrace:
Ordinal0 [0x002A3733+2504499]
Ordinal0 [0x0023C401+2081793]
Ordinal0 [0x00142628+1058344]
Ordinal0 [0x0015F6B0+1177264]
Ordinal0 [0x0015CFEA+1167338]
Ordinal0 [0x00159DC3+1154499]
Ordinal0 [0x00189B82+1350530]
Ordinal0 [0x001897DA+1349594]
Ordinal0 [0x00185D4B+1334603]
Ordinal0 [0x001622B4+1188532]
Ordinal0 [0x00163149+1192265]
GetHandleVerifier [0x0041FB8C+1512252]
GetHandleVerifier [0x004CB0DF+2214031]
GetHandleVerifier [0x00324BC3+484211]
GetHandleVerifier [0x00323E69+480793]
Ordinal0 [0x0024218D+2105741]
Ordinal0 [0x002466E8+2123496]
Ordinal0 [0x00246827+2123815]
Ordinal0 [0x0024FB73+2161523]
BaseThreadInitThunk [0x76F4FA29+25]
RtlGetAppContainerNamedObjectPath [0x77CF7A9E+286]
RtlGetAppContainerNamedObjectPath [0x77CF7A6E+238]
(No symbol) [0x00000000]

send message text error

Hi I'm currently trying to send a message and a image, but it doesn't sends the message and stands still in that part:

from alright import WhatsApp
messenger = WhatsApp()
numbers = ['14155238886']
for number in numbers:
messenger.find_user(number)
messenger.send_message("I wish you a Merry X-mass and Happy new year ")
messenger.send_picture('/Users/matiasgonzalotiberio/Desktop/Whatsapp-Python/1451023683665.jpeg')

Captura de Pantalla 2021-09-14 a la(s) 12 50 04

Captura de Pantalla 2021-09-14 a la(s) 12 50 13

As you can see it starts and throws no error, but the message text isn't sent

Multiline Textmessage

Is it possible to send multiline textmessages with whatsapp without all of them being a separate text-message

Message with line break

How I break line in place of '\n'?

phone = '55628140XXXX'
messages = ['Hi!', 'How are you?\n\nI hope you're okay...']

messenger.find_user(phone)
for message in messages:
    messenger.send_message(message)

Get chat

hi kalebu
I think if this library can get the last chat of the user is It will be great

Newbie guide

Sorry to ask this, but do I need to login via chrome first before I'm using alright? Thanks!

Whatsapp doesn't use whatsapp web

When trying to send msg on ubuntu, whatsapp shows to download Desktop (that doesn't exists) or to let you select to use whatsapp web.
I remember that last week it was working good, any advice? Thank you

find_by_username search box XPATH does not work - updated it - and created close_browser method.

So, I'm using Pyhon 3.10.4, Chrome 102.0.5005.61 and Debian 9.13.

When trying to send a simple message, the code hang forever and nothing happened. While debugging, I noticed that the XPATH for the search_box on find_by_username was not correct.

Under my configuration, this is incorrect:

            search_box = self.wait.until(
                EC.presence_of_element_located(
                    (By.XPATH, '//*[@id="side"]/div[1]/div/label/div/div[2]')
                )
            )

And this is correct:

            search_box = self.wait.until(
                EC.presence_of_element_located(
                    (By.XPATH, '//*[@id="app"]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[2]')
                )
            )

I was wondering if this is happening to anyone else and if it depends on Chrome version or OS. If it does, I can work on a PR for it.

Thanks in advance for your attention.

@Kalebu @vadolasi

Noticed some grammar mistakes in README

If you're facing any issue or difficult with the usage of the package just raise one so as we can fix it as soon as possible. Difficult -- Difficulty and as -- that

username_exists function

Hi all, first of all let me say it's my first time interacting like this on Github. I'll try my best.
I found a problem while trying to send a message to more than one destination, when one of those was not saved as a contact. What happened was that the find_by_username function performed the search, but if there was no result for the search, there was no special output to detect it. So, the chat that was open before that search was the one who received the next message. And would continue to get messages until the search gets a result.
I created a new function called username_exists, with find_by_username as the base, which returns true or false whether the search for username opens the username chat or not (by looking at the title of the open conversation).
Here is the code I made. Please, consider I'm just an amateur programmer.

def username_exists(self, username):
        """username_exists ()

        Return True or False whether the contact exists or not, and selects the contact if it exists

        Args:
            username ([type]): [description]
        """
        try:
            search_box = self.wait.until(EC.presence_of_element_located(
                (By.XPATH, '//*[@id="side"]/div[1]/div/label/div/div[2]')))
            search_box.clear()
            search_box.send_keys(username)
            search_box.send_keys(Keys.ENTER)
            m = self.browser.find_element_by_xpath("/html/body/div/div[1]/div[1]/div[4]/div[1]/header/div[2]/div[1]/div/span")
            title = m.get_attribute("title") 
            if title == username:
                return True
            else:
                return False
        except Exception as bug:
            error = f'Exception raised while finding user {username}\n{bug}'
            print(error)

Finally, let me say thanks for alright, and I hope this is useful in some way.

headless doesn't work.

When I change to headless this is what Im getting if I debug the browser.page_source (found it since wait_until wait forever)

WhatsApp WebWhatsApp WebWhatsApp works with Google Chrome 60+To use WhatsApp, update Chrome or use Mozilla Firefox, Safari, Microsoft Edge or Opera.Update Google ChromeWhatsApp works with Google Chrome 60+To use WhatsApp, update Chrome or use Mozilla Firefox, Safari, Microsoft Edge or Opera.Update Google Chrome

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.