open-wa / wa-automate-python

💬 🤖 The most advanced Python whatsapp library for chatbots with advanced features. Be sure to ⭐ this repository for updates!
Other
330 stars 71 forks source link

A lot of things broke after yesterday's Whatsapp Web update #68

Closed Yuvix25 closed 3 years ago

Yuvix25 commented 3 years ago

After yesterday's update, I cannot get chat by name, get unread messages from chat, and probably more.
This is my code to get chat by name:

self.driver = WhatsAPIDriver(client="chrome")

self.driver.wait_for_login(timeout=20000)

# Save image to file
self.driver.get_qr()

# Get image in base64 
self.driver.get_qr_base64()
self.groups = []
for name in self.group_names:
    self.groups.append(self.driver.get_chat_from_name(name))

And the error is:

Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\site-packages\openwa\wapi_js_wrapper.py", line 165, in __call__
    return self.driver.execute_async_script(command)
  File "C:\Program Files\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 657, in execute_async_script
    return self.execute(command, {
  File "C:\Program Files\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response   
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: javascript error: window[(_0x35a243(...) + "I")][(_0x35a243(...) + _0x35a243(...) + _0x35a243(...) + "ts")](...)[(_0x35a243(...) + "d")] is not a 
function
JavaScript stack:
TypeError: window[(_0x35a243(...) + "I")][(_0x35a243(...) + _0x35a243(...) + _0x35a243(...) + "ts")](...)[(_0x35a243(...) + "d")] is not a function
    at Object.window.<computed>.<computed> [as getChatByName] (eval at executeScript (:480:16), <anonymous>:3:248625)
    at eval (eval at executeAsyncScript (:556:26), <anonymous>:3:54)
    at Object.window.WAPI.pyFunc (eval at executeScript (:480:16), <anonymous>:2154:23)
    at eval (eval at executeAsyncScript (:556:26), <anonymous>:3:38)
    at eval (eval at executeAsyncScript (:556:26), <anonymous>:3:97)
    at executeAsyncScript (<anonymous>:556:47)
    at <anonymous>:571:29
    at callFunction (<anonymous>:450:22)
    at <anonymous>:464:23
    at <anonymous>:465:3
  (Session info: chrome=89.0.4389.114)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "path to main file", line 174, in <module>
    whatsappBot = WhatsAppBot(["chat name"])
  File "path to main file", line 39, in __init__
    self.groups.append(self.driver.get_chat_from_name(name))
  File "C:\Program Files\Python38\lib\site-packages\openwa\__init__.py", line 424, in get_chat_from_name
    chat = self.wapi_functions.getChatByName(chat_name)
  File "C:\Program Files\Python38\lib\site-packages\openwa\wapi_js_wrapper.py", line 173, in __call__
    raise JsException(
openwa.wapi_js_wrapper.JsException: Error in function getChatByName (javascript error: window[(_0x35a243(...) + "I")][(_0x35a243(...) + _0x35a243(...) + _0x35a243(...) + "ts")](...)[(_0x35a243(...) + "d")] is not a function
JavaScript stack:
TypeError: window[(_0x35a243(...) + "I")][(_0x35a243(...) + _0x35a243(...) + _0x35a243(...) + "ts")](...)[(_0x35a243(...) + "d")] is not a function
    at Object.window.<computed>.<computed> [as getChatByName] (eval at executeScript (:480:16), <anonymous>:3:248625)
    at eval (eval at executeAsyncScript (:556:26), <anonymous>:3:54)
    at Object.window.WAPI.pyFunc (eval at executeScript (:480:16), <anonymous>:2154:23)
    at eval (eval at executeAsyncScript (:556:26), <anonymous>:3:38)
    at eval (eval at executeAsyncScript (:556:26), <anonymous>:3:97)
    at executeAsyncScript (<anonymous>:556:47)
    at <anonymous>:571:29
    at callFunction (<anonymous>:450:22)
    at <anonymous>:464:23
    at <anonymous>:465:3
  (Session info: chrome=89.0.4389.114)). Command: return WAPI.pyFunc(()=>WAPI.getChatByName('chat name'), arguments[0])

And if I try to get chat by ID it works, but then once a new message appears this error shows up (I have checked and js_obj is an empty dictionary):

Traceback (most recent call last):
  File "path to main file", line 175, in <module>        
    whatsappBot.start_bot()
  File "path to main file", line 158, in start_bot       
    for message in group.get_unread_messages(include_me=True):
  File "C:\Program Files\Python38\lib\site-packages\openwa\objects\whatsapp_object.py", line 18, in wrapped      
    return func(self, *args, **kwargs)
  File "C:\Program Files\Python38\lib\site-packages\openwa\objects\chat.py", line 80, in get_unread_messages     
    return list(self.driver.get_unread_messages_in_chat(
  File "C:\Program Files\Python38\lib\site-packages\openwa\__init__.py", line 614, in get_unread_messages_in_chat
    unread = [factory_message(message, self) for message in messages]
  File "C:\Program Files\Python38\lib\site-packages\openwa\__init__.py", line 614, in <listcomp>
    unread = [factory_message(message, self) for message in messages]
  File "C:\Program Files\Python38\lib\site-packages\openwa\objects\message.py", line 28, in factory_message      
    if js_obj["isMedia"]:
KeyError: 'isMedia'

This is my code for getting unread messages:

while True:
    time.sleep(3)
    index = 0
    for group in self.groups:
        for message in group.get_unread_messages(include_me=True):
            if isinstance(message, Message):
                try:
                    self.parse_message(message, index)
                except Exception as e:
                    print(e)
        index += 1

I am running on Windows 10 Pro, Python 3.8.5 64 bit and tried installing using both pip and directly from GitHub.

erickythierry commented 3 years ago

this project is abandoned, many errors accumulating and without update for months. I have already corrected several errors and features manually in my code, but there are always others. I am migrating my bots to the project in JS that is much more active. I suggest doing the same

edit: I am not criticizing the creators, I know that it is not easy to maintain a repository for an unofficial service

mrodal commented 3 years ago

Hi, this repo is more of a python interface for the core wapi file that is in the nodejs repo. Thats why this one is not as active, but I try to keep it working when there are breaking changes on whatsapp or the core api.

Sometimes it could be that WP made breaking changes and the core api is temporarily broken, but after it is fixed, it should be working again from python as well.

Im currently looking to fix this issue, which seems a like a initialization error

mrodal commented 3 years ago

Its fixed, please try again and let me know if you still get it. No need to download any new version, it was fixed from the other repo