-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_telethon.py
38 lines (24 loc) · 945 Bytes
/
main_telethon.py
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
33
34
35
36
37
38
from telethon import TelegramClient, events, sync
# These example values won't work. You must get your own api_id and
# api_hash from https://my.telegram.org, under API Development.
api_id = 12345
api_hash = '0123456789abcdef0123456789abcdef'
# tutorial - https://pypi.org/project/Telethon/
# Creating a client
client = TelegramClient('session_name', api_id, api_hash)
client.start()
# Doing stuff
print(client.get_me().__str__())
username = '@ell70_bot'
client.send_message(username, 'Hello! Talking to you from Telethon')
# client.send_file('username', '/home/myself/Pictures/holidays.jpg')
# client.download_profile_photo('me')
messages = client.get_messages(username)
print(messages)
# messages[0].download_media()
# @client.on(events.NewMessage(pattern='(?i)hi|hello'))
# async def handler(event):
# await event.respond('Hey!')
# await event.reply('Hi!')
# await event.get_chat()d
client.run_until_disconnected()