diff --git a/README.md b/README.md index 2b5dd71..275fc94 100644 --- a/README.md +++ b/README.md @@ -264,4 +264,19 @@ See: https://core.telegram.org/bots/api#sendlocation * **Promise** +## getFile(fileId) + +Get file. +Use this method to get basic info about a file and prepare it for downloading. +Attention: link will be valid for 1 hour. + +See: https://core.telegram.org/bots/api#getfile + +### Params: +* **String** *fileId* File identifier to get info about + +### Return: + +* **Promise** + diff --git a/src/telegram.js b/src/telegram.js index ce6bf46..e14972c 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -389,4 +389,20 @@ TelegramBot.prototype.sendLocation = function (chatId, latitude, longitude, opti return this._request('sendLocation', {qs: query}); }; +/** + * Get file. + * Use this method to get basic info about a file and prepare it for downloading. + * Attention: link will be valid for 1 hour. + * + * @param {String} fileId File identifier to get info about + * @return {Promise} + * @see https://core.telegram.org/bots/api#getfile + */ +TelegramBot.prototype.getFile = function(fileId) { + + var query = { file_id: fileId }; + + return this._request('getFile', {qs: query}); +}; + module.exports = TelegramBot; diff --git a/test/index.js b/test/index.js index 4a8b6b7..cef7065 100644 --- a/test/index.js +++ b/test/index.js @@ -368,6 +368,32 @@ describe('Telegram', function () { }); }); + describe('#getFile', function () { + var fileId; + + // To get a file we have to send any file first + it('should send a photo from file', function (done) { + var bot = new Telegram(TOKEN); + var photo = __dirname + '/bot.gif'; + bot.sendPhoto(USERID, photo).then(function (resp) { + resp.should.be.an.instanceOf(Object); + fileId = resp.photo[0].file_id; + done(); + }); + }); + + it('should get a file', function (done) { + + var bot = new Telegram(TOKEN); + + bot.getFile(fileId).then(function (resp) { + resp.should.be.an.instanceOf(Object); + resp.file_path.should.be.an.instanceOf(String); + done(); + }); + }); + }); + }); // End Telegram