微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何检测我的电报消息是否已使用 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')

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。