Reputation: 1183
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.
Upvotes: 1
Views: 2760
Reputation: 1183
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()
Upvotes: 1