@ -82,11 +82,7 @@ TelegramBot.prototype._request = function (path, options) {
throw new Error ( 'Telegram Bot Token not provided!' ) ;
throw new Error ( 'Telegram Bot Token not provided!' ) ;
}
}
options = options || { } ;
options = options || { } ;
options . url = URL . format ( {
options . url = this . _buildURL ( path ) ;
protocol : 'https' ,
host : 'api.telegram.org' ,
pathname : '/bot' + this . token + '/' + path
} ) ;
debug ( 'HTTP request: %j' , options ) ;
debug ( 'HTTP request: %j' , options ) ;
return requestPromise ( options )
return requestPromise ( options )
. then ( function ( resp ) {
. then ( function ( resp ) {
@ -102,6 +98,20 @@ TelegramBot.prototype._request = function (path, options) {
} ) ;
} ) ;
} ;
} ;
/ * *
* Generates url with bot token and provided path / method you want to be got / executed by bot
* @ return { String } url
* @ param { String } path
* @ see https : //core.telegram.org/bots/api#making-requests
* /
TelegramBot . prototype . _buildURL = function ( path ) {
return URL . format ( {
protocol : 'https' ,
host : 'api.telegram.org' ,
pathname : '/bot' + this . token + '/' + path
} ) ;
}
/ * *
/ * *
* Returns basic information about the bot in form of a ` User ` object .
* Returns basic information about the bot in form of a ` User ` object .
* @ return { Promise }
* @ return { Promise }
@ -405,4 +415,32 @@ TelegramBot.prototype.getFile = function(fileId) {
return this . _request ( 'getFile' , { qs : query } ) ;
return this . _request ( 'getFile' , { qs : query } ) ;
} ;
} ;
/ * *
* Get link for file .
* Use this method to get link for file for subsequent use .
* Attention : link will be valid for 1 hour .
*
* This method is a sugar extension of the ( getFile ) [ # getfilefileid ] method , which returns just path to file on remote server ( you will have to manually build full uri after that ) .
*
* @ param { String } fileId File identifier to get info about
* @ return { Promise } promise Promise which will have * fileURI * in resolve callback
* @ see https : //core.telegram.org/bots/api#getfile
* /
TelegramBot . prototype . getFileLink = function ( fileId ) {
var bot = this ;
return new Promise ( function ( resolve ) {
bot . getFile ( fileId ) . then ( function ( resp ) {
var fileURI = URL . format ( {
protocol : 'https' ,
host : 'api.telegram.org' ,
pathname : '/file/bot' + bot . token + '/' + resp . file _path
} ) ;
resolve ( fileURI ) ;
} )
} ) ;
} ;
module . exports = TelegramBot ;
module . exports = TelegramBot ;