2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-29 13:27:44 +00:00

Merge branch 'universome-getFile'

This commit is contained in:
Yago 2015-09-26 19:12:40 +02:00
commit 9270f61baf
3 changed files with 57 additions and 0 deletions

View File

@ -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**
<!-- End src/telegram.js -->

View File

@ -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;

View File

@ -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