Documentation Index
Fetch the complete documentation index at: https://mintlify.com/avikekk/JackettSearchBot/llms.txt
Use this file to discover all available pages before exploring further.
Security
Environment Variables
Never Commit Secrets
Never Commit Secrets
Critical: Keep all sensitive data in Required secrets:
config.env and never commit it to version control.TELEGRAM_TOKEN- Bot token from @BotFatherAPI_HASH- Telegram API hash from my.telegram.orgJACKETT_API_KEY- Jackett API key from web interface
Rotate Credentials Immediately After Exposure
Rotate Credentials Immediately After Exposure
If any credentials are accidentally exposed:
- Telegram Bot Token: Revoke via @BotFather and generate new token
- Jackett API Key: Regenerate in Jackett web UI settings
- API Hash: Create new application at my.telegram.org
- Update
config.envwith new values - Restart the bot
README.md:112Restrict File Permissions
Restrict File Permissions
Ensure config files have restrictive permissions:This prevents other users on the system from reading your secrets.
Authorization
Use OWNER_ID for Administrative Control
Use OWNER_ID for Administrative Control
The
OWNER_ID bypasses all authorization checks and has access to admin commands:/auth- Grant temporary access/unauth- Revoke temporary access/unauthall- Clear all temporary authorizations
- Set this to your personal Telegram user ID
- Never share your owner credentials
- Keep this separate from chat/group IDs
jackett_bot/handlers/commands.py:279Understand Authorization Layers
Understand Authorization Layers
Deployment
Process Management
Use systemd for Production
Use systemd for Production
Run the bot as a systemd service for automatic restarts and logging.Create service file: Enable and start:View logs:
/etc/systemd/system/jackett-bot.serviceDocker Deployment
Docker Deployment
Run the bot in a container for isolation and easy updates.Example Dockerfile:docker-compose.yml:
Handle Database Lock Errors
Handle Database Lock Errors
The bot uses Pyrogram’s session database. If you see “database is locked” errors:Cause: Another bot instance is running or a stale lock exists.Solution:Source:
jackett_bot/app.py:40The bot already uses
in_memory=True by default, so session locks should not occur. If you modify this, be aware of potential lock issues.Logging
Configuration
Dual-Output Logging Strategy
Dual-Output Logging Strategy
The bot implements two-tier logging for different use cases:Console Handler (stdout)
- Default level:
INFO - Purpose: High-level operational visibility
- Configure via:
CONSOLE_LOG_LEVEL - Format:
%(asctime)s | %(levelname)s | %(name)s | %(message)s
- Default level:
DEBUG - Purpose: Detailed troubleshooting
- Configure via:
FILE_LOG_LEVEL - Location:
logs/jackett_bot.log(configurable) - Rotation: 10MB max, 5 backup files
- Format: Includes filename, line number, function name
jackett_bot/app.py:125Log Levels
Log Levels
Choose appropriate log levels for each environment:
Set in config.env:Valid values:
| Environment | Console | File | Reasoning |
|---|---|---|---|
| Development | DEBUG | DEBUG | Full visibility |
| Staging | INFO | DEBUG | Clean console, detailed files |
| Production | INFO | INFO | Reduce I/O overhead |
| Production (issues) | WARNING | DEBUG | Minimal console noise |
DEBUG, INFO, WARNING, ERROR, CRITICALSource: jackett_bot/config.py:100Log Rotation
Log Rotation
The bot uses Result:
RotatingFileHandler to prevent unbounded log growth:- Current:
logs/jackett_bot.log - Backups:
logs/jackett_bot.log.1throughlogs/jackett_bot.log.5 - Total max size: ~60 MB (10 MB × 6 files)
jackett_bot/app.py:135Dependency Management
Using uv
Why uv?
Why uv?
The project uses uv for faster, more reliable dependency management:Benefits:Source: Mentioned in
- 10-100× faster than pip
- Automatic virtual environment management
- Lock file for reproducible installs
- Built-in workspace support
- Compatible with pip/requirements.txt
README.md:21Dependency Files
Dependency Files
The project uses modern Python packaging with
pyproject.toml:pyproject.toml (project metadata + dependencies)- Defines project metadata
- Lists runtime dependencies
- Conditional dependencies (e.g.,
tgcryptoonly on Python < 3.13)
- Generated by
uv lock - Contains exact versions and hashes
- Ensures reproducible installs across environments
- Commit this file to version control
- Human-readable dependency list
- Used for documentation
- Can be used with pip if needed
Optional tgcrypto
Optional tgcrypto
The bot includes Why conditional?Source:
tgcrypto for faster encryption, but it’s optional:- Requires C++ build tools to compile
- Python 3.13+ has compatibility issues
- Bot works fine without it (just slightly slower encryption)
requirements.txt:4Performance
HTTP Timeouts
Configure Appropriate Timeouts
Configure Appropriate Timeouts
The bot uses different timeouts for different operations:Jackett SearchPTP Availability CheckSource:
- Default: 15 seconds
- Configurable per request
- Increase for slow indexers or many trackers
- Default: 5 seconds
- Intentionally short (it’s just a health check)
jackett_bot/services/jackett.py:54, jackett_bot/services/ptp.py:10Result Redaction
Result Redaction
Search results are automatically redacted after a configurable timeout:Configuration:Behavior:Source:
- Results display normally with pagination
- After timeout, message changes to “RESULTS REDACTED”
- Pagination buttons removed
- Session cleaned from memory
- Reduces sensitive data exposure in chat history
- Prevents outdated results from being referenced
- Frees memory from expired pagination sessions
jackett_bot/handlers/commands.py:340Pagination Session Management
Pagination Session Management
Search results use in-memory pagination with automatic cleanup:Session TTLSession ownership:
- Default: 3600 seconds (1 hour)
- Automatically pruned on new searches or page requests
- Prevents memory leaks from abandoned sessions
- Each session tied to requesting user ID
- Only requester (or owner) can change pages
- Prevents unauthorized pagination hijacking
jackett_bot/handlers/commands.py:330Error Handling
Graceful Degradation
HTTP Error Handling
HTTP Error Handling
The bot distinguishes between different HTTP error types:Error categories:
HTTPStatusError- Bad status code (4xx, 5xx)HTTPError- Network issues (timeout, connection refused)Exception- Parsing errors or unexpected issues
jackett_bot/handlers/commands.py:125Startup Validation
Startup Validation
The bot validates configuration before starting:Validation checks:
- All required environment variables present
- Numeric values parseable as integers
- Log levels valid
- Chat IDs valid integers
main.py:4, jackett_bot/config.py:53Fast-fail on startup prevents runtime errors from missing configuration.
Graceful Shutdown
Graceful Shutdown
The bot handles shutdown signals cleanly:Cleanup actions:
- Close Jackett HTTP client
- Close PTP HTTP client
- Flush log handlers
jackett_bot/app.py:89Maintenance
Updates
Updating Dependencies
Updating Dependencies
Monitoring
Monitoring
Key metrics to monitor:
- Bot uptime - Use systemd status or Docker health checks
- Error rates - Parse log files for ERROR/CRITICAL entries
- Response times - Monitor Jackett timeout frequency
- Authorization failures - Track unauthorized access attempts
Backup and Recovery
Backup and Recovery
What to backup:
- config.env - Contains all secrets and configuration
- logs/ - For troubleshooting and audit trails
- pyproject.toml and uv.lock - For reproducible deployments
The bot uses in-memory sessions, so no session database backup is needed.