mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 13:27:44 +00:00
Added getFile method to TelegramBot
This commit is contained in:
parent
9fd97861c3
commit
e85f517e00
15
README.md
15
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**
|
||||
|
||||
<!-- End src/telegram.js -->
|
||||
|
@ -380,4 +380,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;
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user