Skip to content

Commit c2f408d

Browse files
committed
Change API URL (for proxy using)
1 parent 8728aab commit c2f408d

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/TelegramBotApi.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
use telegram\query\TUnbanChatMemberQuery;
3939

4040
class TelegramBotApi{
41-
private $baseURL = 'https://api.telegram.org/bot%s/%s';
41+
private $apiURL = 'https://api.telegram.org';
42+
private $baseURL = '%s/bot%s/%s';
4243
private $token;
4344
/**
4445
* @var Proxy
@@ -55,6 +56,18 @@ function __construct(?string $token = null){
5556
$this->token = $token;
5657
$this->json = new JsonProcessor;
5758
}
59+
60+
/**
61+
* @param string $url
62+
* @return TelegramBotApi
63+
*/
64+
function setApiURL(string $url){
65+
if(!str::startsWith($url, 'https://')) throw new TelegramException('HTTPS protocol required');
66+
if(str::endsWith($url, '/')) $url = str::sub($url, 0, str::length($url)-1);
67+
$this->apiURL = $url;
68+
return $this;
69+
}
70+
5871
/**
5972
* @return TGetMeQuery
6073
*/
@@ -264,7 +277,7 @@ private function formatMultipart(array $args, string $boundary){
264277
* @return URLConnection
265278
*/
266279
private function createConnection(string $method, bool $multipart = false, ?string $boundary = null){
267-
$connection = URLConnection::create(str::format($this->baseURL, $this->token, $method), $this->proxy);
280+
$connection = URLConnection::create(str::format($this->baseURL, $this->apiURL, $this->token, $method), $this->proxy);
268281
$connection->doInput = true;
269282
$connection->doOutput = true;
270283
$connection->requestMethod = 'POST';

src/telegram/TelegramBotApi.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
use telegram\query\TUnbanChatMemberQuery;
3939

4040
class TelegramBotApi{
41-
private $baseURL = 'https://api.telegram.org/bot%s/%s';
41+
private $apiURL = 'https://api.telegram.org';
42+
private $baseURL = '%s/bot%s/%s';
4243
private $token;
4344
/**
4445
* @var Proxy
@@ -55,6 +56,18 @@ function __construct(?string $token = null){
5556
$this->token = $token;
5657
$this->json = new JsonProcessor;
5758
}
59+
60+
/**
61+
* @param string $url
62+
* @return TelegramBotApi
63+
*/
64+
function setApiURL(string $url){
65+
if(!str::startsWith($url, 'https://')) throw new TelegramException('HTTPS protocol required');
66+
if(str::endsWith($url, '/')) $url = str::sub($url, 0, str::length($url)-1);
67+
$this->apiURL = $url;
68+
return $this;
69+
}
70+
5871
/**
5972
* @return TGetMeQuery
6073
*/
@@ -264,7 +277,7 @@ private function formatMultipart(array $args, string $boundary){
264277
* @return URLConnection
265278
*/
266279
private function createConnection(string $method, bool $multipart = false, ?string $boundary = null){
267-
$connection = URLConnection::create(str::format($this->baseURL, $this->token, $method), $this->proxy);
280+
$connection = URLConnection::create(str::format($this->baseURL, $this->apiURL, $this->token, $method), $this->proxy);
268281
$connection->doInput = true;
269282
$connection->doOutput = true;
270283
$connection->requestMethod = 'POST';

src/telegram/query/TGetFileQuery.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function file_id($value){
2020
}
2121

2222
/**
23+
* @todo change domain for downloading file
2324
* @return TFile
2425
*/
2526
function query(){

0 commit comments

Comments
 (0)