Skip to content

Commit 485957f

Browse files
committed
add custom API support
1 parent af28595 commit 485957f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Telegram.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Telegram
8585
*/
8686
const MY_CHAT_MEMBER = 'my_chat_member';
8787

88+
private $api;
8889
private $bot_token;
8990
private $data;
9091
private $updates = [];
@@ -99,12 +100,13 @@ class Telegram
99100
* @param $proxy array with the proxy configuration (url, port, type, auth)
100101
* @return void an instance of the class.
101102
*/
102-
public function __construct($bot_token, $log_errors = true, array $proxy = [])
103+
public function __construct($bot_token, $log_errors = true, array $proxy = [], $api = 'https://api.telegram.org')
103104
{
104105
$this->bot_token = $bot_token;
105106
$this->data = $this->getData();
106107
$this->log_errors = $log_errors;
107108
$this->proxy = $proxy;
109+
$this->api = $api;
108110
}
109111

110112
/**
@@ -116,7 +118,7 @@ public function __construct($bot_token, $log_errors = true, array $proxy = [])
116118
*/
117119
public function endpoint($api, array $content, $post = true)
118120
{
119-
$url = 'https://api.telegram.org/bot'.$this->bot_token.'/'.$api;
121+
$url = $this->api.'/bot'.$this->bot_token.'/'.$api;
120122
if ($post) {
121123
$reply = $this->sendAPIRequest($url, $content);
122124
} else {
@@ -658,7 +660,7 @@ public function stopPoll(array $content)
658660
*/
659661
public function downloadFile($telegram_file_path, $local_file_path)
660662
{
661-
$file_url = 'https://api.telegram.org/file/bot'.$this->bot_token.'/'.$telegram_file_path;
663+
$file_url = $this->api.'/file/bot'.$this->bot_token.'/'.$telegram_file_path;
662664
$in = fopen($file_url, 'rb');
663665
$out = fopen($local_file_path, 'wb');
664666

0 commit comments

Comments
 (0)