如何检测我的电报消息是否已使用 Telethon 读取?

问题描述

我使用 Telethon 通过电报向我的联系人发送了多条消息,但我没有使用此事件来知道它们是否被直接读取,因此我想检查是否使用其他方法读取了我的消息


@client.on(events.MessageRead)
async def handler(event):
    # Log when someone reads your messages
    print('Someone has read all your messages until',event.max_id)

我阅读了完整的文档,但我找不到答案,是否可以使用其 ID 作为示例来了解消息是否已被读取? cz 即使我调用了 get_dialogs() 函数,它也给了我最后一条消息的 ID,而不是用户最后读取的消息作为给定的评论 here

解决方法

使用 GetPeerDialogsRequest() 获取您发送 Dialogmessage,然后如果 read_outbox_max_id 属性等于或高于 message.id,则消息具有已阅读。

chat = 'INSERT_CHAT'
msg_id = (await client.send_message(chat,'YOUR_TEXT')).id

# get the Dialog where you sent the message
result = await client(functions.messages.GetPeerDialogsRequest(
        peers=[chat]
    ))
# check if the message has been read    
if result.dialogs[0].read_outbox_max_id >= msg_id:
    print('the message has been read')
else:
    print('the message has not been read yet')