Configuration Guide¶
StreamBot uses environment variables for configuration. This guide covers all available options and their purposes.
Environment File Setup¶
Create a .env
file in your project root:
Required Configuration¶
Telegram Settings¶
# Telegram API credentials (required)
API_ID=12345678
API_HASH=your_api_hash_from_my_telegram_org
BOT_TOKEN=123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi
LOG_CHANNEL=-1001234567890
Variable | Description | How to Get |
---|---|---|
API_ID |
Telegram API ID | Get from my.telegram.org |
API_HASH |
Telegram API Hash | Get from my.telegram.org |
BOT_TOKEN |
Bot token from BotFather | Message @BotFather |
LOG_CHANNEL |
Channel ID for file storage | Create private channel, add bot as admin |
Database Configuration¶
Variable | Description | Examples |
---|---|---|
DATABASE_URL |
MongoDB connection string | mongodb://localhost:27017 (local)mongodb+srv://user:pass@cluster.mongodb.net/ (Atlas) |
DATABASE_NAME |
Database name | StreamBotDB , MyStreamBot |
Server Configuration¶
Variable | Description | Examples |
---|---|---|
BASE_URL |
Public URL for download/streaming links | https://files.yourdomain.com , http://localhost:8080 |
PORT |
Port for web server | 8080 , 3000 , 80 |
BIND_ADDRESS |
IP address to bind server | 127.0.0.1 (local), 0.0.0.0 (public) |
Video Streaming Frontend¶
Variable | Description | Default | Disable |
---|---|---|---|
VIDEO_FRONTEND_URL |
Video player frontend URL | https://cricster.pages.dev |
Set to false |
Optional Configuration¶
Admin Settings¶
Variable | Description | Format |
---|---|---|
ADMINS |
Space-separated admin user IDs | 123456789 987654321 |
Multi-Client Support¶
# Additional bot tokens for load balancing
ADDITIONAL_BOT_TOKENS=token1,token2,token3
WORKER_CLIENT_PYROGRAM_WORKERS=1
WORKER_SESSIONS_IN_MEMORY=true
Variable | Description | Benefits |
---|---|---|
ADDITIONAL_BOT_TOKENS |
Comma-separated additional bot tokens | Increases download/streaming throughput, load balancing |
WORKER_CLIENT_PYROGRAM_WORKERS |
Workers per additional client | Keep at 1 for stability |
WORKER_SESSIONS_IN_MEMORY |
Store sessions in memory | Reduces disk I/O |
Rate Limiting¶
Variable | Description | Default | Disable |
---|---|---|---|
MAX_LINKS_PER_DAY |
Daily link generation limit per user | 5 |
0 (unlimited) |
BANDWIDTH_LIMIT_GB |
Monthly bandwidth limit in GB | 100 |
0 (unlimited) |
Force Subscription¶
Variable | Description | Usage |
---|---|---|
FORCE_SUB_CHANNEL |
Channel ID for required subscription | Users must join channel before using bot |
Performance Tuning¶
Variable | Description | Default | Recommendations |
---|---|---|---|
WORKERS |
Number of worker threads | 4 |
2-8 depending on server |
SESSION_NAME |
Session file prefix | TgDlBot |
Unique name per instance |
Link Management¶
Variable | Description | Default | Notes |
---|---|---|---|
LINK_EXPIRY_SECONDS |
Link validity duration | 86400 (24 hours) |
In seconds, affects both download and streaming links |
External Integrations¶
# Optional external services
GITHUB_REPO_URL=https://github.com/AnikethJana/Telegram-Download-Link-Generator
Variable | Description | Usage |
---|---|---|
GITHUB_REPO_URL |
Repository URL for info display | Shown in /info command and API |
Environment-Specific Configurations¶
Development Environment¶
# Development settings
API_ID=12345678
API_HASH=your_dev_api_hash
BOT_TOKEN=your_dev_bot_token
LOG_CHANNEL=-1001234567890
DATABASE_URL=mongodb://localhost:27017
DATABASE_NAME=StreamBotDev
BASE_URL=http://localhost:8080
PORT=8080
BIND_ADDRESS=127.0.0.1
VIDEO_FRONTEND_URL=https://cricster.pages.dev
ADMINS=your_telegram_user_id
MAX_LINKS_PER_DAY=0
BANDWIDTH_LIMIT_GB=0
SESSION_NAME=StreamBotDev
WORKERS=2
Production Environment¶
# Production settings
API_ID=12345678
API_HASH=your_production_api_hash
BOT_TOKEN=your_production_bot_token
LOG_CHANNEL=-1001234567890
DATABASE_URL=mongodb+srv://user:password@cluster.mongodb.net/
DATABASE_NAME=StreamBotProd
BASE_URL=https://files.yourdomain.com
PORT=8080
BIND_ADDRESS=0.0.0.0
VIDEO_FRONTEND_URL=https://cricster.pages.dev
ADMINS=your_telegram_user_id
MAX_LINKS_PER_DAY=5
BANDWIDTH_LIMIT_GB=100
FORCE_SUB_CHANNEL=-1009876543210
ADDITIONAL_BOT_TOKENS=token1,token2
SESSION_NAME=StreamBotProd
WORKERS=4
LINK_EXPIRY_SECONDS=86400
Video Frontend Configuration¶
Default Cricster Integration¶
StreamBot comes with Cricster integration by default:
Custom Frontend¶
To use your own video frontend:
Your frontend will receive streaming URLs as: {VIDEO_FRONTEND_URL}?stream={encoded_stream_url}
Disable Video Frontend¶
Configuration Validation¶
StreamBot validates your configuration on startup. Common validation errors:
Missing Required Variables
Solution: Ensure all required variables are set in your.env
file.
Invalid Bot Token
Solution: Check your bot token format. It should look like123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi
Database Connection Failed
Solution: Verify yourDATABASE_URL
and ensure MongoDB is running.
Invalid Channel ID
Solution: Channel IDs should be negative numbers like-1001234567890
Video Frontend Not Accessible
Solution: Check yourVIDEO_FRONTEND_URL
or set to false
to disable.
Security Best Practices¶
Environment Variables Security¶
- Never commit
.env
files to version control - Use HTTPS in production for
BASE_URL
- Restrict admin access with proper
ADMINS
configuration - Use secure MongoDB connections with authentication
IP Address Restrictions¶
For additional security, configure your reverse proxy or firewall to restrict access to specific IP addresses.
Configuration Templates¶
.env.example
Template¶
# Telegram Configuration (Required)
API_ID=your_api_id
API_HASH=your_api_hash
BOT_TOKEN=your_bot_token
LOG_CHANNEL=your_log_channel_id
# Database Configuration (Required)
DATABASE_URL=mongodb://localhost:27017
DATABASE_NAME=StreamBotDB
# Server Configuration (Required)
BASE_URL=https://yourdomain.com
PORT=8080
BIND_ADDRESS=0.0.0.0
# Video Frontend (defaults to Cricster)
VIDEO_FRONTEND_URL=https://cricster.pages.dev
# Admin Configuration
ADMINS=your_telegram_user_id
# Optional Features
MAX_LINKS_PER_DAY=5
BANDWIDTH_LIMIT_GB=100
FORCE_SUB_CHANNEL=
ADDITIONAL_BOT_TOKENS=
# Performance Settings
WORKERS=4
SESSION_NAME=TgDlBot
LINK_EXPIRY_SECONDS=86400
Troubleshooting Configuration¶
If StreamBot fails to start, check:
- Environment file exists: Ensure
.env
file is in the project root - Required variables set: All required variables have values
- Format correctness: Variables follow the correct format
- File permissions:
.env
file is readable by the application - No trailing spaces: Remove any trailing spaces from variable values
- Video frontend accessibility: Ensure VIDEO_FRONTEND_URL is accessible or set to
false
For additional help, see the Installation Guide or User Guide.