Skip to content

Instantly share code, notes, and snippets.

@carmebar
Created June 6, 2018 07:03
Show Gist options
  • Save carmebar/b7deb2cd19d3b7ac5b68ceada42e3fb8 to your computer and use it in GitHub Desktop.
Save carmebar/b7deb2cd19d3b7ac5b68ceada42e3fb8 to your computer and use it in GitHub Desktop.
Uses Telethon to create a Telegram Client and forward messages silently from any entities (Channels, Groups or Users) to any other entities.
from telethon import TelegramClient, events
#/////
# Get list of ids from the "Dialogos" list printed after logging
entity_ids = []
to_ids = []
# Register an APP in https://my.telegram.org/
api_id = 0
api_hash = ""
#/////
client = TelegramClient('session_name', api_id, api_hash, update_workers=1, spawn_read_thread=False)
client.start()
print("Dialogs:")
dialogs = client.get_dialogs()
for d in dialogs:
print("\t", d.title, ":", d.entity.id)
if len(entity_ids) == 0:
print("Remember to set the 'entity' and 'to' ids. Check the dialog list.")
@client.on(events.NewMessage)
def newMessage(event):
if (event.chat.id in entity_ids):
for eid in to_ids:
entity = client.get_input_entity(eid)
client.send_message(entity, event.raw_text)
client.idle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment