alexander-akhmetov / python-telegram

Python client for the Telegram's tdlib
MIT License
610 stars 122 forks source link

[Question] A way to understand if a message has been read (given the message_id and the chat_id) #400

Closed asarubbo closed 1 year ago

asarubbo commented 1 year ago

Hello,

I didn't understand at all if is possible to have info about a message (if it was read or not).

On stackoverflow a user says that tdlib is able to do that, but when I call get_message I don't see an interactionInfo field.

I can see something related in the scheme but I still don't understand if is possible to get that info or not, and If I can do something via python-telegram. If you have an example it would be great. Thanks

alexander-akhmetov commented 1 year ago

Hi,

I'll have a look a bit later, but in theory if tdlib returns the field it should be in the dictionary that get_message returns.

alexander-akhmetov commented 1 year ago

I'm not sure how to get that directly, actually. get_message indeed does not have this information.

I added a handler for updateMessageInteractionInfo and it works only when a reaction is added to the message. An emoji for example. You can check this by adding it to the existing send_message example

import time

...

def update_message_interaction_info(update):
    print(f'Received updateMessageInteractionInfo: {update}')
    ...

tg.add_update_handler('updateMessageInteractionInfo', update_message_interaction_info)

...

message_has_been_sent.wait(timeout=60)
print(f'Message has been sent.')

# sleep to allow the receiver to add a reaction to the message
time.sleep(300)

tg.stop()

What I also found is this issue: https://github.com/tdlib/td/issues/1878. If you send a message, then call get_chat, you get back an object with last_read_inbox_message_id and last_read_outbox_message_id. You can compare them with the message id that you received from the server in update_message_send_succeeded_handler (same send_message.py example).

alexander-akhmetov commented 1 year ago

Please, reopen the issue if you have more questions.