In-Telegram Admin Suite (/admin) & User Management

Raw MD
Native Telegram-based administrative control center with telemetry, user search, custom ban reasons, and hierarchical navigation.

The Native In-Telegram Admin Suite

Every professional Telegram bot requires a powerful administrative dashboard accessible directly inside Telegram without logging into an external web portal. Botlify Cloud establishes a standardized architectural pattern for building secure, intuitive in-bot admin panels.

1. Strict Security Gate

The admin suite is gated strictly by ADMIN_CHAT_ID (provisioned automatically via environment variables). If any unauthorized user attempts to send /admin or trigger admin callback queries, the bot must silently terminate execution with zero response and zero data exposure:

PHP — Admin Authorization Gate
<?php
// ── Botlify Cloud .env — auto-injected, never hardcode secrets ──
$BOT_TOKEN     = getenv('BOT_TOKEN');     // Telegram bot token from @BotFather
$ADMIN_CHAT_ID = getenv('ADMIN_CHAT_ID'); // Your numeric admin Telegram user ID
$BOT_USERNAME  = getenv('BOT_USERNAME');  // Bot username without @

declare(strict_types=1);

if ($text === '/admin' || str_starts_with($callbackData, 'admin_')) {
    if ((string)$chatId !== ADMIN_CHAT_ID) {
        exit; // Silently drop unauthorized attempts
    }
}

2. Hierarchical Back Navigation (admin_home)

To maintain seamless UX, administrative sub-sections (such as Statistics, User Management, Broadcast, or Tickets) must never redirect the administrator back to the general user menu. All admin sub-menu « Back buttons must specify callback_data => 'admin_home', editing the existing message in-place back to the main admin control center. An explicit « Exit to Bot Menu button (admin_exit) is provided for intentional exits.

3. Real-Time Bot Telemetry & Analytics (admin_stats)

The analytics view displays live bot statistics queried directly from the local SQLite database:

  • Total Registered Users & Today's Active Users (24h).
  • Currently Suspended / Banned Users count.
  • Domain-specific metrics (e.g., Total Revenue, Open Support Tickets, Total Orders, Paid Referrals).
  • Server Engine status (SQLite WAL Mode, PHP version).

4. User Management, Dossier Inspection & Ban Firewall

Administrators can search any user by numeric Chat ID or @username using a dedicated FSM search prompt. The bot renders a detailed user dossier:

  • Account Info: User ID, Username, Display Name, Registration Date, Total Transactions.
  • Interactive Action Buttons:
    • [🔴 Ban User] — Prompts admin for a mandatory Ban Reason, updates the database with is_banned = 1 and ban_reason, and blocks the user.
    • [🟢 Unban User] — Restores user access and clears the ban flag.
Instant Ban Firewall & Keyboard Removal When a banned user attempts to interact with the bot, the ban firewall intercepts the request, displays the custom suspension reason, executes reply_markup => ['remove_keyboard' => true] to strip all menu buttons from their screen, and halts execution immediately.
Botlify Cloud Runtime
Credentials are auto-injected in .env — always load them with getenv(): BOT_TOKEN, ADMIN_CHAT_ID, BOT_USERNAME. Main database: database.db (SQLite, WAL mode). Runtime errors: error.log. Quick test: send to $ADMIN_CHAT_ID. Full details: Runtime Reference.