A powerful Telegram String Session Generator Bot
Generate Pyrogram & Telethon string sessions with auto-join, force-join protection, and Supabase storage.
✨ Features • 📋 Prerequisites • 🔧 Configuration • 🚀 Deploy • 📌 Commands • 🛠️ Troubleshooting
| Feature | Description |
|---|---|
| 🔑 Pyrogram Sessions | Generate Pyrogram string sessions instantly |
| 📡 Telethon Sessions | Generate Telethon string sessions instantly |
| 🤝 Auto Join | Users automatically join your support channel & group after generation |
| 🔒 Force Join | Block users from generating until they join your channels |
| 💾 Supabase Storage | All sessions stored securely in Supabase PostgreSQL |
| 📢 Broadcast | Owner-only broadcast with live progress bar & stats |
| 📊 Admin Panel | User count, session stats, ban/unban management |
| 🛡️ 2FA Support | Handles two-factor authentication seamlessly |
You need 4 things before deploying. Get them all now:
Step 1 — Create a free account:
- Go to supabase.com → Click "Start your project"
- Sign up with GitHub or email
- Click "New project"
- Fill in: Project name (anything), Database Password (save this!), Region (pick closest to you)
- Click "Create new project" — wait ~2 minutes for it to set up
Step 2 — Get your credentials:
- In your project dashboard, click "Settings" (gear icon, left sidebar)
- Click "API"
- Copy "Project URL" → this is your
SUPABASE_URL - Under "Project API keys", copy "service_role" key → this is your
SUPABASE_KEY
Step 3 — Create the sessions table:
- In your project dashboard, click "SQL Editor" (left sidebar)
- Click "New query"
- Paste this SQL and click "Run":
CREATE TABLE IF NOT EXISTS sessions (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL,
username TEXT DEFAULT '',
session_string TEXT NOT NULL,
session_type TEXT NOT NULL CHECK (session_type IN ('pyrogram', 'telethon')),
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_sessions_user_id ON sessions(user_id);
CREATE INDEX IF NOT EXISTS idx_sessions_user_type ON sessions(user_id, session_type);- You should see "Success. No rows returned" — the table is ready ✅
After cloning the repo, open tgbot/config.py and update these values:
# Your Telegram user ID (from @userinfobot)
OWNER_ID = 123456789
# Channels/groups users must join and auto-join after generating a session
# Use the @username without the @ symbol
AUTO_JOIN_CHATS = [
"your_channel_username", # e.g. "devilbots971"
"your_group_username", # e.g. "devilbotsupport"
]
# Your bot's display name (shown in welcome message)
BOT_NAME = "Devil X String"
⚠️ Important: Add your bot as a member or admin of both your channel and group. Without this, the force-join membership check will not work.
Choose your preferred platform below. Each section has complete step-by-step instructions.
Termux lets you run the bot directly on your Android phone for free.
Step 1 — Install Termux:
- Download Termux from F-Droid (NOT from Play Store — Play Store version is outdated)
Step 2 — Set up Termux:
# Update packages
pkg update && pkg upgrade -y
# Install required tools
pkg install python git nano -yStep 3 — Clone the bot:
git clone https://github.com/mrdevil42023/DevilXString
cd DevilXString/tgbotStep 4 — Install Python dependencies:
pip install -r requirements.txtStep 5 — Configure the bot:
# Copy the example env file
cp .env.example .env
# Open it and fill in your values
nano .envIn the nano editor, fill in:
BOT_TOKEN=your_bot_token_here
API_ID=your_api_id_here
API_HASH=your_api_hash_here
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your-service-role-key-herePress Ctrl+X → Y → Enter to save.
Step 6 — Edit config.py:
nano config.py
# Update OWNER_ID and AUTO_JOIN_CHATSStep 7 — Run the bot:
python3 bot.pyKeep bot running when phone screen is off:
# Install termux-services
pkg install termux-services -y
# OR simply use nohup
nohup python3 bot.py &
# To stop it later:
pkill -f bot.pyTo run in background and check logs:
# Start in background
nohup python3 bot.py > bot.log 2>&1 &
# Check logs anytime
tail -f bot.log
# Check if running
ps aux | grep bot.pyRailway gives you $5 free credit per month — enough to run a bot continuously.
Step 1 — Prepare your GitHub repo:
- Fork this repository on GitHub (click the Fork button top-right)
- In your fork, open
tgbot/config.py - Update
OWNER_IDandAUTO_JOIN_CHATSwith your values - Commit the changes
Step 2 — Create a Railway account:
- Go to railway.app
- Click "Login" → "Login with GitHub"
- Authorize Railway to access your GitHub
Step 3 — Create a new project:
- Click "New Project"
- Select "Deploy from GitHub repo"
- Find and select your forked repository
- Railway will detect the project automatically
Step 4 — Configure the service:
- Click on your newly created service
- Go to the "Settings" tab
- Under "Root Directory", enter:
tgbot - Under "Start Command", enter:
python3 bot.py - Click "Save"
Step 5 — Add environment variables:
- Go to the "Variables" tab
- Click "+ New Variable" and add each one:
| Variable | Value |
|---|---|
BOT_TOKEN |
Your bot token from BotFather |
API_ID |
Your API ID from my.telegram.org |
API_HASH |
Your API Hash from my.telegram.org |
SUPABASE_URL |
Your Supabase project URL |
SUPABASE_KEY |
Your Supabase service role key |
Step 6 — Deploy:
- Go to the "Deployments" tab
- Click "Deploy Now" (or it may deploy automatically)
- Click on the active deployment to see logs
- You should see
🤖 String Session Bot starting...in the logs ✅
To redeploy after code changes:
- Push to your GitHub repo — Railway auto-deploys on every push
Render offers a free tier for background workers (may spin down after inactivity on free plan).
Step 1 — Prepare your GitHub repo:
- Fork this repository on GitHub
- Update
tgbot/config.pywith yourOWNER_IDandAUTO_JOIN_CHATS - Commit the changes
Step 2 — Create a Render account:
- Go to render.com
- Click "Get Started for Free"
- Sign up with GitHub
Step 3 — Create a Background Worker:
- From your Render dashboard, click "New +"
- Select "Background Worker"
- Click "Connect a repository"
- Find and select your forked repository
- Click "Connect"
Step 4 — Configure the worker:
Fill in these settings:
| Setting | Value |
|---|---|
| Name | DevilXString (or anything you like) |
| Region | Choose closest to your users |
| Branch | main |
| Root Directory | tgbot |
| Runtime | Python 3 |
| Build Command | pip install -r requirements.txt |
| Start Command | python3 bot.py |
Step 5 — Add environment variables:
- Scroll down to the "Environment Variables" section
- Click "Add Environment Variable" for each:
| Key | Value |
|---|---|
BOT_TOKEN |
Your bot token |
API_ID |
Your API ID |
API_HASH |
Your API Hash |
SUPABASE_URL |
Your Supabase URL |
SUPABASE_KEY |
Your Supabase key |
Step 6 — Create the service:
- Click "Create Background Worker"
- Render will build and deploy automatically
- Click "Logs" to see the output
- Wait for
🤖 String Session Bot starting...✅
Note: On Render's free plan, background workers run 24/7 for 750 hours/month.
Heroku requires a paid plan (Eco Dynos at ~$5/month) since they removed the free tier.
Step 1 — Install required tools:
# Install Git (if not already installed)
# Windows: https://git-scm.com/download/win
# Mac: brew install git
# Linux: sudo apt install git -y
# Install Heroku CLI
# Windows: Download from https://devcenter.heroku.com/articles/heroku-cli
# Mac: brew tap heroku/brew && brew install heroku
# Linux:
curl https://cli-assets.heroku.com/install.sh | shStep 2 — Log in to Heroku:
heroku login
# A browser window will open — log in thereStep 3 — Clone and prepare the bot:
git clone https://github.com/yourusername/devil-x-string
cd devil-x-string/tgbotStep 4 — Edit config.py with your values:
nano config.py
# Update OWNER_ID and AUTO_JOIN_CHATSStep 5 — Create the Heroku app:
heroku create your-bot-name
# Replace "your-bot-name" with a unique name (e.g. devil-x-string-123)Step 6 — Set all environment variables:
heroku config:set BOT_TOKEN="your_bot_token_here"
heroku config:set API_ID="your_api_id_here"
heroku config:set API_HASH="your_api_hash_here"
heroku config:set SUPABASE_URL="https://your-project.supabase.co"
heroku config:set SUPABASE_KEY="your-service-role-key-here"
# Verify they are set
heroku configStep 7 — Initialize Git and deploy:
git init
git add .
git commit -m "Deploy Devil X String Bot"
heroku git:remote -a your-bot-name
git push heroku mainStep 8 — Scale the worker dyno:
# Heroku bots run as "worker" (not "web")
heroku ps:scale worker=1
# Verify it's running
heroku ps
# Check logs
heroku logs --tailYou should see 🤖 String Session Bot starting... in the logs ✅
To update the bot after code changes:
git add .
git commit -m "Update bot"
git push heroku mainDocker works on any machine (Windows, Mac, Linux, VPS) that has Docker installed.
Step 1 — Install Docker:
- Windows/Mac: Download Docker Desktop
- Linux (Ubuntu/Debian):
sudo apt update
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable dockerStep 2 — Clone the repo:
git clone https://github.com/mrdevil42023/devil-x-string
cd devil-x-string/tgbotStep 3 — Edit config.py:
nano config.py
# Update OWNER_ID and AUTO_JOIN_CHATSStep 4 — Create your .env file:
cp .env.example .env
nano .envFill in all 5 values and save.
Step 5 — Build the Docker image:
docker build -t devil-x-string .Step 6 — Run the container:
# Option A: Using .env file (recommended)
docker run -d \
--env-file .env \
--name devil-x-string \
--restart always \
devil-x-string
# Option B: Pass variables manually
docker run -d \
-e BOT_TOKEN="your_token" \
-e API_ID="your_api_id" \
-e API_HASH="your_api_hash" \
-e SUPABASE_URL="your_supabase_url" \
-e SUPABASE_KEY="your_supabase_key" \
--name devil-x-string \
--restart always \
devil-x-stringThe --restart always flag means Docker will automatically restart the bot if it crashes or the server reboots.
Useful Docker commands:
# View live logs
docker logs -f devil-x-string
# Stop the bot
docker stop devil-x-string
# Start again
docker start devil-x-string
# Restart
docker restart devil-x-string
# Remove container (to redeploy)
docker stop devil-x-string && docker rm devil-x-string
# See running containers
docker psTo update after code changes:
docker stop devil-x-string
docker rm devil-x-string
docker build -t devil-x-string .
docker run -d --env-file .env --name devil-x-string --restart always devil-x-stringBest for 24/7 reliability. Works on any Ubuntu/Debian VPS from providers like DigitalOcean, Contabo, Hetzner, Linode, etc.
Step 1 — Connect to your VPS:
ssh root@your_server_ip
# Enter your password when promptedStep 2 — Install system dependencies:
# Update package lists
apt update && apt upgrade -y
# Install Python, pip, git
apt install python3 python3-pip git nano screen -y
# Verify Python version (should be 3.10+)
python3 --versionStep 3 — Clone the bot:
cd /root
git clone https://github.com/mrdevil42023/DevilXString
cd DevilXString/tgbotStep 4 — Install Python dependencies:
pip3 install -r requirements.txtStep 5 — Configure the bot:
# Copy env file
cp .env.example .env
# Edit env file
nano .envFill in all 5 values. Press Ctrl+X → Y → Enter to save.
# Edit config.py
nano config.py
# Update OWNER_ID and AUTO_JOIN_CHATS, then saveStep 6 — Test the bot:
python3 bot.py
# You should see: 🤖 String Session Bot starting...
# Press Ctrl+C to stop after confirming it worksStep 7 — Run permanently with Screen:
# Start a new screen session named "devilbot"
screen -S devilbot
# Run the bot inside the screen
python3 bot.py
# Detach from screen (bot keeps running)
# Press: Ctrl+A then D
# Later, to check on the bot:
screen -r devilbot
# List all screens
screen -lsStep 7 (Alternative) — Run permanently with Systemd (recommended):
Systemd automatically restarts the bot if it crashes and starts it on server boot.
# Create the service file
nano /etc/systemd/system/devilbot.servicePaste this content:
[Unit]
Description=Devil X String Telegram Bot
After=network.target
Wants=network-online.target
[Service]
Type=simple
User=root
WorkingDirectory=/root/devil-x-string/tgbot
ExecStart=/usr/bin/python3 bot.py
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.targetSave with Ctrl+X → Y → Enter.
# Reload systemd to register the new service
systemctl daemon-reload
# Enable the service (auto-start on reboot)
systemctl enable devilbot
# Start the bot now
systemctl start devilbot
# Check status
systemctl status devilbotYou should see Active: active (running) ✅
Useful systemd commands:
# View live logs
journalctl -u devilbot -f
# Restart the bot (after code changes)
systemctl restart devilbot
# Stop the bot
systemctl stop devilbot
# Disable auto-start
systemctl disable devilbotTo update the bot:
cd /root/devil-x-string
git pull
cd tgbot
pip3 install -r requirements.txt
systemctl restart devilbotKoyeb offers a generous free tier with no credit card required.
Step 1 — Create account:
- Go to koyeb.com
- Sign up for free (no credit card needed)
Step 2 — Prepare your repo:
- Fork this repo on GitHub
- Update
tgbot/config.pywith your values - Commit changes
Step 3 — Create a new service:
- From Koyeb dashboard → "Create Service"
- Select "GitHub"
- Connect your GitHub account and select your forked repo
- Set Branch:
main
Step 4 — Configure build:
| Setting | Value |
|---|---|
| Build command | pip install -r tgbot/requirements.txt |
| Run command | python3 tgbot/bot.py |
| Instance type | Free (nano) |
Step 5 — Add environment variables: Click "Add variable" for each:
BOT_TOKEN,API_ID,API_HASH,SUPABASE_URL,SUPABASE_KEY
Step 6 — Deploy:
Click "Deploy" and watch the logs for 🤖 String Session Bot starting... ✅
| Command | Description |
|---|---|
/start |
Show welcome screen with menu |
/help |
Full guide on how to generate sessions |
/generate |
Choose session type (Pyrogram or Telethon) |
/mysessions |
View your previously generated sessions |
/cancel |
Cancel current operation and return to menu |
| Command | Description |
|---|---|
/stats |
Full stats dashboard (users, sessions, types) |
/users |
List all users who have used the bot |
/userinfo <id> |
Detailed info + sessions for a specific user |
/broadcast |
Send a message to ALL users (with progress bar) |
/ban <id> |
Ban user and delete all their sessions |
/unban <id> |
Unban a user |
tgbot/
├── bot.py # Main bot — handlers and session flow
├── admin.py # Owner-only admin commands & broadcast
├── config.py # ← Edit this to configure your bot
├── database.py # Supabase database helpers
├── helpers.py # Auto-join channel logic (post-generation)
├── force_join.py # Force-join membership checker (pre-generation)
├── keyboards.py # Inline keyboard builders
├── messages.py # All bot message text templates
├── pyrogram_gen.py # Pyrogram session OTP + sign-in logic
├── telethon_gen.py # Telethon session OTP + sign-in logic
├── start_image.png # Bot welcome image
├── requirements.txt # Python package dependencies
├── Procfile # Heroku worker configuration
├── railway.toml # Railway deployment configuration
├── render.yaml # Render deployment configuration
├── Dockerfile # Docker container configuration
├── .env.example # Template for environment variables
├── .gitignore # Files to exclude from Git
└── supabase_setup.sql # SQL to create sessions table
- Never share your string session — it gives complete account access
- Never commit
.envto GitHub — it's in.gitignoreby default - Use Supabase service_role key (not anon key) for full database access
- If a session is compromised: Telegram → Settings → Devices → Terminate session
OWNER_IDinconfig.pyis the only account that can run admin commands
Bot doesn't start / crashes immediately
- Check all 5 environment variables are set correctly
- Verify
BOT_TOKENis valid — test by visitinghttps://api.telegram.org/bot<TOKEN>/getMe - Make sure
API_IDis a number only (no spaces) - Ensure
SUPABASE_URLstarts withhttps://
Supabase error: "table sessions not found"
You haven't created the table yet. Run the SQL from the Prerequisites section in your Supabase SQL Editor.
Auto-join not working after session generation
- Make sure the usernames in
AUTO_JOIN_CHATSare correct (without@) - The channel/group must be public OR the bot must be a member
- Check bot logs for
[AutoJoin]lines to see exact errors
Force-join check always passes (not blocking anyone)
Your bot needs to be a member or admin of both the channel and group to check user membership. Add your bot to both chats, then test again.
OTP not received / phone number invalid
- Include country code with
+(e.g.+919876543210) - If OTP doesn't arrive, check Telegram notifications — it's sent as a Telegram message, not SMS
- Wait 60 seconds and try again if rate limited
2FA password rejected
- Make sure Caps Lock is off
- Try the password you use on Telegram → Settings → Privacy and Security → Two-Step Verification
pyrogram==2.0.106 — Telegram MTProto client (Pyrogram sessions)
TgCrypto==1.2.5 — Fast encryption for Pyrogram
telethon==1.36.0 — Telegram client (Telethon sessions)
supabase==2.15.2 — Supabase Python client
python-dotenv==1.0.1 — Load .env file automatically
Made with ❤️ by @mrdevil12
📢 Channel: t.me/devilbots971 💬 Support Group: t.me/devilbotsupport 🤖 𝘋𝘌𝘝𝘐𝘓 𝘟 𝘚𝘛𝘙𝘐𝘕𝘎: t.me/devilxstring_bot
⭐ If this helped you, please star the repo! ⭐