Skip to content

Instantly share code, notes, and snippets.

@deedy
Last active July 17, 2022 00:59
Show Gist options
  • Save deedy/6854f64e63909d0671f434fad7683450 to your computer and use it in GitHub Desktop.
Save deedy/6854f64e63909d0671f434fad7683450 to your computer and use it in GitHub Desktop.
Telegram Bot to notify about photos
#!/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