wa-automate-python icon indicating copy to clipboard operation
wa-automate-python copied to clipboard

Issue with Reading Unread Messages & Marking them as Read

Open KarthikAbiram opened this issue 4 years ago • 1 comments

I am trying to read unread messages using the below code. I did not get any messages with the default arguments for the 'get_unread' method. But by passing 'use_unread_count', I am able to get the list of unread messages. But one issue is, it doesn't mark these chat messages as 'read' in mobile (it does get marked as read in browser view). So, when I rerun below code, it again returns the older messages.

from openwa import WhatsAPIDriver, MessageGroup
import time

driver = WhatsAPIDriver()

print("Waiting for QR")
while not driver.wait_for_login():
    time.sleep(3)

print("Bot started")

print("Getting Existing Unread Messages..")

# # Get Unread Messages
message_groups = driver.get_unread(use_unread_count=True)
print(message_groups)
for i,message_group in enumerate(message_groups):
    for j,msg in enumerate(message_group.messages):
        print(f'Message {j}: {msg}')
        # Mark Chat as Read
        driver.chat_send_seen(msg.chat_id)
        try:
            print(f'Message Content is: {msg.content}')
        except:
            pass

print('Bot stopped')

Instead of using the code, if I manually click a chat in the launched browser window, it does get marked as read in both browser and mobile. Is there anyway I can mark the chat as read in mobile as well, so that the messages don't get returned during the next run.

OS: Windows 10 Python: 3.7.9 64-bit openwa: 1.3.16 (installed using pipenv) Browser: Firefox using gecko driver

PS: I also tried "driver.chat_send_seen(msg.chat_id)", but that didn't help in marking the chat as read in mobile.

KarthikAbiram avatar Jan 22 '22 08:01 KarthikAbiram

I see this is an issue and the reason is that 'wait_for_login' is no longer available to use in the latest version codebase.

Fix for this:

import time

while not driver.is_logged_in():
    print("Waiting for login...")
    time.sleep(2)

print("Successfully logged in")

IsJn-227 avatar Jun 21 '25 07:06 IsJn-227