Skip to content

Commit 8a36eef

Browse files
committed
Refactor and Revert Base Bot URL.
1 parent 2d0c0e5 commit 8a36eef

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/Laravel/config/telegram.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
| If you'd like to use a custom Base Bot Url.
9191
| Should be a local bot api endpoint or a proxy to the telegram api endpoint
9292
|
93-
| Default: https://api.telegram.org
93+
| Default: https://api.telegram.org/bot
9494
|
9595
*/
9696
'base_bot_url' => null,

src/TelegramClient.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010

1111
final class TelegramClient
1212
{
13-
/**
14-
* @var string
15-
*/
16-
public const BASE_BOT_URL = 'https://api.telegram.org';
17-
18-
private string $fileUrl = '{BASE_API_URL}/file/bot{TOKEN}/{FILE_PATH}';
13+
public const BASE_API_URL = 'https://api.telegram.org';
14+
public const BASE_BOT_URL = self::BASE_API_URL.'/bot';
15+
private string $fileUrl = '{BASE_FILE_URL}/file/bot{TOKEN}/{FILE_PATH}';
1916

2017
private HttpClientInterface $httpClientHandler;
2118

2219
private string $baseBotUrl;
20+
private string $baseFileUrl;
2321

24-
public function __construct(HttpClientInterface $httpClientHandler = null, string $baseBotUrl = null)
22+
public function __construct(?HttpClientInterface $httpClientHandler = null, ?string $baseBotUrl = null)
2523
{
2624
$this->httpClientHandler = $httpClientHandler ?? new GuzzleHttpClient();
25+
2726
$this->baseBotUrl = $baseBotUrl ?? self::BASE_BOT_URL;
27+
$this->baseFileUrl = $baseBotUrl ?? self::BASE_API_URL;
2828
}
2929

3030
public function getHttpClientHandler(): HttpClientInterface
@@ -64,8 +64,8 @@ public function sendRequest(TelegramRequest $request): TelegramResponse
6464
public function getFileUrl(string $path, TelegramRequest $request): string
6565
{
6666
return str_replace(
67-
['{BASE_API_URL}', '{TOKEN}', '{FILE_PATH}'],
68-
[$this->baseBotUrl, $request->getAccessToken(), $path],
67+
['{BASE_FILE_URL}', '{TOKEN}', '{FILE_PATH}'],
68+
[$this->baseFileUrl, $request->getAccessToken(), $path],
6969
$this->fileUrl
7070
);
7171
}
@@ -95,7 +95,7 @@ public function download(string $filePath, string $filename, TelegramRequest $re
9595
$request->getMethod(),
9696
$request->getHeaders(),
9797
['sink' => $filename],
98-
$request->isAsyncRequest(),
98+
$request->isAsyncRequest()
9999
);
100100

101101
if ($response->getStatusCode() !== 200) {
@@ -107,7 +107,7 @@ public function download(string $filePath, string $filename, TelegramRequest $re
107107

108108
public function prepareRequest(TelegramRequest $request): array
109109
{
110-
$url = $this->baseBotUrl.'/bot'.$request->getAccessToken().'/'.$request->getEndpoint();
110+
$url = $this->baseBotUrl.$request->getAccessToken().'/'.$request->getEndpoint();
111111

112112
return [$url, $request->getMethod(), $request->getHeaders(), $request->isAsyncRequest()];
113113
}

0 commit comments

Comments
 (0)