Last active
July 17, 2022 00:59
-
-
Save deedy/6854f64e63909d0671f434fad7683450 to your computer and use it in GitHub Desktop.
Telegram Bot to notify about photos
This file contains 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
#!/usr/bin/env python3 | |
from cgi import test | |
import os | |
from telethon import TelegramClient, events | |
session = os.environ.get('TG_SESSION', 'printer') | |
# 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 = # REPLACE ME | |
api_hash = # REPLACE ME | |
NEWACCNT = # REPLACE ME | |
proxy = None # https://github.com/Anorov/PySocks | |
client = TelegramClient(session, api_id, api_hash, proxy=proxy).start() | |
@client.on(events.NewMessage()) | |
async def handler(event): | |
if event.photo: | |
text = event.text | |
if not text: | |
text = "PHOTO!!!" | |
print(text) | |
await client.send_message(NEWACCNT, text, file=event.photo) | |
try: | |
print('(Press Ctrl+C to stop this)') | |
client.run_until_disconnected() | |
finally: | |
client.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment