【问题标题】:How to detect if my messages on telegram is already read using telethon?如何检测我在电报上的消息是否已使用 Telethon 阅读?
【发布时间】:2021-04-07 20:25:48
【问题描述】:

我使用 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

【问题讨论】:

    标签: python telegram telethon


    【解决方案1】:

    使用GetPeerDialogsRequest()获取您发送messageDialog,然后如果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')
    

    【讨论】:

    • 谢谢,GetPeerDialogsRequest() 函数正在完成它的工作:)
    猜你喜欢
    • 1970-01-01
    • 2019-04-07
    • 1970-01-01
    • 2022-12-16
    • 2017-11-20
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    • 2021-10-12
    相关资源
    最近更新 更多