Skip to content

Commit 4a7e927

Browse files
committed
Allow definition of a custom Request Client
1 parent ce6d656 commit 4a7e927

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ TG_WEBHOOK='{"url": "https://bot.com/manager.php"}'
2121
TG_ADMINS='[123,456]'
2222
TG_LOGGING='{"error": "${TG_LOGS_DIR}/error.log", "update": "${TG_LOGS_DIR}/update.log"}'
2323

24+
# Request Client
25+
TG_REQUEST_CLIENT_BASE_URI='https://client-base-uri.com'
26+
TG_REQUEST_CLIENT_PROXY='socks5://client-proxy.com:9050'
27+
2428
# Database
2529
TG_DB_HOST='localhost'
2630
TG_DB_PORT=3306

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
55

66
## [Unreleased]
77
### Added
8+
- Possibility to set custom Request Client.
89
### Changed
910
### Deprecated
1011
### Removed

public/manager.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515

1616
use Dotenv\Dotenv;
1717
use Exception;
18+
use GuzzleHttp\Client;
1819
use Longman\TelegramBot\DB;
19-
use Longman\TelegramBot\Exception\TelegramLogException;
20+
use Longman\TelegramBot\Request;
2021
use Longman\TelegramBot\TelegramLog;
2122
use MatthiasMullie\Scrapbook\Adapters\MySQL;
2223
use MatthiasMullie\Scrapbook\KeyValueStore;
@@ -73,6 +74,7 @@ function cache(): KeyValueStore
7374
}
7475

7576
initLogging();
77+
initRequestClient();
7678

7779
$bot = new BotManager($params);
7880
$bot->run();
@@ -108,3 +110,16 @@ function initLogging(): void
108110

109111
TelegramLog::initialize($logger, $update_logger);
110112
}
113+
114+
/**
115+
* Initialise a custom Request Client.
116+
*/
117+
function initRequestClient()
118+
{
119+
$config = array_filter([
120+
'base_uri' => getenv('TG_REQUEST_CLIENT_BASE_URI') ?: 'https://api.telegram.org',
121+
'proxy' => getenv('TG_REQUEST_CLIENT_PROXY'),
122+
]);
123+
124+
$config && Request::setClient(new Client($config));
125+
}

0 commit comments

Comments
 (0)