【问题标题】:Forward incoming messages from Telegram to another chat将来自 Telegram 的传入消息转发到另一个聊天室
【发布时间】:2018-08-10 17:43:51
【问题描述】:

我正在尝试使我从聊天(聊天 A)收到的所有消息自动转发到另一个聊天(聊天 B)。我不是 Chat A 的管理员。我一直在研究这个问题,但我不明白 Telegram Bot 怎么可能,如果我错了,请纠正我。基本上我需要一种方法来读取我的电报帐户上的所有传入消息。

【问题讨论】:

  • 您使用哪种编程语言?
  • 我正在使用 python 3

标签: python telegram


【解决方案1】:

我想通了。当收到或发送新消息时,会自动调用 my_event_handler

if '1113462530' in str(event): 这一行主要是查看消息是否来自特定聊天 1113462530(这是聊天 id),如果是,则将消息发送到 PERSON_NAME

import asyncio
from telethon import TelegramClient, events

api_id = 1234
api_hash = 'abc123'

client  = TelegramClient('session_id', api_id, api_hash)
client.start()

@client.on(events.NewMessage)
async def my_event_handler(event):
    if '1113462530' in str(event):
        await client.send_message('PERSON_NAME', event.raw_text)

client.run_until_disconnected()

【讨论】:

    猜你喜欢
    • 2017-06-10
    • 1970-01-01
    • 2015-12-01
    • 2022-12-21
    • 2021-06-07
    • 2014-10-31
    • 2018-04-07
    • 2021-12-12
    • 2017-10-03
    相关资源
    最近更新 更多