2017-10-24 22:32:31 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# A simple script to print all updates received
|
|
|
|
|
|
|
|
from os import environ
|
2018-02-16 23:02:47 +03:00
|
|
|
|
2017-10-24 22:32:31 +03:00
|
|
|
# environ is used to get API information from environment variables
|
2017-10-26 19:03:24 +03:00
|
|
|
# You could also use a config file, pass them as arguments,
|
2017-10-24 22:32:31 +03:00
|
|
|
# or even hardcode them (not recommended)
|
2017-10-26 19:03:24 +03:00
|
|
|
from telethon import TelegramClient
|
2018-02-16 23:02:47 +03:00
|
|
|
|
2017-10-24 22:32:31 +03:00
|
|
|
|
|
|
|
def main():
|
2017-10-26 19:03:24 +03:00
|
|
|
session_name = environ.get('TG_SESSION', 'session')
|
2017-10-24 22:32:31 +03:00
|
|
|
client = TelegramClient(session_name,
|
2017-10-26 19:03:24 +03:00
|
|
|
int(environ['TG_API_ID']),
|
|
|
|
environ['TG_API_HASH'],
|
|
|
|
proxy=None,
|
2018-02-16 23:02:47 +03:00
|
|
|
update_workers=4,
|
|
|
|
spawn_read_thread=False)
|
|
|
|
|
|
|
|
if 'TG_PHONE' in environ:
|
|
|
|
client.start(phone=environ['TG_PHONE'])
|
|
|
|
else:
|
|
|
|
client.start()
|
2017-10-24 22:32:31 +03:00
|
|
|
|
|
|
|
client.add_update_handler(update_handler)
|
2018-02-16 23:02:47 +03:00
|
|
|
print('(Press Ctrl+C to stop this)')
|
|
|
|
client.idle()
|
|
|
|
|
2017-10-24 22:32:31 +03:00
|
|
|
|
|
|
|
def update_handler(update):
|
2017-10-26 19:03:24 +03:00
|
|
|
print(update)
|
2018-02-16 23:02:47 +03:00
|
|
|
|
2017-10-24 22:32:31 +03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|