Skip to content

Commit

Permalink
Merge pull request #14 from rflsouza/master
Browse files Browse the repository at this point in the history
Add method getFileData, Use this for download file data.
  • Loading branch information
mgp25 committed Jan 8, 2016
2 parents b76efb2 + 507c30c commit 7281d4e
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

class telegramBot
{
const BASE_URL = 'https://api.telegram.org/bot';

const BASE_URL = 'https://api.telegram.org';
const BOT_URL = '/bot';
const FILE_URL = '/file';

protected $token;

public function __construct($token)
Expand All @@ -14,7 +16,8 @@ public function __construct($token)
if (is_null($this->token))
throw new TelegramException('Required "token" key not supplied');

$this->baseURL = self::BASE_URL . $this->token . '/';
$this->baseURL = self::BASE_URL . self::BOT_URL . $this->token . '/';
$this->baseFileURL = self::BASE_URL . self::FILE_URL . self::BOT_URL . $this->token . '/';
}

/**
Expand Down Expand Up @@ -291,7 +294,7 @@ public function sendChatAction($chat_id, $action)
*/
public function getUserProfilePhotos($user_id, $offset = null, $limit = null)
{
$param = compact('user_id', 'offset', 'limit');
$params = compact('user_id', 'offset', 'limit');

return $this->sendRequest('getUserProfilePhotos', $params);
}
Expand All @@ -309,6 +312,23 @@ public function getFile($file_id)
{
return $this->sendRequest('getFile', compact('file_id'));
}

/**
* Use this method to get file Data.
*
* @link https://core.telegram.org/bots/api#getfile
*
* @see getFile
*
* @param string $file_id
* @param string $file_path Is taken from the getFile response
*
* @return On success, a File Data is returned
*/
public function getFileData($file_id, $file_path)
{
return file_get_contents($this->baseFileURL . $file_path . '?' . http_build_query(compact('file_id')));
}

/**
* Set a Webhook to receive incoming updates via an outgoing webhook.
Expand Down

0 comments on commit 7281d4e

Please sign in to comment.