How to spin up your own Telegram bot

You can control Telegram in two ways:

Using bots, so you can interract with users and build apps inside messenger

Using API and controlling whole account (control contacts, numbers and do everything you can do on your mobile app)


After we have a token, let’s create a jail where bot will live

$ curl

$ curl

  "app_port": 52113, 
  "hours_left": 4, 
  "ip": "", 
  "ssh_port": 62742, 
  "ssh_pwd": "9a09b27f355cb297", 
  "ssh_usr": "satoshi", 
  "status": "subscribed"

$ ssh -p62742

[root@praecipua-1]$ python3.7 -m pip install python-telegram-bot

Here’s examples, but to demonstrate a minimum app create a file

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple Bot to reply to Telegram messages.
This is built on the API wrapper, see to see the same example built
on the telegram.ext bot framework.
This program is dedicated to the public domain under the CC0 license.
import logging
import telegram
from telegram.error import NetworkError, Unauthorized
from time import sleep

update_id = None

def main():
    """Run the bot."""
    global update_id
    # Telegram Bot Authorization Token
    bot = telegram.Bot('1069585330:AAGKZX_xH6NXFgDcErsDTGsx92nK0nUoHpQ')

    # get the first pending update_id, this is so we can skip over it in case
    # we get an "Unauthorized" exception.
        update_id = bot.get_updates()[0].update_id
    except IndexError:
        update_id = None

    logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    while True:
        except NetworkError:
        except Unauthorized:
            # The user has removed or blocked the bot.
            update_id += 1

def echo(bot):
    """Echo the message the user sent."""
    global update_id
    # Request updates after the last update_id
    for update in bot.get_updates(offset=update_id, timeout=10):
        update_id = update.update_id + 1

        if update.message:  # your bot can receive updates without messages
            # Reply to the message

if __name__ == '__main__':

Finally, launch it

$ python3.7


To control your Telegram account, use Telethon

[root@praecipua-1]$ python3.7 -m pip install telethon

from telethon.sync import TelegramClient, events

with TelegramClient('name', API_ID, API_HASH) as client:
   client.send_message('me', 'Hello, myself!')

   async def handler(event):
      await event.reply('Hey!')


[root@praecipua-1]$ python3.7

Code above will reply to your contacts with message

Attention! For security purposes this jail has no normal internet connection, while you still can access internet via proxy socks5:// or

Or you can also simply execute any command with torsocks prefix

torsocks ssh

[satoshi@praecipua-1]$ torsocks ssh

However, some programs will work as usual, because proxy enviroment variable is set in ~/.cshrc to use HTTP TORed proxy This means that your bot is completely anonymous and communicates over TOR with Telegram servers ;)