在电报组中关注用户的消息 [英] Following messages of a user in telegram group

查看:67
本文介绍了在电报组中关注用户的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于在电报组中关注用户的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆