How to evade telegram and set an autoreply for who’s left

If you take a rapid look at my presentation about openspace’s aenigma state-of-the-art XMPP server automation project, you’ll find out why I encourage everyone to get the fuck out of Telegram right away.

Here is a fun and fast way to set up an autoreply message that gets returned to anyone who contacts you on Telegram on a normal, non-E2EE, direct chat [at least those are still remotely acceptable].

This is based upon this cool article and tested to be working on Ubuntu 18.

sudo apt install python3-pip
pip3 install telethon

nano telegram_autoreply.py

And paste the following content inside:

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 = 000000
api_hash = '2435afd0987efa001824712490cde800'

# fill in your own details here
phone = '+15555555555'
username = 'username'
password = 'two_step_password'  # if you have two-step verification enabled

# content of the automatic reply
message = "Autoreply: \n\n[EN] I'm no longer reachable via non-E2EE channels and especially on centralized services like this one. \n\nTo get in touch with me either start a secret chat here if it's urgent or wake up and move on with your life onto a libre communication protocol. You can find me on XMPP from any modern client that supports OMEMO at <your_JID> or even better on Riot.IM [you can use 'https://mt.os.vu' as custom homeserver to register using openspace's instance] at <your_Riot_ID> and get the fuck out of here once and for all. \n\n[IT] Non sono più raggiungibile attraverso canali non E2EE e specialmente su servizi centralizzati come questo. \n\nPer raggiungermi avvia una chat segreta qui se è urgente o svegliati e vai avanti con la tua vita verso protocolli di comunicazione libre. Trovami su XMPP con un qualsiasi client moderno che supporti OMEMO a <your_JID> o ancora meglio su Riot.IM [puoi registrarti usando il homeserver 'https://mt.os.vu' per usare l'istanza di openspace] a <your_Riot_ID> e scappa da qui fintanto che sei ancora in tempo."

if __name__ == '__main__':
    # Create the client and connect
    # use sequential_updates=True to respond to messages one at a time
    client = TelegramClient(username, api_id, api_hash, sequential_updates=True)


    @client.on(events.NewMessage(incoming=True))
    async def handle_new_message(event):
        if event.is_private:  # only auto-reply to private chats
            from_ = await event.client.get_entity(event.from_id)  # this lookup will be cached by telethon
            if not from_.bot:  # don't auto-reply to bots
                print(time.asctime(), '-', event.message)  # optionally log time and message
                time.sleep(1)  # pause for 1 second to rate-limit automatic replies
                await event.respond(message)


    print(time.asctime(), '-', 'Auto-replying...')
    client.start(phone, password)
    client.run_until_disconnected()
    print(time.asctime(), '-', 'Stopped!')

Now simply:

crontab -e

And paste the following content:

@reboot sleep 16 && python3 telegram_autoreply.py

You can run it manually the first time – before the first reboot – by running:

python3 telegram_autoreply.py

And have someone else write you to see if it works [messages to yourself via saved messages don’t count]. This will obviously work only in direct chats [user to user] and only on non-E2EE chats.

Press ^c to stop the manual run. After reboot run:

ps aux | grep telegram_autoreply

And you should get something along the lines of:

nz@mb:~$ ps aux | grep telegram_autoreply
nz         787  0.0  0.0   4628   828 ?        Ss   14:20   0:00 /bin/sh -c sleep 16 && python3 telegram_autoreply.py
nz        1691  0.0  1.5  97172 32324 ?        S    14:20   0:00 python3 telegram_autoreply.py
nz        4331  0.0  0.0  14428  1036 pts/0    S+   14:46   0:00 grep --color=auto telegram_autoreply

Now it’s time to get started on XMPP and/or even better Riot.IM once and for all!