Skip to content

Instantly share code, notes, and snippets.

@crazygit
Last active March 19, 2024 09:35
Show Gist options
  • Save crazygit/1fbacfba604f9c7b2a616033ca5b81a1 to your computer and use it in GitHub Desktop.
Save crazygit/1fbacfba604f9c7b2a616033ca5b81a1 to your computer and use it in GitHub Desktop.
Telegram auto checkin script
from telethon import TelegramClient, events
import pathlib
# Remember to use your own values from my.telegram.org!
api_id = 12345
api_hash = '0123456789abcdef0123456789abcdef'
# Replace the checkin bot and text with yourown
checkin_at_bot_id = '@checkin_bot'
checkin_text = '/checkin'
# where to save the login session
session_name = pathlib.Path.home() / '.tg-auto-checkin'
client = TelegramClient(str(session_name), api_id, api_hash)
# handle reply message from checkin_bot
@client.on(events.NewMessage(chats=checkin_at_bot_id))
async def handler(event):
print(event.message.text)
await client.disconnect()
async def main():
# Getting information about yourself
# me = await client.get_me()
# "me" is a user object. You can pretty-print
# any Telegram object with the "stringify" method:
# print(me.stringify())
await client.send_message(checkin_at_bot_id, checkin_text)
# disconnet after handle the reply message from checkin_bot
await client.run_until_disconnected()
if __name__ == '__main__':
with client:
client.loop.run_until_complete(main())
@crazygit
Copy link
Author

Install Dependencies

$ python3 -m pip install --upgrade pip
$ python3 -m pip install --upgrade telethon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment