Created
November 9, 2021 10:02
-
-
Save Ninjanaut/e80a0a769f19bb62b4e34b5220447a38 to your computer and use it in GitHub Desktop.
Telegram Telethon API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from telethon import TelegramClient, events | |
api_id = 123456 | |
api_hash = '<someHash>' | |
channel = '@someChannel' | |
client = TelegramClient('session', api_id, api_hash) | |
@client.on(events.NewMessage(chats=channel)) | |
async def my_event_handler(event): | |
print(event.text) | |
client.start() | |
client.run_until_disconnected() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from telethon.sync import TelegramClient, events | |
from telethon.tl.functions.messages import GetHistoryRequest | |
api_id = 123456 | |
api_hash = '<someHash>' | |
channel = '@someChannel' | |
client = TelegramClient('session', api_id, api_hash) | |
client.start() | |
for message in client.get_messages(channel, limit=10): | |
print(message.message) | |
client.run_until_disconnected() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment