Skip to content

Commit cb80fc0

Browse files
authored
Merge pull request #2 from TsSaltan/master
Изменение API URL
2 parents d451ce2 + 82f1f4b commit cb80fc0

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

README.MD

+3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ $api->sendMessage()
108108
->query();
109109
```
110110

111+
## Использование прокси сервера
112+
[PHP proxy for Telegram Bot API](https://github.com/TsSaltan/Telegram-bot-api-php-proxy)
113+
111114
## Расширение для DevelNext
112115
[Скачать](https://github.com/jphp-group/jphp-telegram-bot-api/releases/latest)
113116

package.php.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: telegram-bot-api
2-
version: 1.1.0
2+
version: 1.2
33
deps:
44
jphp-core: '*'
55
jphp-json-ext: '*'
@@ -34,7 +34,7 @@ config:
3434
- /LICENSE
3535

3636
develnext-bundle:
37-
version: 1.1.0
37+
version: 1.2
3838
name: Telegram Bot API
3939
author: broelik
4040
icon: "develnext/bundle/telegram/icon32.png"

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

+15-2
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

+15-2
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

+1
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)