Skip to content

Commit

Permalink
Merge pull request #2 from TsSaltan/master
Browse files Browse the repository at this point in the history
Изменение API URL
  • Loading branch information
TsSaltan authored Jan 11, 2020
2 parents d451ce2 + 82f1f4b commit cb80fc0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ $api->sendMessage()
->query();
```

## Использование прокси сервера
[PHP proxy for Telegram Bot API](https://github.com/TsSaltan/Telegram-bot-api-php-proxy)

## Расширение для DevelNext
[Скачать](https://github.com/jphp-group/jphp-telegram-bot-api/releases/latest)

Expand Down
4 changes: 2 additions & 2 deletions package.php.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: telegram-bot-api
version: 1.1.0
version: 1.2
deps:
jphp-core: '*'
jphp-json-ext: '*'
Expand Down Expand Up @@ -34,7 +34,7 @@ config:
- /LICENSE

develnext-bundle:
version: 1.1.0
version: 1.2
name: Telegram Bot API
author: broelik
icon: "develnext/bundle/telegram/icon32.png"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
use telegram\query\TUnbanChatMemberQuery;

class TelegramBotApi{
private $baseURL = 'https://api.telegram.org/bot%s/%s';
private $apiURL = 'https://api.telegram.org';
private $baseURL = '%s/bot%s/%s';
private $token;
/**
* @var Proxy
Expand All @@ -55,6 +56,18 @@ function __construct(?string $token = null){
$this->token = $token;
$this->json = new JsonProcessor;
}

/**
* @param string $url
* @return TelegramBotApi
*/
function setApiURL(string $url){
if(!str::startsWith($url, 'https://')) throw new TelegramException('HTTPS protocol required');
if(str::endsWith($url, '/')) $url = str::sub($url, 0, str::length($url)-1);
$this->apiURL = $url;
return $this;
}

/**
* @return TGetMeQuery
*/
Expand Down Expand Up @@ -264,7 +277,7 @@ private function formatMultipart(array $args, string $boundary){
* @return URLConnection
*/
private function createConnection(string $method, bool $multipart = false, ?string $boundary = null){
$connection = URLConnection::create(str::format($this->baseURL, $this->token, $method), $this->proxy);
$connection = URLConnection::create(str::format($this->baseURL, $this->apiURL, $this->token, $method), $this->proxy);
$connection->doInput = true;
$connection->doOutput = true;
$connection->requestMethod = 'POST';
Expand Down
17 changes: 15 additions & 2 deletions src/telegram/TelegramBotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
use telegram\query\TUnbanChatMemberQuery;

class TelegramBotApi{
private $baseURL = 'https://api.telegram.org/bot%s/%s';
private $apiURL = 'https://api.telegram.org';
private $baseURL = '%s/bot%s/%s';
private $token;
/**
* @var Proxy
Expand All @@ -55,6 +56,18 @@ function __construct(?string $token = null){
$this->token = $token;
$this->json = new JsonProcessor;
}

/**
* @param string $url
* @return TelegramBotApi
*/
function setApiURL(string $url){
if(!str::startsWith($url, 'https://')) throw new TelegramException('HTTPS protocol required');
if(str::endsWith($url, '/')) $url = str::sub($url, 0, str::length($url)-1);
$this->apiURL = $url;
return $this;
}

/**
* @return TGetMeQuery
*/
Expand Down Expand Up @@ -264,7 +277,7 @@ private function formatMultipart(array $args, string $boundary){
* @return URLConnection
*/
private function createConnection(string $method, bool $multipart = false, ?string $boundary = null){
$connection = URLConnection::create(str::format($this->baseURL, $this->token, $method), $this->proxy);
$connection = URLConnection::create(str::format($this->baseURL, $this->apiURL, $this->token, $method), $this->proxy);
$connection->doInput = true;
$connection->doOutput = true;
$connection->requestMethod = 'POST';
Expand Down
1 change: 1 addition & 0 deletions src/telegram/query/TGetFileQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function file_id($value){
}

/**
* @todo change domain for downloading file
* @return TFile
*/
function query(){
Expand Down

0 comments on commit cb80fc0

Please sign in to comment.