diff --git a/src/Telegram.php b/src/Telegram.php index ba7f37a..654a30d 100644 --- a/src/Telegram.php +++ b/src/Telegram.php @@ -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) @@ -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 . '/'; } /** @@ -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); } @@ -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.