Code Monkey home page Code Monkey logo

webwhatsapp-wrapper's Introduction

Logo

(Based on web.whatsapp.com)

PyPI version Firefox version All Contributors Code style: black

What is it?

This package is used to provide a python interface for interacting with WhatsAPP Web to send and receive Whatsapp messages. It is based on the official Whatsapp Web Browser Application and uses Selenium browser automation to communicate with Whatsapp Web.

How to contribute?

If you are new, click here

Local installation

Dependencies

You will need to install Gecko Driver separately, if using firefox, which is the default.

From Source

  • Clone the repository
  • Use pip install -r requirements.txt to install the required packages
  • or pipenv install && pipenv install --dev

From PyPI

  • Install from pip pip install webwhatsapi

Docker and remote Selenium Installation

It may be favorable to run Selenium and the webwhatsapi client as Docker containers. This almost completely avoids any installation problems and any messy local installation or dependency hell. The result is a more stable runtime environment for the client, which could run on a headless server. Using Docker may also help in developing the library itself.

1. Create network

docker network create selenium

2. Run Selenium grid/standalone container

This is based on the official Selenium image (https://github.com/SeleniumHQ/docker-selenium). The following Docker command runs a Selenium standalone Firefox browser in debug (VNC) mode. You can use VNC on port 5900 to view the browser. It uses the network "selenium" and the container is named "firefox" for later reference.

docker run -d -p 4444:4444 -p 5900:5900 --name firefox --network selenium -v /dev/shm:/dev/shm selenium/standalone-firefox-debug:3.14.0-curium

3. Build python/webwhatsapi docker base image

The following command uses the dockerfile to build a new image based on Python 2.7 with all required packages from requirements.txt.

docker build -t webwhatsapi .

4. Run client container

Now to the client container. The following command installs a local webwhatsapi inside the base container and runs a client. It maps the local directory to the app directory inside the container for easy development. Also sets the network to "selenium" and an environment variable for the remote selenium url. Please note that the remote Selenium hostname must be identical to the name of the Selenium container.

docker run --network selenium -it -e SELENIUM='http://firefox:4444/wd/hub' -v $(pwd):/app  webwhatsapi /bin/bash -c "pip install ./;pip list;python sample/remote.py"

For Windows (cmd):

docker run --network selenium -it -e SELENIUM='http://firefox:4444/wd/hub' -v "%cd%:/app" webwhatsapi /bin/bash -c "pip install ./;pip list;python sample/remote.py"

For Windows (PowerShell):

docker run --network selenium -it -e SELENIUM='http://firefox:4444/wd/hub' -v "$(pwd):/app".ToLower() webwhatsapi /bin/bash -c "pip install ./;pip list;python sample/remote.py"

It is also certainly possible to fully build the docker image in advance and define an entrypoint/cmd inside the dockerfile to run a full client.

Usage

See sample directory for more complex usage examples.

1. Import library

from webwhatsapi import WhatsAPIDriver

2. Instantiate driver and set username

driver = WhatsAPIDriver(username="mkhase")

Possible arguments for constructor:

  • client : Type of browser. The default is Firefox, but Chrome and Remote is supported too. See sample directory for remote examples.
  • username : Can be any value.
  • proxy: The proxy server to configure selenium to. Format is ":"
  • command_executor: Passed directly as an argument to Remote Selenium. Ignore if not using it. See sample directory for remote examples.
  • loadstyles: Default is False. If True, it will load the styling in the browser.
  • profile: Pass the full path to the profile to load it. Profile folder will be end in ".default". For persistent login, open a normal firefox tab, log in to whatsapp, then pass the profile as an argument.

3. Use a function to save the QR code in a file, for remote clients, so that you can access them easily. Scan the QR code either from the file, or directly from the client to log in.

driver.get_qr()

4. In case the QR code expires, you can use the reload_qr function to reload it

driver.reload_qr()

5. Viewing unread messages

driver.view_unread()

6. Viewing all contacts

driver.get_all_chats()

7. To send a message, get a Contact object, and call the send_message function with the message.

<Contact Object>.send_message("Hello")

8. Sending a message to an ID, whether a contact or not.

driver.send_message_to_id(id, message)

Code Documentation

https://webwhatsapi.readthedocs.io/en/latest/

Limitation

Phone needs to manually scan the QR Code from Whatsapp Web. Phone has to be on and connected to the internet.

Capabilities

  • Read recent messages
  • Get unread messages
  • Send text messages
  • Get List of Contacts
  • Get List of Groups
  • Get information about Groups
  • Get various events. For example: Leaving, Joining, Missed Call etc.
  • Download media messages
  • Get List of common groups
  • Asyncio driver version

Note

There are issues with asynchronous calls in Chrome. Primary support of this api is for firefox. If something doesn't work in chrome, please try firefox.

Known issues with chrome:

  • Group Metadata

For more queries, contact: [email protected]

Contribute

Contributing is simple as cloning, making changes and submitting a pull request. If you would like to contribute, here are a few starters:

  • Bug Hunts
  • More sorts of examples
  • Additional features/ More integrations (This api has the minimum amount, but I don't mind having more data accessible to users)
  • Create an env/vagrant box to make it easy for others to contribute. (At the moment, all I have is a requirements.txt
  • Phantom JS support

Legal

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.

Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

webwhatsapp-wrapper's People

Contributors

acarist avatar adarshsanjeev avatar alfred82santa avatar anibalcesar avatar bobaoapae avatar brunosoaresds avatar choval avatar chriso0710 avatar codemanat avatar dafner avatar eduardomazolini avatar geovrodri avatar heinleit avatar houseme-brandon avatar ju-w avatar kaykyr avatar kevinkit avatar lfagundes avatar lfdelphino avatar lucasrcezimbra avatar marcelomaia avatar michotastico avatar mukulhase avatar ofirkp avatar pabloruan0710 avatar prehensilebbc avatar r0manchak avatar rbnishant avatar sevetseh28 avatar tobaloidee 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  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

webwhatsapp-wrapper's Issues

Help Needed

WebWhatsAPI
#!/usr/bin/python2.7
from webwhatsapi import WhatsAPIDriver
driver = WhatsAPIDriver(username="Test", browser="firefox", proxy=None)

Traceback (most recent call last):
File "./whatsapp.py", line 3, in
driver = WhatsAPIDriver(username="L0RE", browser="firefox", proxy=None)
TypeError: init() got an unexpected keyword argument 'browser'

I think missing some Elementary here
Mayby you could help,

only can send to store chats

It can send only to store chats, how can i send a message if i do not have the chat open, in js file there are this line

var Chats = Store.Chat.models;

It take only chats that are open

not opening web.whatsapp.com

installed via pip2, downloaded geckodriver and added to /usr/bin/
when i try to run the sample, it opens a firefox window but it doesn't open web.whatsapp.com.
no errors in the console

Do I have to scan the QR code every time ?

Hello,

First of all, please change the qr selector to the following in order for the app to work:
qrCode': "#app img:first-of-type"

On the other hand, I was wondering if there's a way not to scan the QR code on ever run, just scan it the first time and that's it. Because in my case, every-time I run my script, the firefox pops up asking again to scan the QR code even when I already did.

I'm using the code in sample.py

Thanks a lot!

Multiple QR reading

Hello, I'm sorry my English.

How make for use "user".png qr code and skip reading QR every time after restart, I have the picture with QR code saved in directory, but always that restarted sample.py, need reader again QR

Not able to send message to contact

I am trying to send message by send_to_phone_number(). But if chat isn't active I am unable to send. The user is in my contact list?

Also when I try to send YouTube link, it is not showing thumbnail but web.whatsapp.com has this feature, should I add delay before send?

Possibility to send message to a new contact?

Hello

It seems this API only works to send message if the conversation with the contact already exists.

Is there a way to create a conversation with a contact ? (in my contact list or not)

Thank you!

Issue while storing QR Code

I am getting below error;

waiting for QR Traceback (most recent call last): File "sample.py", line 5, in <module> driver.firstrun() File "/home/xxxx/.local/lib/python2.7/site-packages/webwhatsapi/__init__.py", line 67, in firstrun qr = self.driver.find_element_by_css_selector(self._SELECTORS['qrCode']) File "/home/xxxx/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 509, in find_element_by_css_selector return self.find_element(by=By.CSS_SELECTOR, value=css_selector) File "/home/xxxx/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 855, in find_element 'value': value})['value'] File "/home/xxxx/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute self.error_handler.check_response(response) File "/home/xxxx/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .qrcode > img:nth-child(4)

Gecokdriver.log
1511772898197 geckodriver INFO geckodriver 0.18.0 1511772898209 geckodriver INFO Listening on 127.0.0.1:33645 1511772899359 geckodriver::marionette INFO Starting browser /usr/bin/firefox with args ["-marionette"] 1511772901880 Marionette INFO Enabled via --marionette 1511772905154 Marionette INFO Listening on port 36689 1511772905344 Marionette WARN TLS certificate errors will be ignored for this session 1511772905448 Marionette DEBUG Register listener.js for window 2147483649 1511772905481 Marionette DEBUG Received DOM event "beforeunload" for "about:blank" 1511772906580 Marionette DEBUG Received DOM event "pagehide" for "about:blank" 1511772906581 Marionette DEBUG Received DOM event "unload" for "about:blank" 1511772907216 Marionette DEBUG Received DOM event "DOMContentLoaded" for "https://web.whatsapp.com/" 1511772914152 Marionette DEBUG Received DOM event "pageshow" for "https://web.whatsapp.com/" *** UTM:SVC TimerManager:registerTimer called after profile-before-change notification. Ignoring timer registration for id: telemetry_modules_ping

Any clue?

How to use?

How to use? I am using amazon aws, how do I get the qr code?

Failed during authentication

Hello in some cases I get this error:

C:\Users\pier\Desktop\WhatsAPI-masterBuh>python sample.py
waiting for QR
Traceback (most recent call last):
File "sample.py", line 5, in
driver.firstrun()
File "C:\Users\pier\Desktop\WhatsAPI-masterBuh\webwhatsapi_init_.py", line 68, in firstrun
qr = self.driver.find_element_by_css_selector(self._SELECTORS['qrCode'])
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 498, in find_element_by_css_selector
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 832, in find_element
'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .qrcode > img:nth-child(4)

How to fix it?

Not running on ubuntu server

Hi there,

I have just downloaded your API and tried to get them running on my Ubuntu server. Unfortunately without success. I'm new in Python and don't know, how i can fix this. Can you please help me?
Message in the console:
root@vps1446237:/home/WhatsAPI/sample# python sample.py waiting for QR Traceback (most recent call last): File "sample.py", line 4, in <module> driver = WhatsAPIDriver() File "/usr/local/lib/python2.7/dist-packages/webwhatsapi/__init__.py", line 58, in __init__ self.driver = webdriver.Firefox() # trying to add proxy support: webdriver.FirefoxProfile().set_proxy()) #self._PROXY)) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 154, in __init__ keep_alive=True) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 151, in __init__ self.start_session(desired_capabilities, browser_profile) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 240, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute self.error_handler.check_response(response) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status: 1

geckodriver.log
1507640594754 geckodriver INFO geckodriver 0.19.0 1507640594781 geckodriver INFO Listening on 127.0.0.1:57576 1507640595929 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.4Cra2gFpQhPB" Error: GDK_BACKEND does not match available displays

Thank you :)

What is wrong?

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/webwhatsapi-1.0.3-py2.7.egg/webwhatsapi/init.py", line 62, in init
self.driver = webdriver.Firefox(executable_path="/home/xxx/gecko/geckodriver") # trying to add proxy support: webdriver.FirefoxProfile().set_proxy()) #self._PROXY))
File "/usr/local/lib/python2.7/dist-packages/selenium-3.7.0-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 154, in init
keep_alive=True)
File "/usr/local/lib/python2.7/dist-packages/selenium-3.7.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 151, in init
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium-3.7.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 240, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium-3.7.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium-3.7.0-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status: 1

Not running on Windows Server

I know... Why windows :p.

I tried my app on Mac OS and it works good, but when I try to running on Windows server the function "view_unread()" backs empty :(

Help please :) and thanks

How can I send an image?

Hey , How can I send an Image, I was trying to found the correct function but it is really hard to find.

connection refuse

I am facing this issue after installing all the mention prerequisites.

C:\Users\AMIT>python E:\Python\WhatsAPI-master\sample.py
bot started!
Traceback (most recent call last):
File "E:\Python\WhatsAPI-master\sample.py", line 13, in
contacts = driver.view_unread();
File "E:\Python\WhatsAPI-master\webwhatsapp.py", line 152, in view_unread
Store = self.driver.execute_script(script)
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\site-package
s\selenium\webdriver\remote\webdriver.py", line 465, in execute_script
'args': converted_args})['value']
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\site-package
s\selenium\webdriver\remote\webdriver.py", line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\site-package
s\selenium\webdriver\remote\remote_connection.py", line 401, in execute
return self._request(command_info[0], url, body=data)
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\site-package
s\selenium\webdriver\remote\remote_connection.py", line 432, in _request
self._conn.request(method, parsed_url.path, body, headers)
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\http\client.
py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\http\client.
py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\http\client.
py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\http\client.
py", line 1026, in _send_output
self.send(msg)
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\http\client.
py", line 964, in send
self.connect()
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\http\client.
py", line 936, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\socket.py",
line 722, in create_connection
raise err
File "C:\Users\AMIT\AppData\Local\Programs\Python\Python36-32\lib\socket.py",
line 713, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the
target machine actively refused it

Error while driver instantiating

driver = WhatsAPIDriver("mkhase")

Traceback (most recent call last):
File "", line 1, in
File "webwhatsapi/init.py", line 58, in init
self.driver = webdriver.Firefox() # trying to add proxy support: webdriver.FirefoxProfile().set_proxy()) #self._PROXY))
File "/home/blackunicorn47/venvs/WhatsAPI/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 144, in init
self.service.start()
File "/home/blackunicorn47/venvs/WhatsAPI/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python2.7/subprocess.py", line 710, in init
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 20] Not a directory

skip QR code Auth

How to use the QR Code saved, to skip authentication every time I reboot?

Api need too many improvement

Hello ! Thank you for efforts , but i want to put some notes on this api

before anything the wiki must be updated and more detailed description must be added

Then this api is not an independent api , it depends on

-bs4
-setuptools
-selenium
-gecko web driver

So for beginners this will make headache to know that , so this might be deduced in the api

Then the api when look to find the "click to reload" it look for a full capital letter sentence when the sentence is just small and capital : "Click to reload QR code"

Then as i think their is some limitation about accessing global variable from the selenium proxy, we cannot access the Store variable and each time we ran the code this is the log and the error occured:

bot started
Traceback (most recent call last):
  File "Sample.py", line 8, in <module>
    contacts = driver.view_unread();
  File "/home/xxxxxxxx/python/whatsapp/WhatsAPI-master/webwhatsapp.py", line 156, in view_unread
    Store =  self.driver.execute_script(script)
  File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0b3-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 465, in execute_script
    'args': converted_args})['value']
  File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0b3-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium-3.0.0b3-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: TypeError: Store is undefined

I think something is changed in the web whatsapp integration and code since you wrote the code , also i think that this may be also a dependency issue

In conclusion hope you may review your wiki and code to provide a more stable api that can be used without problems, as of course some beginners will try to play with so it must be simpler and easier

Hope i was not hurting you by my notes , but really because i liked your work and i hope that it will be better i am written this issue

Hope we will hear it from you soon, and any help we are just ready .

Best regards !

Problem with WebWhatsAPI

Hey,
if I start my "script" then it stops at:
driver = WhatsAPIDriver()

The error message is:

C:\Python34\python.exe C:/Users/domen/PycharmProjects/HJBwwkjw/kjbjw.py
waiting for QR
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Python34\lib\subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "C:\Python34\lib\subprocess.py", line 1114, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/domen/PycharmProjects/HJBwwkjw/kjbjw.py", line 4, in <module>
    driver = WhatsAPIDriver()
  File "C:\Python34\lib\site-packages\webwhatsapi\__init__.py", line 58, in __init__
    self.driver = webdriver.Firefox()  # trying to add proxy support: webdriver.FirefoxProfile().set_proxy()) #self._PROXY))
  File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in __init__
    self.service.start()
  File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 


Process finished with exit code 1

I hope you can help me :)

Driver.firstrun() not saving QRcode

`from webwhatsapi import WhatsAPIDriver

driver = WhatsAPIDriver("mkhase")
driver.firstrun()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.4/dist-packages/webwhatsapi/init.py", line 70, in firstrun
EC.invisibility_of_element_located((By.CSS_SELECTOR, self._SELECTORS['qrCode'])))
File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

`
is there a way to scan QRcode remotely?

syntax error near unexpected token `('

If I run ./sample.py<
I'm getting the following error:
Error: no such file "waiting for QR"
./sample.py: line 4: syntax error near unexpected token ('
./sample.py: line 4: driver = WhatsAPIDriver()'`

I'm a newbie python coder :D help me with this json

Hello, i have a new function written by me in JS.
It return a json message and the python code give me an exception:

C:\Users\pier\Desktop\WhatsAPI-masterBuh>python sample.py waiting for QR bot started {\"receivedMsgs\":[{\"sender\":\"THENUMBEROFSENDER\",\"isMedia\":false,\"timestamp\":1507102943,\"message\":\"Ciao\"}]} Traceback (most recent call last): File "sample.py", line 19, in <module> data = json.loads(msgsReceived) File "C:\Python27\lib\json\__init__.py", line 339, in loads return _default_decoder.decode(s) File "C:\Python27\lib\json\decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python27\lib\json\decoder.py", line 380, in raw_decode obj, end = self.scan_once(s, idx) ValueError: Expecting property name: line 1 column 2 (char 1)

Now, i'll post all the code to reproduce this error

view_unread() is returning empty list

Hello,

I have successfully initiated the driver and done the firstrun() method
however, when I tried to use the view_unread() method it is returning an empty list
I have not been able to send message using send_to_phone_number, it is returning a False

What could be the problem? thanks!

edit:
After checking your code for a while
I found that firefox is logging "no", which mean the code doesnt detect any new message?

API chrashing

Hi,
Ive got a problem whilst updating to the newest version: When I create the callback it keeps crashing within seconds. One or two time messages are processed and then it keeps crashing with the following Message:
Traceback (most recent call last): File "run.py", line 115, in <module> driver.create_callback(callback) File "/home/xxx/Schreibtisch/WebWhatsAPI/webwhatsapi/__init__.py", line 284, in create_callback messages = self.get_unread() File "/home/xxx/Schreibtisch/WebWhatsAPI/webwhatsapi/__init__.py", line 222, in get_unread raw_message_groups = self.wapi_functions.getUnreadMessages(include_me, include_notifications) File "/home/xxx/Schreibtisch/WebWhatsAPI/webwhatsapi/wapi_js_wrapper.py", line 99, in __call__ raise JsException("Error in function {0} ({1}). Command: {2}".format(self.function_name, e.msg, command)) webwhatsapi.wapi_js_wrapper.JsException: Error in function getUnreadMessages (ReferenceError: none is not defined). Command: return WAPI.getUnreadMessages(false,false, arguments[0])
Any idea where the Problem is?

Unable to find a matching set of capabilities

Hi,

I am running sample.py on Amazon Linux AMI 2017.09.1 and install the package with "pip install -r requirements.txt". Then I download and set the geckodriver path and got following error when running. Any idea how to fix this?

waiting for QR
Traceback (most recent call last):
File "sample.py", line 4, in
driver = WhatsAPIDriver()
File "/home/WebWhatsAPI/webwhatsapi/init.py", line 66, in init
self.driver = webdriver.Firefox() # trying to add proxy support: webdriver.FirefoxProfile().set_proxy()) #self._PROXY))
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in init
keep_alive=True)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in init
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

Send image

Hi guys,
how can i send local images?
thanks

recent update and media files

I see that after the recent update many things have been improved, now is it possible to read images and media messages in an easier way? currently I can only work with text, but I need to get the images as well.

any1 can help with it?

WebWhatsAPI/webwhatsapi/objects/message.py

class MediaMessage(Message):

def save_media(self, path):
    extension = mimetypes.guess_extension(self.mime)
    filename = "{0}{1}".format(self["__x_filehash"], extension)

    with file(os.path.join(path, filename), "wb") as output:
        output.write(self.content.decode("base64"))

def __repr__(self):
    return "<MediaMessage - {type} from {sender} at {timestamp}>".format(
        type=self.type,
        sender=safe_str(self.sender.get_safe_name()),
        timestamp=self.timestamp
    )

Sample File

Hi,

I have no experience with Python. Would it be possible to share a sample file that can be directly run to register & send messages.

Thank you

base64 for image(miniature)

Hi, I'm running the api normally, it's all compliant, however I need to get the images that are sent to me, when it arrives some image as a message it comes in 'base64' when decoding it returns me the thumbnail of the image, there is some way , inside or outside of the class, do I get even those who 'base64' the uploaded image other than the thumbnail of it?

WebDriverException: Message: TypeError: messages[i].__x_body is undefined

Without fail my script throws a WebDriverException: Message: TypeError: messages[i].__x_body is undefined exception after it's been sitting there waiting for my callback function to be called. This usually happens within 5~10 minutes. It is not the case that my parse function is faulty. I can typically parse several messages before this exception is eventually thrown.

Can you shed some light on this?

Traceback (most recent call last):
  File "sample.py", line 27, in <module>
    main()
  File "sample.py", line 24, in main
    driver.create_callback(parse)
  File "/webwhatsapp.py", line 210, in create_callback
    messages = self.view_unread()
  File "/webwhatsapp.py", line 150, in view_unread
    Store = self.driver.execute_script(script)
  File "/whatsapp3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 491, in execute_script
    'args': converted_args})['value']
  File "/whatsapp3/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
    self.error_handler.check_response(response)
  File "/whatsapp3/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: TypeError: messages[i].__x_body is undefined

bag in send_message_to_phone_number.js

var user = Store.Contact.models.find(function (e) { return e.__x_id.search(contact)!=-1 });
change to:
var user = Store.Contact.models.find(function (e) { return e.__x_id ? e.__x_id.search(contact) != -1 : false });

QR code is Base64 not .png

Log:

waiting for QR
/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py:450: UserWarning: name used for saved screenshot does not match file type. It should end with a .png extension
"type. It should end with a .png extension", UserWarning)

What is the best way of getting around this? Thank you.

echo bot example

Hello, I really liked this API , but I want to ask if you could create an example of a simple echo bot to see how it works , in the api because it looks great , I expect an answer , wonderful job

Updates

First, thanks for the API, I think it's very usefull (y)

I starting to development something in my job, I all ready use your API :) ๐Ÿ‘. For now it works for us, but I'm worry about scalable feature, I can see that you are working on it. I would really appreciate that you have big plans for this.

I what to be with you when I grow up ๐Ÿฅ‡
Thanks again ๐Ÿ‘

Get contact list

Hi guys, exist some way to get the cell numbers of my contact list? Something like the getgroups function but to my contact list.

Whatsapp cloud

Whatsapp cloud(A service): User can access and send messages from anywhere without scanning qr anymore, just simple user login and password

how does it work? how to implement login and password?

Connection refused

After calling driver = WhatsAPIDriver("mkhase") I got:

Traceback (most recent call last):
File "", line 1, in
File "/home/ramon/miniconda3/envs/whats/lib/python2.7/site-packages/webwhatsapi/init.py", line 58, in init
self.driver = webdriver.Firefox() # trying to add proxy support: webdriver.FirefoxProfile().set_proxy()) #self._PROXY))
File "/home/ramon/miniconda3/envs/whats/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in init
keep_alive=True)
File "/home/ramon/miniconda3/envs/whats/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in init
self.start_session(desired_capabilities, browser_profile)
File "/home/ramon/miniconda3/envs/whats/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/ramon/miniconda3/envs/whats/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "/home/ramon/miniconda3/envs/whats/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

OS: Ubuntu Server 16.04.3
Python: 2.7

API "lagged"

Hello I'm trying to run this example with python35 and python27
but the problem is the api freezes at while sometimes, and take long to display messages...

What I tried:

Running in Windows...

  • python2.7
  • python3.5
import time
from webwhatsapi import WhatsAPIDriver
print "waiting for QR"
driver = WhatsAPIDriver(username="mkhase")
#driver.firstrun()
driver.view_unread()
print "bot started"
while True:
    time.sleep(1)
    print('checking for more messages')
    for contact in driver.view_unread():
        for message in contact[u'messages']:
            msg = message['message'].encode('ascii', 'ignore').decode('ascii')
            print(msg)

log in screen



checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking for more messages
checking

frozes here, and have alot of msg to display...

Help!

Mukulhase pls send me a emailadress from you. I really need to speak with you.

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.