From fffb129565ddbbc081945897d628bcb189c7ec90 Mon Sep 17 00:00:00 2001 From: Yago Date: Sat, 26 Sep 2015 19:25:57 +0200 Subject: [PATCH] Better chain a 'then' on the getFile promise and return it. --- src/telegram.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/telegram.js b/src/telegram.js index 8a538be..52cf1e4 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -428,19 +428,15 @@ TelegramBot.prototype.getFile = function(fileId) { */ TelegramBot.prototype.getFileLink = function(fileId) { - var bot = this; + var self = this; + return self.getFile(fileId).then(function (resp) { + return URL.format({ + protocol: 'https', + host: 'api.telegram.org', + pathname: '/file/bot' + self.token + '/' + resp.file_path + }); + }); - 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;