Telegram Userbot

๐Ÿ•“ Jan 17, 2020 ยท โ˜•5 min read

STOP USING VIBER! - Simplify your life with Telegram bots!

What is a userbot and how is it different from other bots?

Unlike normal Telegram bots userbot can read messages you send and receive. Meaning userbot can respond to a text automatically. Think of it like the Telegram app with some stuff automated, You log in with your phone number and enter provided OTP just like how you would log in to Telegram app.


  • python 3.7 or higher
  • pip for Python 3.7 or higher
  • npm
  • carbon-now-cli
  • mongodb
  • screen

Downloading and Installing Softwares

If you already have some Linux knowledge and a Linux box I assume you won’t need these.. Just make sure you have the requirements installed and skip to this step
Even though we could use windows for this, I will be using the Windows-Linux subsystem for this guide.


  1. Get Ubuntu on Microsoft Store
  2. After installation, enable from “Turn Windows Features on or off” from the control panel and restart your computer.
  3. Launch Ubuntu CLI and setup your UNIX account. username and password can be anything you want
  4. Run sudo apt update to update your repositories

python Setup

Ubuntu comes with Python2.7 and Python3.6 pre-installed. But we need 3.7 or higher for this bot to work

  1. Install Python3.8 by running sudo apt install python3.8-minimal
  2. Confirm installation by python3.8 --version


  1. Run sudo apt install python3-pip
    to install pip3 but since Ubuntu have Python3.6 Pre-installed the pip installation will be pip 9.0.1 from python 3.6, We need to upgrade this.
  2. Download get-pip and run it in python3.8
    curl -o
    sudo python3.8
  3. Confirm installation by pip --version


MongoDB do not officially support WSL However, you can get it working with the following steps.

  1. sudo apt-key adv --keyserver hkp:// --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
    This will import the MongoDB public GPG Key so we can use the official MongoDB supported pkg in apt
  2. echo "deb [ arch=amd64,arm64 ] xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
    This will add the .deb to your sources list.
  3. Run sudo apt-get update to update your repositories.
  4. Run the install command by pasting this into the terminal sudo apt-get install mongodb-org


  1. Run sudo apt install npm

carbon now

  1. sudo npm install -g carbon-now-cli --unsafe-perm=true --allow-root

Userbot Clone

  1. run git clone to download bot scripts.

Userbot Requiments

  1. run sudo pip install -r userbot/requirements.txt

Setting up Telegram app development API

As I said earlier the bot is like a Telegram app. You need to get app API ID and app API hash from Telegram to make an app

  1. Go to and login with your account
  2. Select API development tools and fill the form.
    App title, Short Name, URL can be anything you want, Under Platform Select Other.
  3. keep a note of this, it will be required when configuring userbot


MongoDB - Config

Database Directory

MongoDB needs a folder to store database and it has to be a folder called “db” inside a folder called “data”.

  1. Make a new folder called “data” by typing mkdir data
  2. Change your working directory to that folder by cd data
  3. Make a new folder called “db” by typing mkdir db
  4. Go to previous directory by typing cd ..
    Now you need to run mongodb in the directory you can do this with a new terminal window or using screen command.
  5. open up a screen with the name mongodb by running sudo screen -S mongodb
  6. Run mongodb in this screen mongod --dbpath ~/data/db
  7. Deattach from this screen by pressing CTRL+A D

DB name, username, password

While running MongoDB in 1 screen.

  1. Enter MonogoDB shell by entering mongo
  2. use admin to switch to admin db
  3. Copy-paste this to MongoDB console and press Enter
    user: "teleuser",
    pwd: "teleuser",
    roles: [ { role: "readWrite", db: "userbot" } ]

user: and pwd: can be anything you want if you using something else, keep a note of it, it will be required when configuring userbot
5. Exit out of the mongo shell exit

Userbot - Config

  1. Change working directory to the folder userbot is cloned to cd userbot
    when you ls you will see a filed called “userbot.ini.sample” and “file_ids.txt” need to edit “file_ids.txt” remove everything in this file and replace with {}
  2. echo {} > file_ids.txt
    This will replace the content in “file_ids.txt” with {}
  3. Rename “userbot.ini.sample” to “userbot.ini”
    mv userbot.ini.sample userbot.ini
  4. nano userbot.ini add the following text
api_id = 
api_hash = 

url = localhost
db_name = admin
db_username = teleuser
db_password = teleuser

pm_permit = false
pm_limit = 5

log_group = non

Fill it accordingly
api_id = Enter id you noted in this step
api_hash = Enter hash you noted in this step
db_username = Enter username you noted in this step
db_password = Enter username you noted in this step
ave and close nano.
CTRL+X Y Enter

Run the bot and login

  1. Open up a new screen called userbot sudo screen -S userbot
  2. Enter python3.8 -m userbot
  3. When prompted for Phone number enter you number with the country code, and enter OTP sent to your telegram account.
  4. You can deattach from this screen and close the console now. CTRL+A D

Ay you done..

Bot console say “Userbot started. Hi."? Means you are good to go. ๐Ÿ‘Œ๐Ÿ‘Œ
Try .alive or .help on any Telegram chat

Credits, and Thanks to

Shiham Abdul Rahman
Shiham Abdul Rahman