简体   繁体   中英

read a direct message when arrival using telegram_api

i am working with an app and it needs to read direct messages from telegram when they arrive.

i searched on google but all i got was how to send a message not how to read brand new dms. Thanks!

Telethon: Make sure you read the basics in the Docs to understand how to handle events.

I'm assuming you meant "mark as read", if not, read the docs, else read below:

in the event object you get to your callback, you have multiple unique convenience methods, and all the ones available on a Message object, one of them is event.mark_read()

to limit it only to send read requests to private chats; configure handler as needed, a minimal example:

@client.on(events.NewMessage(func=lambda e: e.is_private))
async def read_it_callback(event):
    await event.mark_read()

you can also use client. send_read_acknowledge()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM