mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 13:27:44 +00:00
Merge branch 'getFile' of https://github.com/universome/node-telegram-bot-api into universome-getFile
This commit is contained in:
commit
e8978d4bcb
15
README.md
15
README.md
@ -264,4 +264,19 @@ See: https://core.telegram.org/bots/api#sendlocation
|
|||||||
|
|
||||||
* **Promise**
|
* **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 -->
|
<!-- End src/telegram.js -->
|
||||||
|
@ -389,4 +389,20 @@ TelegramBot.prototype.sendLocation = function (chatId, latitude, longitude, opti
|
|||||||
return this._request('sendLocation', {qs: query});
|
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;
|
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
|
}); // End Telegram
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user