Skip to content

Instantly share code, notes, and snippets.

@xuewei4d
Created September 18, 2020 03:54
Show Gist options
  • Save xuewei4d/222346de1a05320676830c72bf3a387c to your computer and use it in GitHub Desktop.
Save xuewei4d/222346de1a05320676830c72bf3a387c to your computer and use it in GitHub Desktop.
telegram app which just forwards messages
from telethon.sync import TelegramClient, events
api_id= ''
api_hash = ''
mvp_usernames = ['abcd']
source_channel_id = 9999 # # set source channel id here
dest_channel_id = 9999 # set dest channel id here
with TelegramClient('name', api_id, api_hash) as client:
@client.on(events.NewMessage(chats=source_channel_id))
async def handler(event):
sender = await event.get_sender()
if sender.username in mvp_usernames and event.raw_text.strip() != '':
await client.send_message(dest_channel_id, '{}: {}'.format(sender.first_name, event.raw_text))
client.run_until_disconnected()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment