简体   繁体   中英

Forward incoming messages from Telegram to another chat

I am trying to make all the messages I receive from a chat (Chat A) automatically forward to another chat (Chat B). I am not the admin of Chat A. I've been looking into this for a while, but I don't see how its possible to do with Telegram Bot, correct me if I'm wrong. Basically I need a way to read in all incoming messages on my Telegram account.

I figured it out. When a new message is either received or sent my_event_handler is called automatically.

if '1113462530' in str(event): this line basically is looking if the message came from a specific chat 1113462530 (this is the chat id), and if it did a message is sent to 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM