Skip to content

Commit

Permalink
Revise Base File URL
Browse files Browse the repository at this point in the history
  • Loading branch information
irazasyed committed May 28, 2023
1 parent 73ec22c commit 31a71ae
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/TelegramClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@

final class TelegramClient
{
public const BASE_API_URL = 'https://api.telegram.org';
public const BASE_BOT_URL = 'https://api.telegram.org/bot';

public const BASE_BOT_URL = self::BASE_API_URL.'/bot';

private string $fileUrl = '{BASE_FILE_URL}/file/bot{TOKEN}/{FILE_PATH}';
private string $fileUrl = '{BASE_BOT_URL}/file/bot{TOKEN}/{FILE_PATH}';

private HttpClientInterface $httpClientHandler;

private string $baseBotUrl;

private string $baseFileUrl;

public function __construct(?HttpClientInterface $httpClientHandler = null, ?string $baseBotUrl = null)
{
$this->httpClientHandler = $httpClientHandler ?? new GuzzleHttpClient();

$this->baseBotUrl = $baseBotUrl ?? self::BASE_BOT_URL;
$this->baseFileUrl = $baseBotUrl ?? self::BASE_API_URL;
}

public function getHttpClientHandler(): HttpClientInterface
Expand Down Expand Up @@ -66,9 +61,11 @@ public function sendRequest(TelegramRequest $request): TelegramResponse
*/
public function getFileUrl(string $path, TelegramRequest $request): string
{
$baseFileUrl = str_replace('/bot', '', $this->baseBotUrl);

return str_replace(
['{BASE_FILE_URL}', '{TOKEN}', '{FILE_PATH}'],
[$this->baseFileUrl, $request->getAccessToken(), $path],
['{BASE_BOT_URL}', '{TOKEN}', '{FILE_PATH}'],
[$baseFileUrl, $request->getAccessToken(), $path],
$this->fileUrl
);
}
Expand Down

0 comments on commit 31a71ae

Please sign in to comment.