Complete overview of project organization and file structure.
Telegram-Panel/
├── docs/ # Documentation
│ ├── README.md # Documentation index
│ ├── PROJECT_STRUCTURE.md # This file
│ └── API.md # API reference
├── src/ # Source code
│ ├── __init__.py
│ ├── Config.py # Configuration management
│ ├── Telbot.py # Main bot orchestrator
│ ├── Client.py # Session and account management
│ ├── Handlers.py # Event handlers
│ ├── Keyboards.py # UI keyboard layouts
│ ├── Monitor.py # Message monitoring
│ ├── actions.py # Bulk and individual operations
│ ├── Validation.py # Input validation
│ ├── Logger.py # Logging configuration
│ └── utils.py # Utility functions
├── tests/ # Test suite
│ ├── __init__.py
│ ├── conftest.py # Pytest configuration
│ ├── run_tests.py # Test runner
│ ├── test_account_persistence.py
│ ├── test_admin.py
│ ├── test_all_buttons.py
│ ├── test_bulk_send_pv_flow.py
│ ├── test_config_detection.py
│ ├── test_flows_account_management.py
│ ├── test_flows_bulk_operations.py
│ ├── test_flows_individual_operations.py
│ ├── test_flows_monitor_mode.py
│ ├── test_handler_flows.py
│ ├── test_handlers.py
│ ├── test_integration_edge_cases.py
│ ├── test_memory_session.py
│ ├── test_network.py
│ ├── test_session_isolation.py
│ ├── test_unit_config.py
│ ├── test_unit_handlers.py
│ ├── test_unit_keyboards.py
│ └── test_unit_validation.py
├── logs/ # Log files
│ └── bot.log # Application logs
├── main.py # Application entry point
├── requirements.txt # Python dependencies
├── env.example # Environment variables template
├── config.json # Runtime configuration
├── clients.json # Client session data
├── install.sh # Installation script
├── README.md # Main project documentation
├── CONTRIBUTING.md # Contribution guidelines
├── CHANGELOG.md # Version history
└── LICENSE # License file
main.py
- Application entry point
- Initializes logging
- Creates and runs TelegramBot instance
- Handles graceful shutdown
Configuration management system.
Classes:
ConfigManager: Manages JSON configuration files
Functions:
validate_env_file(): Validates required environment variablesget_env_variable(): Retrieves environment variablesget_env_int(): Retrieves integer environment variables
Configuration Variables:
API_ID,API_HASH: Telegram API credentialsBOT_TOKEN: Bot authentication tokenADMIN_ID: Admin user IDCHANNEL_ID: Target channel for forwarding- Rate limiting and batch size configurations
Main bot orchestrator managing all system components.
Classes:
TelegramBot: Main bot class
Key Responsibilities:
- Bot connection and lifecycle management
- Component initialization
- Handler registration
- Client management coordination
- Admin notifications
Session and account management.
Classes:
SessionManager: Manages Telegram client sessionsAccountHandler: Handles account-related operations
Key Features:
- Session detection and loading
- Account authentication
- Session persistence
- Account status checking
- Group management
- Report status checking
Event handlers for bot interactions.
Classes:
CommandHandler: Handles bot commandsCallbackHandler: Handles callback queriesMessageHandler: Handles text messagesAccountHandler: Account management handlersKeywordHandler: Keyword management handlersStatsHandler: Statistics and reporting handlers
Key Features:
- Command processing (
/start) - Callback query routing
- Conversation state management
- Input validation and sanitization
UI keyboard layout generation.
Classes:
Keyboard: Static keyboard layout methods
Key Methods:
start_keyboard(): Main menumonitor_keyboard(): Monitor mode menubulk_keyboard(): Bulk operations menuindividual_keyboard(): Individual operations menuaccount_management_keyboard(): Account management menureport_keyboard(): Report menu
Message monitoring and forwarding system.
Classes:
Monitor: Message monitoring handler
Key Features:
- Keyword-based message filtering
- Automatic message forwarding
- Channel resolution
- User ignore list support
- Real-time monitoring across accounts
Bulk and individual operation implementations.
Classes:
Actions: Operation execution handler
Key Operations:
- Reactions: Apply reactions to messages
- Polls: Vote in polls
- Join/Leave: Group membership management
- Block: User blocking
- Private Messages: Send messages to users
- Comments: Post comments on messages
Key Features:
- Bulk operation execution with concurrency control
- Individual account operations
- Automatic retry with exponential backoff
- Rate limiting and flood wait handling
- Session revocation detection and cleanup
- Link parsing and entity resolution
Input validation and sanitization.
Classes:
InputValidator: Input validation utilities
Key Features:
- Phone number validation
- Username validation
- Link validation
- Text sanitization
Logging configuration.
Functions:
setup_logging(): Configures logging system
Features:
- File and console logging
- Log rotation
- Configurable log levels
General utility functions.
Key Functions:
get_session_name(): Extract session name from clientcleanup_conversation_state(): Clean up conversation stateexecute_bulk_operation(): Execute bulk operationsformat_bulk_result_message(): Format operation resultsresolve_entity(): Resolve Telegram entitiescheck_account_exists(): Check account availabilityremove_revoked_session_completely(): Remove revoked sessions
Template for environment variables. Copy to .env and fill in values.
Runtime configuration storing:
- Target groups for monitoring
- Keywords for filtering
- Ignore user list
- Client configurations
Client session data and account information.
Tests are organized by category:
- Unit Tests: Individual component testing
- Integration Tests: Component interaction testing
- Flow Tests: End-to-end user flow testing
- Edge Case Tests: Error and boundary condition testing
conftest.py: Pytest fixtures and configurationtest_unit_*.py: Unit tests for specific modulestest_flows_*.py: User flow teststest_integration_*.py: Integration teststest_*.py: Feature-specific tests
- User Interaction: User sends command or clicks button
- Handler Processing: Appropriate handler processes request
- Validation: Input is validated and sanitized
- Action Execution: Operation is executed via Actions class
- Client Management: SessionManager handles account operations
- Response: Result is formatted and sent to user
telethon: Telegram client librarypython-dotenv: Environment variable managementaiohttp: Async HTTP clientrequests: HTTP librarypysocks: SOCKS proxy support
pytest: Testing frameworkpytest-asyncio: Async test supportpytest-cov: Coverage reporting
- Module files:
PascalCase.pyfor classes,snake_case.pyfor utilities - Test files:
test_*.py - Configuration files:
lowercase.json,lowercase.env - Documentation:
UPPERCASE.mdfor main docs,lowercase.mdfor guides
Session files are stored in the project root with format:
{phone_number}.sessionfor user accountsbot2.sessionfor bot session
Session files contain authentication data and should never be committed to version control.