在电报组中关注用户的消息

问题描述:

每当用户在大型电报组中发布新消息时,我都需要得到通知.最好的方法是什么?有没有现成的机器人或方法?例如,我可以创建一个新频道,其帖子是该用户的帖子吗?

I need to get notified whenever a user posts a new message in a large telegram group. What is the best way to do that? Is there any ready bot or method for this? for example can I make a new channel which its posts are posts of that user?

你要做的是收听来自该聊天(组)的传入消息更新 -> 仅过滤用户发送的消息 -> 转发该消息到特定频道.

What you've to do is to listen to incoming message updates from that chat(group) -> Filter only these sent by the user -> forward that message to a specific channel.

这是 telethon 中的工作示例代码:

Here is a working sample code in telethon:

from telethon import TelegramClient, events

API_ID = ...
API_HASH = " ... "

BOT_TOKEN = " ... "

client = TelegramClient('session', api_id=API_ID, api_hash=API_HASH).start(bot_token=BOT_TOKEN)

@client.on(events.NewMessage(
    chats=" ... ",  # insert group username here
    from_users=" ..."  # insert a user to monitor here
))
async def _(event):
    await event.message.forward_to(" ... ") # insert the username for the receiver chat/channel

with client:
    client.run_until_disconnected()

您可以从 https 中找到 API_IDAPI_HASH 值://my.telegram.org.

You can find the API_ID and API_HASH values from https://my.telegram.org.

另外在这里阅读 Telethon 的文档,如果您想添加/修改行为.

Also read telethon's Documentation here if you wish to add/modify the behavior.