mukulhase / WebWhatsapp-Wrapper

An API for sending and receiving messages over web.whatsapp [Working as of 18th May 2018]
https://webwhatsapi.readthedocs.io/en/latest/
MIT License
2.04k stars 795 forks source link

HOWTO Mark messages as "read" #129

Closed jinfeei closed 6 years ago

jinfeei commented 6 years ago

Hi, while running the echo sample, I noticed the messages are not marked as "read" (double blue ticks). How can this be done?

Also I think the async_echo.py sample is not working on Windows platform. It threw some kind of NotImplementedError exception, because I think the implementation of asyncio is different on Windows platform?

File "D:/PycharmProjects/WhatsAppWeb/sample/async_echo.py", line 48, in start loop.add_signal_handler(SIGINT, stop) File "C:\Users\XXXX\AppData\Local\Programs\Python\Python36-32\lib\asyncio\events.py", line 499, in add_signal_handler raise NotImplementedError NotImplementedError

Tschipp commented 6 years ago

This may not be exactly what you're looking for, but if you directly execute this script using the driver, it will mark the messages as read:

var originalID = Store.Chat.models[0].id; 
Store.Chat.models[0].id = arguments[0]; 
Store.Chat.models[0].sendSeen(); 
Store.Chat.models[0].id = originalID;

The arguments[0] is the chatID of the Chat that you want to mark as read.

tapankumar commented 6 years ago

@Tschipp : I am using echo.py example and unable to understand where should i put your provided sample code.

Can you please help?


import time
from webwhatsapi import WhatsAPIDriver
from webwhatsapi.objects.message import Message
import requests

driver = WhatsAPIDriver(loadstyles=True,profile="/Users/tapankumarthapa/Library/Application Support/Firefox/Profiles/2qw4xd77.xxxxxxx")
print("Waiting for QR")
driver.wait_for_login()

print("Bot started")
wa_server_number = 'xxxxxx'

while True:
    time.sleep(3)
    print('Checking for more messages')
    for contact in driver.get_unread():
        for message in contact.messages:
            if isinstance(message, Message):  # Currently works for text messages only.
                print("Phone:" + message.sender.id + "Message:" + message.content)
                requests.post('http://xxxxxxxx/api/wa_receive', data={'wa_number': message.sender.id,
                                                               'wa_message': message.content,
                                                               'wa_type': 'text',
                                                               'wa_server_number': wa_server_number})
                #contact.chat.send_message(message.safe_content)

~~~python
jinfeei commented 6 years ago

@Tschipp thank you...

chriso0710 commented 6 years ago

You might also want to try

https://github.com/mukulhase/WebWhatsapp-Wrapper/blob/9a87f5d69bad42f7d5b4677a179b09df959c3b62/webwhatsapi/__init__.py#L453

Would be great if you could post working code here after testing.

Tschipp commented 6 years ago

I have an update: This code seems to be working better:

var chat = Store.Chat.get(arguments[0]);  
chat.sendSeen();
chat.markSeen(); 

You would need to call this JS code directly from the selenium webdriver. arguments[0] is the id of the chat that you want to mark as read.

kevinkit commented 6 years ago

Duplicate of #73