Advertisement
Guest User

Untitled

a guest
Jan 8th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import time
  2. from telethon import TelegramClient, events
  3.  
  4. # sample API_ID from https://github.com/telegramdesktop/tdesktop/blob/f98fdeab3fb2ba6f55daf8481595f879729d1b84/Telegram/SourceFiles/config.h#L220
  5. # or use your own
  6. api_id = 331902
  7. api_hash = 'def1dd2060f845f5f95a2deee07c9884'
  8.  
  9. # fill in your own details here
  10. phone = '62895619937197'
  11. username = 'YOUR_USERNAME'
  12. password = 'YOUR_PASSWORD' # if you have two-step verification enabled
  13.  
  14. # content of the automatic reply
  15. message = "Sorry, I'll be away until next week!"
  16.  
  17.  
  18. def main():
  19. # Create the client and connect
  20. client = TelegramClient(username, api_id, api_hash, update_workers=1, spawn_read_thread=False)
  21. client.start(phone, password)
  22.  
  23. @client.on(events.NewMessage(incoming=True))
  24. def _(event):
  25. if event.is_private:
  26. print(time.asctime(), '-', event.message) # optionally log time and message
  27. time.sleep(1) # pause for 1 second to rate-limit automatic replies
  28. client.send_message(event.message.from_id, message)
  29.  
  30. print(time.asctime(), '-', 'Auto-replying...')
  31. client.idle()
  32. client.disconnect()
  33. print(time.asctime(), '-', 'Stopped!')
  34.  
  35.  
  36. if __name__ == '__main__':
  37. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement