Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from telethon import TelegramClient, events
- # sample API_ID from https://github.com/telegramdesktop/tdesktop/blob/f98fdeab3fb2ba6f55daf8481595f879729d1b84/Telegram/SourceFiles/config.h#L220
- # or use your own
- api_id = 331902
- api_hash = 'def1dd2060f845f5f95a2deee07c9884'
- # fill in your own details here
- phone = '62895619937197'
- username = 'YOUR_USERNAME'
- password = 'YOUR_PASSWORD' # if you have two-step verification enabled
- # content of the automatic reply
- message = "Sorry, I'll be away until next week!"
- def main():
- # Create the client and connect
- client = TelegramClient(username, api_id, api_hash, update_workers=1, spawn_read_thread=False)
- client.start(phone, password)
- @client.on(events.NewMessage(incoming=True))
- def _(event):
- if event.is_private:
- print(time.asctime(), '-', event.message) # optionally log time and message
- time.sleep(1) # pause for 1 second to rate-limit automatic replies
- client.send_message(event.message.from_id, message)
- print(time.asctime(), '-', 'Auto-replying...')
- client.idle()
- client.disconnect()
- print(time.asctime(), '-', 'Stopped!')
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement