diff --git a/.env.docker.example b/.env.docker.example index 6fec5f5..e0e8d9d 100644 --- a/.env.docker.example +++ b/.env.docker.example @@ -27,6 +27,12 @@ TELEGRAM_API_HASH= # FATAL_ERROR = 0; ERROR = 1; WARNING = 2; const NOTICE = 3; VERBOSE = 4; ULTRA_VERBOSE = 5; LOGGER_LEVEL=2 +# TELEGRAM SOCKS5 PROXY (optional) +TELEGRAM_PROXY_ADDRESS= +TELEGRAM_PROXY_PORT= +TELEGRAM_PROXY_USERNAME= +TELEGRAM_PROXY_PASSWORD= + # DB # memory # Keep all data in memory/session file. diff --git a/.env.example b/.env.example index 3805f8f..c8bd3fd 100644 --- a/.env.example +++ b/.env.example @@ -26,6 +26,12 @@ TELEGRAM_API_HASH= # FATAL_ERROR = 0; ERROR = 1; WARNING = 2; const NOTICE = 3; VERBOSE = 4; ULTRA_VERBOSE = 5; LOGGER_LEVEL=2 +# TELEGRAM SOCKS5 PROXY (optional) +TELEGRAM_PROXY_ADDRESS= +TELEGRAM_PROXY_PORT= +TELEGRAM_PROXY_USERNAME= +TELEGRAM_PROXY_PASSWORD= + # DB # memory # Keep all data in memory/session file. diff --git a/README.md b/README.md index b4a5629..24ffea1 100644 --- a/README.md +++ b/README.md @@ -232,15 +232,24 @@ Each session stored in `sessions/{$session}.madeline`. Nested folders supported. ```json { - "connection_settings": { - "all": { - "proxy": "\\SocksProxy", - "proxy_extra": { - "address": "127.0.0.1", - "port": 1234, - "username": "user", - "password": "pass" - } + "connection": { + "proxies": { + "\\danog\\MadelineProto\\Stream\\Proxy\\SocksProxy": [ + { + "address": "127.0.0.1", + "port": 1234, + "username": "user", + "password": "pass" + } + ], + "\\danog\\MadelineProto\\Stream\\Proxy\\HttpProxy": [ + { + "address": "127.0.0.1", + "port": 1234, + "username": "user", + "password": "pass" + } + ] } } } diff --git a/config.php b/config.php index c866d32..6b70050 100644 --- a/config.php +++ b/config.php @@ -23,7 +23,17 @@ $settings = [ 'rpc_drop_timeout' => 11, ], 'connection' => [ - 'max_media_socket_count' => 10 + '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'), + ], + ] + ] ], 'serialization' => [ 'interval' => 600, @@ -63,6 +73,10 @@ $settings = [ ] ]; +if (empty($settings['telegram']['connection']['proxies']['\danog\MadelineProto\Stream\Proxy\SocksProxy'][0]['address'])) { + $settings['telegram']['connection']['proxies'] = []; +} + if (empty($settings['telegram']['app_info']['api_id'])) { throw new InvalidArgumentException('Need to fill TELEGRAM_API_ID in .env.docker or .env'); } diff --git a/src/Client.php b/src/Client.php index 9385c57..8b09594 100644 --- a/src/Client.php +++ b/src/Client.php @@ -161,7 +161,7 @@ class Client private static function getSettingsFromArray(string $session, array $settings, SettingsAbstract $settingsObject = new Settings()): SettingsAbstract { foreach ($settings as $key => $value) { - if (is_array($value)) { + if (is_array($value) && $key !== 'proxies') { if ($key === 'db' && isset($value['type'])) { $type = match ($value['type']) { 'memory' => new Settings\Database\Memory(),