Kalebu / alright

Python wrapper for WhatsApp web-based on selenium
https://www.youtube.com/watch?v=yitQTt-NukM
MIT License
376 stars 113 forks source link

Can we me have method to fetch all unread chat usernames ? #70

Closed Kalebu closed 2 years ago

Kalebu commented 2 years ago

I am just thinking out loud that can we have a method to fetch all unread chat usernames, This will be very useful when it comes to creating auto-response functionality @euriconicacio

euriconicacio commented 2 years ago

Absolutely! Working on it as 1st priority, it may be delivered by tomorrow. We'll basically iterate through chats adapting search_chat_by_name and use check_if_given_chat_has_unread_messages on them. 🙃

euriconicacio commented 2 years ago

@Kalebu, I just created fetch_all_unread_chats and pushed it into main. Please, lmk if you find any issues, it works nicely here, given a couple of natural limitations for a large number of chats (500+) - adding the possibility to limit it was a plus! Closing this, but feel free to open another one if you feel like doing it.

Kalebu commented 2 years ago

Hi @euriconicacio

I just tried the fetch_all_unread_chats method but it s throwing up an error as shown in the snippet below, can you please have a close look at what might be causing this.

>>> messenger.fetch_all_unread_chats(limit=True, top=5)
2022-06-18 15:19:27,979 - root -- [ERROR] >> Exception raised while getting first chat: Message: element not interactable
  (Session info: chrome=96.0.4664.45)

Thank you : @euriconicacio

euriconicacio commented 2 years ago

Absolutely weird. It appears that somehow the element is interactible to me and not to you - that probably happens when sending the PAGE_DOWN key to the div; I'd have to check this abnormal behavior. 🤔

euriconicacio commented 2 years ago

Just confirmed, @Kalebu: can't reproduce it here (suppressed phone numbers and chats/groups names) and I'm using messenger.fetch_all_unread_chats(limit=True, top=30) at the same script I showed you:

stuff/gg_message on  main [?] 🐍 stuff (stuff)
❯ python whatsapp_msg.py sendmessage --not-dry

[WDM] - ====== WebDriver manager ======
[WDM] - Current google-chrome version is 102.0.5005
[WDM] - Get LATEST chromedriver version for 102.0.5005 google-chrome
[WDM] - Driver [/Users/euriconicacio/.wdm/drivers/chromedriver/mac64/102.0.5005.61/chromedriver] found in cache
2022-06-18 17:20:55,071 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:55,256 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:55,372 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:55,542 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:55,722 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:55,907 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:56,070 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:56,330 - root -- [INFO] >> Yup, 3 new message(s) on chat "********".
2022-06-18 17:20:56,595 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:56,799 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:57,016 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:57,291 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:57,535 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:57,883 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:58,161 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:58,443 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:58,717 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:59,021 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:59,337 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:20:59,684 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:00,028 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:05,178 - root -- [INFO] >> The counter value at this chunk is: 21.
2022-06-18 17:21:05,231 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:05,310 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:05,399 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:05,500 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:05,616 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:05,744 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:05,881 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:06,034 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:06,364 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:06,566 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:06,770 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:06,988 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:07,203 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:07,435 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:07,655 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:07,904 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:08,171 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:08,483 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:08,766 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:09,063 - root -- [INFO] >> There are no new messages on chat "********".
2022-06-18 17:21:14,197 - root -- [INFO] >> The list of unread chats, considering the first 33 messages, is: ['********'].
(stuff) 

I'll investigate under which circumstances an element could be interactable for one user and not for another.

Btw, I see you're using Chrome Version 96.0.4664.45 and I'm using Chrome Version 102.0.5005.115 (Official Build) (x86_64). Could you try to update that and retry, please, @Kalebu?

I mean, not ideal to deliver functionality to the most updated version of a browser, but it would point to a solution path and we could add a disclaimer to the code.

Edit: added a temporary disclaimer to the README and to the init.