Skip to content

feat: add user-facing Telegram bot with trial, payments and referrals#2016

Open
muitiiifruckt wants to merge 1 commit intoGozargah:masterfrom
muitiiifruckt:master
Open

feat: add user-facing Telegram bot with trial, payments and referrals#2016
muitiiifruckt wants to merge 1 commit intoGozargah:masterfrom
muitiiifruckt:master

Conversation

@muitiiifruckt
Copy link
Copy Markdown

New separate TeleBot instance (TELEGRAM_USER_BOT_TOKEN) running in its own daemon thread alongside the existing admin bot without touching it.

Features:

  • /start: auto-creates trial account (configurable days/GB), supports referral deeplinks (ref_CODE)
  • Personal cabinet: live status, traffic used/remaining, expiry date
  • Config section: subscription URL + QR code generation in-memory
  • Telegram Stars payments (1/3/6 months) with invoice flow and automatic Xray sync on successful payment
  • Referral system: configurable bonus days, hard cap on total bonus, optional require-payment mode to prevent farming

DB changes:

  • Alembic migration a1b2c3d4e5f6 adds telegram_id, referral_code, referred_by_id columns to the users table
  • New CRUD helpers: get_user_by_telegram_id, get_user_by_referral_code, link_user_telegram_id, set_user_referral_code, record_referral, extend_user_expire, count_user_referrals

Bug fixes in bot code:

  • DetachedInstanceError: _account_text() now called inside session
  • IntegrityError on race condition handled with rollback + retry
  • Double DB queries in cb_router collapsed into single session
  • user_bot.get_me() result cached at module level
  • Removed unused imports

Made-with: Cursor

New separate TeleBot instance (TELEGRAM_USER_BOT_TOKEN) running in its
own daemon thread alongside the existing admin bot without touching it.

Features:
- /start: auto-creates trial account (configurable days/GB), supports
  referral deeplinks (ref_CODE)
- Personal cabinet: live status, traffic used/remaining, expiry date
- Config section: subscription URL + QR code generation in-memory
- Telegram Stars payments (1/3/6 months) with invoice flow and
  automatic Xray sync on successful payment
- Referral system: configurable bonus days, hard cap on total bonus,
  optional require-payment mode to prevent farming

DB changes:
- Alembic migration a1b2c3d4e5f6 adds telegram_id, referral_code,
  referred_by_id columns to the users table
- New CRUD helpers: get_user_by_telegram_id, get_user_by_referral_code,
  link_user_telegram_id, set_user_referral_code, record_referral,
  extend_user_expire, count_user_referrals

Bug fixes in bot code:
- DetachedInstanceError: _account_text() now called inside session
- IntegrityError on race condition handled with rollback + retry
- Double DB queries in cb_router collapsed into single session
- user_bot.get_me() result cached at module level
- Removed unused imports

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant