A secure Telegram bot that generates Pyrogram and Telethon session strings for users. This bot helps users create session strings safely and securely for their Telegram accounts.
- 🎨 Kurigram Bot API 10.2 UI: Native Rich Messages, HTML tables, collapsible
<details>, styled buttons, and streaming drafts - 🔐 Secure Session Generation: Safely generates Pyrogram and Telethon session strings
- 🧩 Both Libraries: Pick Pyrogram or Telethon with styled inline buttons
- 📱 Phone Number Verification: Supports international phone number format
- 🔢 2FA Support: Handles two-factor authentication with in-memory security
- ⚡ Fast & Reliable: Live streaming draft updates during authorization
- 🛡️ Privacy Focused: Keeps user data secure and isolated
- 🐳 Docker Ready: Easy deployment with Docker
- Python 3.8+
- Telegram Bot Token
- Telegram API ID and API Hash
- Clone the repository:
git clone https://github.com/nub-coders/Session-gen.git
cd Session-gen- Build the Docker image:
docker build -t session .- Run the container with restart policy:
docker run -d --name session --restart always sessionNote: The --restart always flag ensures the container automatically restarts if it stops unexpectedly.
- Install system dependencies:
sudo apt-get update
sudo apt-get install ffmpeg libmagic1- Install Python dependencies:
pip install -r requirements.txt-
Configure your bot:
- Copy
.env.exampleto.envand fill in your values - Set
ADMIN_IDS(comma-separated user IDs) in.envif needed
- Copy
-
Run the bot:
python main.pySet up your environment variables in .env:
API_ID=your_api_id
API_HASH=your_api_hash
BOT_TOKEN=your_bot_token
GROUP=your_support_group
CHANNEL=your_updates_channel
ADMIN_IDS=123456789,987654321- Go to my.telegram.org
- Log in with your phone number
- Go to "API development tools"
- Create a new application
- Copy your API ID and API Hash
- Message @BotFather on Telegram
- Create a new bot with
/newbot - Copy the bot token
/start- Show welcome message and bot information/gen- Generate a session string (choose Pyrogram or Telethon)
- Start a conversation with the bot
- Send
/gencommand - Choose Pyrogram or Telethon
- Enter your phone number in international format (e.g., +1234567890)
- Enter the verification code sent to your Telegram
- If 2FA is enabled, enter your password
- Receive your session string
Tap ❌ Cancel at any step to abort the flow.
- Non-root User: Docker container runs as non-root user
- Session Isolation: Each user session is isolated
- Input Validation: Phone numbers and codes are validated
- Error Handling: Comprehensive error handling for various scenarios
- Admin Controls: Restricted admin commands
Session-gen/
├── main.py # Main bot application (kurigram/pyrogram, state-machine flow)
├── flavors.py # Pyrogram/Telethon adapters + error classes
├── config.py # Configuration file
├── requirements.txt # Python dependencies
├── .env.example # Example environment variables template
├── Dockerfile # Docker configuration
└── README.md # This file
- Pyrogram (kurigram): Bot client and Pyrogram session generation
- Telethon: Telethon session generation
- And more: See
requirements.txtfor complete list
The Dockerfile includes:
- Latest Python image
- System dependencies (ffmpeg, libmagic)
- Security hardening (non-root user)
- Optimized layer caching
- Environment variables
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
- Support Group: @nub_coder_s
- Updates Channel: @nub_coders
This project is licensed under the MIT License - see the LICENSE file for details.
- v2.1.0: Full migration to Kurigram Bot API 10.2 UI — Native Rich Messages (
send_rich_message), interactive HTML<table>layouts, collapsible<details>walkthroughs,ButtonStyleinline buttons, streaming drafts (send_rich_message_draft) for real-time progress, and ephemeral feedback toasts. - v2.0.0: Added Telethon session generation via /gen → inline button choice; state-machine flow (conversation-lite) replaces telethon's Conversation API; cancel button, code-expiry handling, client cleanup on every exit path; kurigram/pyrogram bot
- v1.0.0: Initial release with Pyrogram session generation
Made with ❤️ by @nub_coder_s