-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
32 lines (24 loc) · 831 Bytes
/
Copy pathmain.py
File metadata and controls
32 lines (24 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
from dotenv import load_dotenv
load_dotenv()
from telethon import TelegramClient, events
api_id = os.getenv("API_ID")
api_hash = os.getenv("API_HASH")
client = TelegramClient(os.getenv("SESSION_NAME"), api_id, api_hash)
print("Client Starting...")
# Log in to your account
client.start()
print("Client Created")
# Source and target channels
source_channel_id = int(os.getenv("FROM_CHANNEL_ID"))
target_channel_id = int(os.getenv("TO_CHANNEL_ID"))
print("Channels Loaded")
# keep getting all live messages from source channel
@client.on(events.NewMessage(chats=source_channel_id))
async def handler(event):
print(event.message)
# send message to target channel
await client.send_message(target_channel_id, event.message)
print("Message Sent")
# run until disconnect
client.run_until_disconnected()