TelegramApiServer/config.php

89 lines
3.5 KiB
PHP
Raw Permalink Normal View History

<?php
2023-04-11 01:56:45 +02:00
use danog\MadelineProto\Logger;
use TelegramApiServer\EventObservers\LogObserver;
use function Amp\Socket\SocketAddress\fromString;
2020-01-19 04:17:14 +01:00
$settings = [
2019-06-20 18:51:58 +02:00
'server' => [
2023-04-11 01:56:45 +02:00
'address' => (string)getenv('SERVER_ADDRESS'),
'port' => (int)getenv('SERVER_PORT'),
'real_ip_header' => (string)(getenv('REAL_IP_HEADER') ?? ''),
],
'telegram' => [
'app_info' => [ // obtained in https://my.telegram.org
2023-04-11 01:56:45 +02:00
'api_id' => (int)getenv('TELEGRAM_API_ID'),
'api_hash' => (string)getenv('TELEGRAM_API_HASH'),
],
'logger' => [ // Logger settings
2023-08-13 18:17:58 +02:00
'type' => Logger::CALLABLE_LOGGER, // 0 - Logs disabled, 3 - echo logs.
2023-09-02 23:45:01 +02:00
'extra' => LogObserver::log(...),
2023-08-13 18:17:58 +02:00
'level' => (int)getenv('LOGGER_LEVEL'), // Logging level, available logging levels are: ULTRA_VERBOSE - 5, VERBOSE - 4 , NOTICE - 3, WARNING - 2, ERROR - 1, FATAL_ERROR - 0.
],
2023-08-13 18:17:58 +02:00
'rpc' => [
2023-11-19 19:04:07 +01:00
'flood_timeout' => 5,
2024-05-18 18:36:19 +02:00
'rpc_drop_timeout' => 20,
2023-07-05 16:39:54 +02:00
],
2023-08-13 18:17:58 +02:00
'connection' => [
2023-12-11 15:55:58 +01:00
'max_media_socket_count' => 10,
'proxies' => [
'\danog\MadelineProto\Stream\Proxy\SocksProxy' => [
[
"address" => (string)getenv('TELEGRAM_PROXY_ADDRESS'),
"port"=> (int)getenv('TELEGRAM_PROXY_PORT'),
"username"=> (string)getenv('TELEGRAM_PROXY_USERNAME'),
"password"=> (string)getenv('TELEGRAM_PROXY_PASSWORD'),
],
]
]
2019-04-19 14:49:01 +02:00
],
'serialization' => [
2023-10-25 00:18:07 +02:00
'interval' => 600,
],
2020-04-26 20:50:42 +02:00
'db' => [
2023-08-14 01:22:07 +02:00
'enable_min_db' => (bool)filter_var((string)getenv('DB_ENABLE_MIN_DATABASE'), FILTER_VALIDATE_BOOL),
2023-10-25 00:11:34 +02:00
'enable_file_reference_db' => (bool)filter_var((string)getenv('DB_ENABLE_FILE_REFERENCE_DATABASE'), FILTER_VALIDATE_BOOL),
2023-08-14 01:22:07 +02:00
'type' => (string)getenv('DB_TYPE'),
2020-10-03 01:50:56 +02:00
getenv('DB_TYPE') => [
2023-08-14 01:22:07 +02:00
'uri' => 'tcp://' . getenv('DB_HOST') . ':' . (int)getenv('DB_PORT'),
'username' => (string)getenv('DB_USER'),
'password' => (string)getenv('DB_PASSWORD'),
'database' => (string)getenv('DB_DATABASE'),
2023-04-11 01:56:45 +02:00
'max_connections' => (int)getenv('DB_MAX_CONNECTIONS'),
'idle_timeout' => (int)getenv('DB_IDLE_TIMEOUT'),
2023-08-14 01:22:07 +02:00
'cache_ttl' => (string)getenv('DB_CACHE_TTL'),
'serializer' => ((string)getenv('DB_SERIALIZER')) ?: 'serialize',
2020-04-26 20:50:42 +02:00
]
],
2023-08-13 18:17:58 +02:00
'files' => [
2019-12-08 13:46:54 +01:00
'report_broken_media' => false,
2024-05-18 18:36:19 +02:00
'download_parallel_chunks' => 20,
2020-10-03 00:50:48 +02:00
],
2024-07-01 11:56:29 +02:00
'metrics' => [
'enable_prometheus_collection' => true, //(bool)getenv("PROMETHEUS_BIND_TO"),
'metrics_bind_to' => fromString("0.0.0.0:12345")
]
],
2019-01-20 18:20:41 +01:00
'api' => [
2019-03-19 23:56:28 +01:00
'ip_whitelist' => array_filter(
array_map(
'trim',
2023-08-14 01:22:07 +02:00
explode(',', (string)getenv('IP_WHITELIST'))
2019-03-19 23:56:28 +01:00
)
),
2024-04-15 17:09:24 +02:00
'passwords' => (array)json_decode((string)getenv('PASSWORDS'), true),
2023-09-02 23:45:01 +02:00
'bulk_interval' => (float)getenv('REQUESTS_BULK_INTERVAL')
2019-01-20 18:20:41 +01:00
],
2020-01-19 04:17:14 +01:00
];
2023-12-11 15:55:58 +01:00
if (empty($settings['telegram']['connection']['proxies']['\danog\MadelineProto\Stream\Proxy\SocksProxy'][0]['address'])) {
$settings['telegram']['connection']['proxies'] = [];
}
2023-01-17 12:39:06 +01:00
if (empty($settings['telegram']['app_info']['api_id'])) {
2023-01-17 14:00:55 +01:00
throw new InvalidArgumentException('Need to fill TELEGRAM_API_ID in .env.docker or .env');
2023-01-17 12:39:06 +01:00
}
2024-07-01 11:56:29 +02:00
return $settings;