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.

Revisions

  1. crazygit revised this gist Aug 24, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions telegram_auto_checkin.py
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@
    # 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'

  2. crazygit created this gist Aug 24, 2022.
    33 changes: 33 additions & 0 deletions telegram_auto_checkin.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    from telethon import TelegramClient, events
    import pathlib

    # Remember to use your own values from my.telegram.org!
    api_id = 12345
    api_hash = '0123456789abcdef0123456789abcdef'
    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())