Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/broelik/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