Reputation: 121
How do I forward a message to another chat as soon as I receive it from a contact? I created this example just to test routing, but it doesn't work.
#!/usr/local/bin/python3
from telethon import TelegramClient, events
api_id = 9999900
api_hash = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
client = TelegramClient('session_name', api_id, api_hash)
client.start()
@client.on(events.NewMessage)
async def main(event):
await client.send_message('Other People', 'Hello!') #Don't work. Keeps waiting forever
with client:
client.run_until_disconnected()
Upvotes: 8
Views: 14193
Reputation: 728
@client.on(events.NewMessage)
async def main(event):
await client.forward_messages(entity, event.message)
This code will work for forwarding new messages.
You can simply put chat_id
of target user in place of entity
Upvotes: 17