10
10
11
11
final class TelegramClient
12
12
{
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} ' ;
19
16
20
17
private HttpClientInterface $ httpClientHandler ;
21
18
22
19
private string $ baseBotUrl ;
20
+ private string $ baseFileUrl ;
23
21
24
- public function __construct (HttpClientInterface $ httpClientHandler = null , string $ baseBotUrl = null )
22
+ public function __construct (? HttpClientInterface $ httpClientHandler = null , ? string $ baseBotUrl = null )
25
23
{
26
24
$ this ->httpClientHandler = $ httpClientHandler ?? new GuzzleHttpClient ();
25
+
27
26
$ this ->baseBotUrl = $ baseBotUrl ?? self ::BASE_BOT_URL ;
27
+ $ this ->baseFileUrl = $ baseBotUrl ?? self ::BASE_API_URL ;
28
28
}
29
29
30
30
public function getHttpClientHandler (): HttpClientInterface
@@ -64,8 +64,8 @@ public function sendRequest(TelegramRequest $request): TelegramResponse
64
64
public function getFileUrl (string $ path , TelegramRequest $ request ): string
65
65
{
66
66
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 ],
69
69
$ this ->fileUrl
70
70
);
71
71
}
@@ -95,7 +95,7 @@ public function download(string $filePath, string $filename, TelegramRequest $re
95
95
$ request ->getMethod (),
96
96
$ request ->getHeaders (),
97
97
['sink ' => $ filename ],
98
- $ request ->isAsyncRequest (),
98
+ $ request ->isAsyncRequest ()
99
99
);
100
100
101
101
if ($ response ->getStatusCode () !== 200 ) {
@@ -107,7 +107,7 @@ public function download(string $filePath, string $filename, TelegramRequest $re
107
107
108
108
public function prepareRequest (TelegramRequest $ request ): array
109
109
{
110
- $ url = $ this ->baseBotUrl .' /bot ' . $ request ->getAccessToken ().'/ ' .$ request ->getEndpoint ();
110
+ $ url = $ this ->baseBotUrl .$ request ->getAccessToken ().'/ ' .$ request ->getEndpoint ();
111
111
112
112
return [$ url , $ request ->getMethod (), $ request ->getHeaders (), $ request ->isAsyncRequest ()];
113
113
}
0 commit comments