Skip to content

Commit

Permalink
Merge pull request #15 from jfkz/extendent-options
Browse files Browse the repository at this point in the history
Implement function getFileUrl
  • Loading branch information
akbarjoudi authored Mar 20, 2020
2 parents 86ffbb2 + ef433bc commit d5e0226
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public function forwardMessage(array $option){
*/
public function sendPhoto(array $option){
$chat_id = $option['chat_id'];
$photo = $option['photo'];
unset($option['chat_id']);
$jsonResponse = $this->curl_call("https://api.telegram.org/bot" .
$this->botToken . "/sendPhoto?chat_id=".$chat_id, $option);
unset($option['photo']);
$jsonResponse = $this->curl_call("https://api.telegram.org/bot" . $this->botToken . "/sendPhoto?chat_id=".$chat_id . "&photo=".$photo, $option);
return json_decode($jsonResponse);
}

Expand Down Expand Up @@ -251,7 +252,7 @@ public function setWebhook(array $option = []){
*
*/
public function deleteWebhook(array $option = []){
$jsonResponse = $this->curl_call("https://api.telegram.org/bot" . $this->botToken . "/setWebhook", $option);
$jsonResponse = $this->curl_call("https://api.telegram.org/bot" . $this->botToken . "/deleteWebhook", $option);
return json_decode($jsonResponse);
}

Expand Down Expand Up @@ -543,7 +544,6 @@ public function kickChatMember(array $option = [])
* 'user_id' => Integer, //Unique identifier of the target user
* ]);
*
* This object represents one row of the high scores table for a game.
*/
public function unbanChatMember(array $option = [])
{
Expand Down Expand Up @@ -674,7 +674,7 @@ public function hook()

/**
* Yii::$app->telegram->getFile([
* 'file_id' => $file_id
* 'file_id' => $file_id
* ]);
*
*/
Expand All @@ -683,6 +683,23 @@ public function getFile($option) {
return json_decode($jsonResponse);
}

/**
* Yii::$app->telegram->getFileUrl([
* 'file_id' => $file_id
* ]);
*
* Return file url by file_id
*/
public function getFileUrl($option) {
$jsonResponse = $this->curl_call("https://api.telegram.org/bot" . $this->botToken . "/getFile", $option);
$result = json_decode($jsonResponse);
if ($result->ok && isset($result->result) && isset($result->result->file_path))
{
return "https://api.telegram.org/file/bot" . $this->botToken . "/" . $result->result->file_path;
}
return false;
}

private function array_push_assoc(&$array, $key, $value){
$array[$key] = $value;
}
Expand Down

0 comments on commit d5e0226

Please sign in to comment.