How hiddify/hiddify-telegram-bot works
1. This repository is a Python-based Telegram bot system for managing Hiddify panels. The architecture is split into two user-facing bots plus support services for panel access, persistence, scheduling, and deployment.
2. The main runtime entrypoint is hiddifyTelegramBot.py, which likely boots the overall application and coordinates bot startup. The codebase is organized as a set of modules rather than a single monolith, with clear separation between admin features, end-user features, and shared infrastructure.
3. There are two distinct bot subsystems: AdminBot/ and UserBot/. Each has its own bot.py, content.py, markups.py, templates.py, and JSON message/command/button definitions. That structure suggests the project supports two different Telegram personas with different menus, localized text, and interaction flows.
4. The AdminBot side is the control plane. From the README and filenames, it handles panel administration tasks such as adding/removing users, editing user details, searching users, viewing statistics, selling configs, and generating backups. The UserBot side is the customer-facing plane, likely focused on subscription lookup, config display, and user self-service actions.
5. Shared logic lives in Shared/common.py, which is the likely boundary for code reused by both bots. This is where cross-cutting concerns such as helpers, role checks, formatting, or shared Telegram/UI utilities would be centralized to avoid duplication between admin and user flows.
6. The Hiddify panel integration is isolated in Utils/api.py and Utils/serverInfo.py. This layer is the bridge to the external Hiddify system and server metrics, so architecture-wise it represents the main outbound dependency: bot actions translate into panel API calls and status queries rather than direct business logic inside the handlers.
7. Persistence is handled by Database/dbManager.py. That module is the repository’s state boundary and likely stores bot configuration, panel metadata, user mappings, language settings, and other operational records needed across restarts. The presence of a dedicated database layer indicates the bots are not stateless.
8. Background automation is implemented under Cronjob/, with backup.py, backupBot.py, and reminder.py. This is the asynchronous side of the system: scheduled backups, automatic delivery of backups or notifications, and reminder workflows run separately from the interactive Telegram update loop.
9. The repository also contains config.py, version.py, and the *_templates.py / JSON files that define content and translations. That points to a configuration-and-content-driven design, where runtime behavior is parameterized by admin setup and user-facing text is externalized for English/Persian support.
10. Operationally, the shell scripts (install.sh, update.sh, restart.sh, uninstall.sh) and crontab.py show that the project is intended to be installed and managed on a server, likely as a long-running service with scheduled jobs. update.py suggests in-place upgrade support, while log retrieval in the README implies file-based operational logging.
11. From an architecture diagram perspective, the key flows are: Telegram users interact with either admin or user bot → handlers route through shared helpers and content templates → bot logic calls the Hiddify API layer and/or database → scheduled cron jobs run backup and reminder workflows independently → deployment scripts manage lifecycle and updates.
12. The main external boundary is Telegram itself on the inbound side and the Hiddify panel on the outbound side. Everything else in the repo supports mediation between those two systems: message routing, localization, configuration, persistence, and scheduled automation.
Main entry points: AdminBot/bot.py Admin bot · UserBot/bot.py User bot · dbManager.py Database · common.py Common core
Components 20
Bots
Interactive Telegram bot subsystems for admins and end users.
- Admin bot · Administrator-facing bot runtime and command routing.
AdminBot/bot.py - Admin content · Admin-side text, templates, and presentation helpers.
AdminBot/content.py - Admin markups · Admin-side Telegram keyboard and menu layouts.
AdminBot/markups.py - Admin templates · Admin-side templated messages and reusable responses.
AdminBot/templates.py - User bot · Customer-facing bot runtime and self-service flows.
UserBot/bot.py - User content · User-facing text, templates, and presentation helpers.
UserBot/content.py - User markups · User-facing Telegram keyboard and menu layouts.
UserBot/markups.py - User templates · User-facing templated messages and reusable responses.
UserBot/templates.py
Shared Core
Common helpers, configuration, persistence, and Hiddify integration.
- Main app · Bootstraps the overall Telegram bot application.
hiddifyTelegramBot.py - Common core · Shared logic reused by both bot subsystems.
Shared/common.py - Hiddify API · Outbound bridge to the Hiddify panel and related actions.
Utils/api.py - Server info · Collects server and panel status information used by the bots.
Utils/serverInfo.py - Utilities · General-purpose utility functions shared across the repository.
Utils/utils.py - Database · Persistent state boundary for bot and panel data.
Database/dbManager.py - Config · Central configuration for bot behavior and deployment settings.
config.py
Operations
Scheduled jobs and deployment scripts that run the service.
- Backups · Backup generation and backup delivery workflows.
Cronjob/backup.py - Backup bot · Bot-assisted backup automation and notification flow.
Cronjob/backupBot.py - Reminders · Reminder and notification workflows run on a schedule.
Cronjob/reminder.py - Crontab · Scheduler configuration and job wiring for the server runtime.
crontab.py - Updater · In-place update support for the deployed service.
update.py
Connections 25
- Main app → Admin bot: starts · Bootstraps the admin-facing runtime.
- Main app → User bot: starts · Bootstraps the user-facing runtime.
- Admin bot → Common core: uses · Shares cross-cutting helpers and checks.
- User bot → Common core: uses · Shares cross-cutting helpers and checks.
- Admin bot → Admin content: renders · Uses admin text and response content.
- Admin bot → Admin markups: builds UI · Uses admin keyboard layouts and menus.
- Admin bot → Admin templates: formats · Uses admin message templates.
- User bot → User content: renders · Uses user-facing text and response content.
- User bot → User markups: builds UI · Uses user keyboard layouts and menus.
- User bot → User templates: formats · Uses user message templates.
- Admin bot → Hiddify API: calls · Executes panel administration actions through the API layer.
- User bot → Hiddify API: calls · Executes user-facing panel lookups and actions.
- Admin bot → Database: reads/writes · Stores admin state and operational records.
- User bot → Database: reads/writes · Stores user mappings and runtime state.
- Hiddify API → Server info: queries · Uses server status and metrics during panel operations.
- Common core → Utilities: uses · Depends on shared utility functions.
- Common core → Config: reads · Loads shared runtime configuration.
- Backups → Database: reads/writes · Backups use persisted configuration and state.
- Backups → Hiddify API: calls · Backup workflows may interact with the panel layer.
- Backup bot → Backups: drives · Coordinates backup automation and delivery.
- Reminders → Database: reads · Reminder jobs use stored schedules and recipients.
- Crontab → Backups: schedules · Registers backup jobs with the server scheduler.
- Crontab → Reminders: schedules · Registers reminder jobs with the server scheduler.
- Updater → Config: reads · Uses configuration during deployment updates.
- Updater → Database: migrates · May update persisted state during upgrades.