Persian README: README-FA.md
TelegramSellBot is a self-hosted Telegram sales system for VPN/proxy operators. It includes a Telegram bot, FastAPI backend, Telegram Mini App, payment webhooks, background workers, Sanaei X-UI integration, ready-config inventory, wallet accounting, ticketing, admin tools, reports, and deployment scripts.
- Sell plans and automatically provision configs through Sanaei X-UI after successful payment.
- Sell preloaded ready configs from uploaded
.txtinventory without connecting X-UI. - Let users buy custom volume and custom duration using admin-defined pricing.
- Renew services, buy extra volume, and buy extra time.
- Internal wallet with top-up and wallet checkout.
- NOWPayments, TetraPay, manual crypto payment, and card-to-card payment.
- Manual admin approval for crypto hashes and card-transfer receipt photos.
- Gateway payment refresh/review when callbacks arrive late.
- Optional mobile number verification before purchase, disabled by default.
- Iranian-only or any-phone-number verification modes.
- Discount codes, plan stock limits, plan inventory display, and unlimited-stock mode.
- Bulk volume/time gifts for active configs, all configs, all servers, or one server.
- Trial config option with admin toggle and per-user reset.
- Support tickets in both the bot and the Mini App.
- User Mini App and admin Mini App panels.
- Weekly purchase Excel report including purchased config name.
- Expiry and low-volume alerts with renewal actions.
- Backup, broadcast, retargeting, recovery, and payment reconciliation tools.
Run this on a fresh Ubuntu server as root:
bash <(curl -fsSL https://raw.githubusercontent.com/sina99778/telegramsellbot/master/setup.sh)The installer:
- installs required base packages
- places the project in
/opt/telegramsellbot - creates
.envthrough an interactive flow - installs Docker, Nginx, and Certbot
- starts
api,bot,worker,postgres, andredis
sudo -i
apt-get update
apt-get install -y git curl rsync
git clone https://github.com/sina99778/telegramsellbot.git /opt/telegramsellbot
cd /opt/telegramsellbot
chmod +x setup.sh install.sh deploy.sh
bash install.shFull deploy:
cd /opt/telegramsellbot
./deploy.sh fullQuick service reload:
cd /opt/telegramsellbot
./deploy.sh reloadUpdate to the latest version:
cd /opt/telegramsellbot
git pull
./deploy.sh fullImportant environment variables:
BOT_TOKEN: Telegram bot token from BotFatherBOT_USERNAME: bot username without@OWNER_TELEGRAM_ID: numeric Telegram ID of the ownerADMIN_API_KEY: internal admin API keyDATABASE_URL: PostgreSQL connection URL inside DockerREDIS_URL: Redis connection URL inside DockerXUI_BASE_URL,XUI_USERNAME,XUI_PASSWORD: X-UI panel connectionNOWPAYMENTS_API_KEY,NOWPAYMENTS_IPN_SECRET,NOWPAYMENTS_IPN_CALLBACK_URL: NOWPayments settingsTETRAPAY_API_KEY,TETRAPAY_CALLBACK_URL: TetraPay settingsWEB_BASE_URL: public domain for the backend and Mini AppSUPPORT_URL: support or panel URL
Card-to-card settings, manual crypto wallets, phone verification, custom purchase pricing, trial config, referral settings, and Toman exchange rate are configured from the admin panel, not from .env.
- Create a bot in BotFather and place the token in
.env. - Point your domain to the server and set
WEB_BASE_URL. - If using gateways, set provider callbacks:
https://your-domain.com/api/webhooks/nowpaymentshttps://your-domain.com/api/webhooks/tetrapay - Run
./deploy.sh full. - Open Telegram and send
/startto the bot. IfOWNER_TELEGRAM_IDis correct, the owner can access admin menus. - Configure servers, plans, gateways, and sales settings.
Important admin sections:
- Server management: X-UI credentials, config domain, subscription domain, and max clients
- Plan management: create plans and edit name, price, duration, volume, stock, and active status
- Ready-config sales: create ready-config plans and upload config inventory
- User management: search users, inspect status, adjust balance, message users, and manage access
- Customers and services: inspect purchases, active services, and config details
- Finance and payments: view payments, review gateways, approve/reject manual payments
- Bot settings: renewal pricing, Toman rate, custom purchase, gateways, phone verification, trial config, referral, and force-join
- Tickets: reply to tickets and close them
- Discounts: create and manage discount codes
- Volume/time gifts: apply gifts to active configs, all configs, all servers, or one server
- Recovery and reconciliation: recover deliveries and recheck payments
- Reports and backup: Excel reports, statistics, and manual backups
Open Admin Panel -> Bot Settings -> Payment Gateways. Each gateway has its own menu.
- Open the NOWPayments menu.
- Enable or disable the gateway.
- Optionally set an API key and IPN secret in the admin panel. Empty values fall back to
.env. - In NOWPayments, set IPN callback to
NOWPAYMENTS_IPN_CALLBACK_URL. - After confirmed payment, the webhook automatically credits wallet or delivers the purchased config.
- Open the TetraPay menu.
- Enable or disable the gateway.
- Set the API key or use the
.envvalue. - Set USD to Toman exchange rate in bot settings.
- Users choose the Rial gateway and the bot processes delivery after verification.
- Open the manual crypto menu.
- Enable the gateway.
- Select the currency, for example
USDT TRC20. - Add one or more wallet addresses.
- Users select the currency, see amount and address, and submit TX hash.
- Admin approves or rejects the request.
- If it is a wallet top-up, the wallet is credited. If it is a direct purchase, the config is delivered after approval.
- Open
Payment Gateways -> Card To Card. - Set card number, cardholder name, bank name, and optional payment note.
- Enable card-to-card payment.
- Users choose card-to-card during purchase or wallet top-up.
- The bot shows Toman amount and card details.
- User sends a receipt photo after payment.
- Admins receive the receipt with approve/reject buttons.
- Approval delivers the config for direct purchases or credits the wallet for top-ups.
Open Admin Panel -> Bot Settings -> Phone Verification.
- Disabled by default.
- Admin can enable or disable it.
Iran onlyaccepts Iranian mobile numbers.Any numberaccepts international or numeric phone numbers.
When enabled, users must send their own mobile number before seeing purchase plans. The verified number is stored in the user profile and is not requested again.
- Open plan management.
- Create a new plan.
- Select the target X-UI inbound.
- Enter plan name, duration, volume, and price.
- Optionally configure stock/sales limit.
- Stock limit
0means unlimited and is not shown to users. - Active plans appear in the bot store and Mini App store.
From plan details, admins can change:
- plan duration
- plan volume
- purchase price
- stock limit
- active/inactive status
Changes affect future purchases only. Existing subscriptions are not modified.
Use ready-config sales when you cannot connect X-UI or already have a fixed list of configs.
- Open
Ready Config Sales. - Create a ready-config plan with name, duration, volume, and price.
- Upload a
.txtfile where each line is one full config. - Keep the pool active.
- Users buy the ready plan like any normal plan.
- After payment, the bot takes the oldest available config, marks it sold, creates the subscription record, and sends that config to the user.
Operational notes:
- One line is delivered to one customer only.
- Empty lines and duplicate configs are ignored during upload.
- If inventory is empty, the plan is hidden from user purchase lists.
- If a plan stock limit is set, effective stock is capped by both plan stock and available ready configs.
Open Bot Settings -> Custom Purchase.
- Enable custom purchase.
- Set price per 1 GB.
- Set price per 1 day.
- Users see the custom volume/duration option in the store.
- Users enter volume, duration, config name, and payment method.
- After payment, the bot creates a config with the requested limits.
This feature needs at least one active plan connected to an inbound so the bot can use it as the template for provisioning.
Open Bot Settings -> Trial Config.
- Admin can enable or disable trial configs.
- Each user can receive one trial by default.
- Admin can reset a user's trial limit.
Users can renew from My Services or from low-volume/expiry alerts.
Admins can gift:
- volume
- time
- both volume and time
- to active configs only
- to all configs
- across all servers
- on one specific server
Users can top up wallets through gateways, manual crypto, or card-to-card. They can then buy plans using wallet balance.
Wallet is used for:
- faster purchases
- manual admin balance adjustments
- automatic refunds after provisioning failures
- referral rewards
Admins can create and manage discount codes with:
- discount percent
- max uses
- expiry
- active/inactive status
Users can enter a code during purchase or continue without a code.
Users can:
- open tickets
- send text or photos
- see admin replies in the same thread
Admins can:
- view tickets from bot or Mini App
- reply
- close tickets
Ticket messages are not deleted when admins reply; the conversation is updated.
- Home and account summary
- Store and plan purchase
- Custom volume/duration purchase
- Wallet top-up
- My services and renewal
- Support tickets
- Referral
- Payment refresh
- Stats and reports
- Finance and payments
- Users and search
- Customers
- Services
- Plans and inventory
- Ready-config sales
- Tickets
- Discounts
- Settings
- Admin actions
Only admins can see the Mini App admin-panel button.
The weekly purchase Excel report includes purchase details, user, amount, payment method, and purchased config name.
Useful server commands:
cd /opt/telegramsellbot
./deploy.sh full
./deploy.sh reload
docker compose -f docker-compose.prod.yml logs -f bot
docker compose -f docker-compose.prod.yml logs -f api
docker compose -f docker-compose.prod.yml logs -f workerIf a gateway payment is not delivered:
- Open finance/payment management.
- Find the payment.
- Press review/refresh.
- If the provider confirms payment, the bot automatically credits wallet or delivers the config.
To ensure you don't lose user and configuration data, a backup and restore system is included.
To back up the database and the .env file, run the following command on your server:
cd /opt/telegramsellbot
./backup.shThis script creates a compressed .sql.gz dump of the database and copies your .env file into the backups/ folder. Download these files to a safe location (e.g., your personal computer).
If you change servers and want to restore the bot with previous data:
- Install the bot on the new server (run the quick install command).
- Upload your backup files (
.envand.sql.gz) to the new server in the/opt/telegramsellbotdirectory. - Replace the current
.envwith your backed-up.envfile (ensure security keys remain the same). - Restart the containers:
docker compose -f docker-compose.prod.yml up -d - Restore the database backup:
cd /opt/telegramsellbot
./restore.sh backups/telegramsellbot_backup_XXXXXX_XXXXXX.sql.gzThis will drop the new database and replace it with your backup data.
python -m venv .venv
. .venv/bin/activate
pip install -e .[dev]
pytest -qapps/bot/: Telegram bot handlers, keyboards, states, and middlewareapps/api/: FastAPI, Mini App routes, and payment webhooksapps/worker/: background jobsmodels/: database modelsrepositories/: data access and app settingsservices/: payment, provisioning, wallet, X-UI, notifications, and domain logicminiapp/: Mini App frontendtests/: regression tests
- The repository is public, but the software remains proprietary. See LICENSE.
- Use strong secrets for PostgreSQL, Redis,
APP_SECRET_KEY, andADMIN_API_KEY. - Always set
NOWPAYMENTS_IPN_SECRETin production. - Never commit
.env. - Gateway callbacks require a valid public domain and SSL.
- The
migrations/directory is not yet a full Alembic history for every historical upgrade path; current deployment still uses metadata-based bootstrap paths.
More details:
- Security guidance: SECURITY.md
- Database notes: docs/DATABASE.md
GitHub Actions runs tests on pushes and pull requests targeting master and main.