Skip to content

Commit 10b3fa2

Browse files
committed
Add method getFileData, Use this for download file data.
How to use: after call getFile method you received information about file. Use this information to call getFileData and you received the data file. @link https://core.telegram.org/bots/api#file Signed-off-by: Rafael Souza <rfl.souza@gmail.com>
1 parent 6afc189 commit 10b3fa2

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/Telegram.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
class telegramBot
66
{
7-
const BASE_URL = 'https://api.telegram.org/bot';
8-
7+
const BASE_URL = 'https://api.telegram.org';
8+
const BOT_URL = '/bot';
9+
const FILE_URL = '/file';
10+
911
protected $token;
1012

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

17-
$this->baseURL = self::BASE_URL . $this->token . '/';
19+
$this->baseURL = self::BASE_URL . self::BOT_URL . $this->token . '/';
20+
$this->baseFileURL = self::BASE_URL . self::FILE_URL . self::BOT_URL . $this->token . '/';
1821
}
1922

2023
/**
@@ -309,6 +312,23 @@ public function getFile($file_id)
309312
{
310313
return $this->sendRequest('getFile', compact('file_id'));
311314
}
315+
316+
/**
317+
* Use this method to get file Data.
318+
*
319+
* @link https://core.telegram.org/bots/api#getfile
320+
*
321+
* @see getFile
322+
*
323+
* @param string $file_id
324+
* @param string $file_path Is taken from the getFile response
325+
*
326+
* @return On success, a File Data is returned
327+
*/
328+
public function getFileData($file_id, $file_path)
329+
{
330+
return file_get_contents($this->baseFileURL . $file_path . '?' . http_build_query(compact('file_id')));
331+
}
312332

313333
/**
314334
* Set a Webhook to receive incoming updates via an outgoing webhook.

0 commit comments

Comments
 (0)