A Telegram Userbot based on Pyrogram
This repository contains the source code of a Telegram Userbot and the instructions for running a copy yourself. Beside its main purpose, the bot is featuring Pyrogram Asyncio and Smart Plugins; feel free to explore the source code to learn more about these topics.
I assume you will read this whole README.md file before continuing.
You're gonna need to get the following programs and services either installed on your server or signed up for. You must do all. It is a cardinal sin if you don't.
-
Python 3.10 (requirements were generated for 3.10. Python 3.8 is supported from the looks of it.)
-
virtualenvinstalled so that the packages don't interfere with other system packages. -
Deno 2.3+ on
PATHfor YouTube downloads, plus FFmpeg for merging video and audio. Both are included in the Docker images. Theyt-dlp[default]requirement supplies the matching YouTube challenge scripts. HTTP 429 means the service is rate-limiting requests; wait before retrying and check the server/proxy's public IP if it persists. Installing Deno does not remove a rate limit. -
MongoDB on your server or a free server from MongoDB Atlas. (I recommend Atlas as I used it during development with no issues.)
-
carbon-now-cli on your server too generate code images for the carbon.py module. I use this CLI tool cause I don't know and couldn't get selenium and chromedriver to work nicely on my server/code. I'll be nice and even give you the command to install this. I assume you already have NPM installed.
Windows: npm install -g carbon-now-cli Linux: sudo npm install -g carbon-now-cli --unsafe-perm=true --allow-root MacOS: I assume almost the same as linux ¯\_(ツ)_/¯
The way I deploy
git clone https://github.com/athphane/userbot.git
cd userbot
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
python -m userbotUsing docker
- Save the following content as
docker-compose.yml
services:
userbot:
hostname: userbot
volumes:
- ./config:/root/userbot/config
image: ghcr.io/athphane/userbot:latest
restart: always
labels:
com.centurylinklabs.watchtower.enable: "true"
depends_on:
- userbot-mongo
userbot-mongo:
image: mongo:latest
hostname: userbot-mongo
restart: always
labels:
com.centurylinklabs.watchtower.enable: "false"
volumes:
- ./mongo:/data/db
environment:
- MONGO_INITDB_DATABASE=userbot
- MONGO_INITDB_ROOT_USERNAME=userbot
- MONGO_INITDB_ROOT_PASSWORD=userbot-passwordIf you already run Watchtower on this Docker host, these labels opt the userbot
into automatic updates from ghcr.io/athphane/userbot:latest and exclude MongoDB.
Watchtower must be configured to include this container and allow updates; the
userbot is also opted in when Watchtower uses --label-enable. See the
Watchtower container selection documentation
for name and scope filters. After adding the labels to an existing deployment,
run docker compose up -d userbot userbot-mongo to apply them.
This example uses the published image. The repository's root docker-compose.yml
builds locally and mounts the source checkout, so its labels alone do not enable
updates from the published image.
- Config
Get your telegram api_id and api_hash from https://my.telegram.org/apps and configure them:
mkdir config
wget -O config/userbot.ini https://raw.githubusercontent.com/athphane/userbot/refs/heads/master/userbot.ini.sample
nano config/userbot.ini
- First run:
docker compose run --rm userbot python -m userbot- Configure userbot and stop container CTRL+C
- Run the container again de-attached:
docker compose up -dTo get the Spotify commands working on the Userbot, you need to get a CLIENT_ID and CLIENT_SECRET form the Spotify Developer Portal and add them into your userbot.ini file.
On the Spotify developer portal, make sure to set your application Redirect URI to
'http://localhost:8888/callback'.
Now is a good time
Then go ahead and run the command python spotify.py
in the projects root directory.
This will create a file called .cache-yourusername. You need to transfer this file to the
project root of the server that will be running your userbot. This is a one time setup.
.restartcommand do not work on Termux as psutils is not supported on Android.
CTRL+C, rungit pullandpython -m userbotto update bot on termux.
- Dan for his Pyrogram Library
- Colin Shark for his PyroBot which helped with most of the useful functions used.
- The people at MyPaperPlane for their Telegram-UserBot that gave a ton of ideas on how and what modules to include in this userbot.
- Baivaru for the ton of help that got me this far into making this repo.
Made with love from the Maldives ❤
