twitter - 制作一个简单的电报转发机器人
问题描述
我是一名试图为电报制作机器人的学生。我已经用谷歌试过了,但我真的很难做到。我想做的是两个机器人,帮助我收集信息。
从电报频道或群组(我不是主持人)自动转发到我的频道或群组
从推特自动转发到我的电报,但在过滤我设置的关键字后转发
我已经尝试过 IFTTT,但没有解决方案可以将频道转发到频道,并在从 twitter 转发时过滤关键字。
谢谢 :)
解决方案
您应该使用 MTPROTO 来访问 Telegram API 的全部潜力,因为机器人是真正 MTPROTO API 的有限版本,它们不会为您的工作(即爬行)提供全部潜力。
那里有一个好的 MTPROTO 库是用 python 编写的,它被称为Telethon。
你可以从这个用 Telethon 编写的源代码中得到一个想法:
api_id = "YOUR API ID HERE"
api_hash = "YOUR API HASH HERE"
client = TelegramClient(session_name, api_id, api_hash)
client.start()
to_copy_groups = {
from_group_id_here: to_group_id_here,
}
@client.on(event=events.NewMessage)
async def message_handler(event):
from_id = None
chat_type = None
if isinstance(event.peer_id, PeerChat):
from_id = event.peer_id.chat_id
chat_type = "Chat"
elif isinstance(event.peer_id, PeerChannel):
from_id = event.peer_id.channel_id
chat_type = "Channel"
if from_id is not None and from_id in to_copy_groups:
if to_copy_groups[from_id] in groups:
if chat_type == "Chat":
await event.forward_to(PeerChat(to_copy_groups[from_id]))
if chat_type == "Channel":
await event.forward_to(PeerChannel(to_copy_groups[from_id]))
return
推荐阅读
- php - 引发未定义变量通知的奇怪情况
- javascript - 将 Excel 文件单元格值读取为 HTML
- php - 使用 NetSuite PHP SDK 时排序交易搜索结果
- sql-server - 您如何处理 xml 列并使用 MSSQL 检查每个 xml 条目?
- arduino - 重载 'begin(int)' 的调用不明确
- reactjs - React.js 导出异步函数
- git - 拉动期间是否可以从遥控器使用“.gitignore”?
- plot - scipy的指数衰减只是给出阶跃函数
- python-3.x - 我没有找到我想要的元素
- django - 在 GKE 上使用 Django 处理长文件上传