英文:
read a direct message when arrival using telegram_api
问题
我正在使用一个应用程序,它需要在Telegram上接收直接消息时进行阅读。
我在Google上搜索了一下,但所有我找到的都是如何发送消息,而不是如何阅读全新的直接消息。
谢谢!
英文:
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!
答案1
得分: 1
Telethon: 请确保你阅读了文档中的基础部分,以了解如何处理事件。
我假设你是指"标记为已读",如果不是,请阅读文档,否则请继续阅读以下内容:
在事件对象中,你可以获得多个独特的便捷方法,以及所有在Message
对象上可用的方法之一是event.mark_read()
。
要将其限制为仅向私人聊天发送已读请求,请根据需要配置处理程序,以下是一个最小示例:
@client.on(events.NewMessage(func=lambda e: e.is_private))
async def read_it_callback(event):
await event.mark_read()
你还可以使用client.[
send_read_acknowledge()](https://docs.telethon.dev/en/stable/modules/client.html#telethon.client.messages.MessageMethods.send_read_acknowledge)
。
英文:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论