使用Telegram API,在到达时读取直接消息。

huangapple go评论70阅读模式
英文:

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()

huangapple
  • 本文由 发表于 2023年1月8日 23:22:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75048953.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定