Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ragnarok22/telegram-bot-api-docker/llms.txt
Use this file to discover all available pages before exploring further.
Configuration Overview
The Telegram Bot API server is configured entirely through environment variables. This approach allows for flexible deployment across different environments without modifying code or configuration files.Getting API Credentials
Before running the server, you need to obtain API credentials from Telegram:Visit my.telegram.org
Navigate to my.telegram.org and log in with your Telegram account.
Create a new application
If you haven’t already, create a new application by filling out the form:
- App title: Choose any name (e.g., “Bot API Server”)
- Short name: A shorter identifier
- Platform: You can select “Other”
- Description: Optional description of your application
Creating the .env File
The recommended way to configure the server is using a.env file:
Example .env File
The repository includes a.env.example file you can use as a template:
.env.example
Environment Variables Reference
Required Variables
These variables must be set for the server to function:| Variable | Type | Description |
|---|---|---|
TELEGRAM_API_ID | Integer | API ID from my.telegram.org |
TELEGRAM_API_HASH | String | API hash from my.telegram.org |
The server will fail to start if these required variables are not provided.
Optional Variables
These variables have sensible defaults but can be customized:Network Configuration
| Variable | Default | Description |
|---|---|---|
TELEGRAM_HTTP_PORT | 8081 | Port for the HTTP API endpoint |
TELEGRAM_HTTP_STAT_PORT | 8082 | Port for the statistics endpoint |
Storage Configuration
| Variable | Default | Description |
|---|---|---|
TELEGRAM_DIR | /data | Directory for bot data and sessions |
TELEGRAM_TEMP_DIR | /tmp | Temporary directory for HTTP file uploads |
TELEGRAM_LOG_FILE | /data/logs/telegram-bot-api.log | Path to the log file |
Feature Flags
| Variable | Default | Description |
|---|---|---|
TELEGRAM_LOCAL | disabled | Enable local file serving mode |
--local flag, allowing it to:
- Return absolute file paths in
getFileresponses - Serve files directly from the local filesystem
Advanced Configuration
| Variable | Default | Description |
|---|---|---|
TELEGRAM_EXTRA_ARGS | empty | Additional flags passed to the telegram-bot-api binary |
Configuration Examples
Minimal Configuration
For basic usage with all defaults:.env
Development Configuration
For local development with verbose logging:.env
Production Configuration
For production deployment with custom ports and resource limits:.env
High-Volume Configuration
For handling many concurrent webhooks:.env
Configuration Methods
Using .env File (Recommended)
With Docker:compose.yml
Using Inline Environment Variables
With Docker:compose.yml
Using Docker Secrets (Production)
For production deployments, use Docker secrets:compose.yml
Docker secrets provide secure credential management in production environments, especially when using Docker Swarm.
Validating Configuration
After configuring the server, verify it’s working correctly:Check Container Logs
Test the API Endpoint
Check Statistics Endpoint
View Log File
Configuration Best Practices
Security
- Never commit
.envfiles to version control - Use
.gitignoreto exclude.envfrom git - Restrict file permissions:
chmod 600 .env - Use Docker secrets in production
- Rotate credentials periodically
Performance
- Increase
--max-webhook-connectionsfor high-traffic bots - Monitor resource usage with
docker stats - Adjust memory limits in Docker Compose based on load
- Use persistent volumes for data directory
Logging
- Mount the data directory to persist logs
- Use log rotation for long-running deployments
- Increase verbosity level for debugging:
--log-verbosity-level 3 - Monitor log file size and disk space
Reliability
- Use
restart: unless-stoppedin Docker Compose - Configure health checks to monitor service status
- Set appropriate resource limits to prevent OOM
- Back up the data directory regularly
Troubleshooting Configuration Issues
Missing Required Variables
If you see errors about missing API credentials:- Verify
.envfile exists:ls -la .env - Check file contents:
cat .env - Ensure variables are not commented out
- Verify
--env-filepath is correct
Port Conflicts
If ports are already in use:.env
Permission Denied Errors
If you encounter permission issues with volumes:botapi (non-root) and needs write access.
Invalid Credentials
If the server fails to authenticate:- Verify credentials at my.telegram.org
- Ensure no extra spaces or quotes in
.env - Check that
TELEGRAM_API_IDis numeric - Verify
TELEGRAM_API_HASHis exactly 32 hexadecimal characters
Next Steps
Docker Setup
Learn how to run the server with Docker
Docker Compose
Deploy using Docker Compose