You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
912B

  1. import asyncio
  2. import json
  3. # Change this:
  4. USER_PHONE = '+19705736497'
  5. from telethon.sync import TelegramClient, events, utils
  6. TELETHON_SPAM = -1001382672427
  7. BWB = -1001146421621
  8. HORSESHOE = -1001269329011
  9. SESSION = 'telethon'
  10. API_ID = '929249' # semi-secret
  11. API_HASH = '00c171d347a5140ddf2212157ab2a37a' # semi-secret
  12. client = TelegramClient(SESSION, API_ID, API_HASH, sequential_updates=True)
  13. client.start(USER_PHONE)
  14. @client.on(events.NewMessage(chats=(HORSESHOE)))
  15. async def new_message(event):
  16. text = event.raw_text
  17. print('[{}]: {}'.format(event.sender.first_name, text))
  18. if text and len(text) < 1000:
  19. m = {}
  20. m['chat_id'] = event.chat_id
  21. m['mid'] = event.id
  22. m['from_id'] = event.sender_id
  23. m['raw_text'] = event.raw_text
  24. j = json.dumps(m)
  25. await client.send_message(BWB, j)
  26. print('Loaded.')
  27. asyncio.get_event_loop().run_forever()