From c2d4ec145a356f1f473cb1fad45f73ec7872a40e Mon Sep 17 00:00:00 2001 From: Riddler Date: Tue, 7 Jul 2015 13:45:37 +0530 Subject: [PATCH 1/3] Add SendDocument Method Add SendDocument Method --- src/telegram.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/telegram.js b/src/telegram.js index fc06d3d..dd0516c 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -295,6 +295,26 @@ TelegramBot.prototype.sendAudio = function (chatId, audio, options) { return this._request('sendAudio', opts); }; +/** + * Send Document + * @param {Number|String} chatId Unique identifier for the message recipient + * @param {String|stream.Stream} A file path or a Stream. Can + * also be a `file_id` previously uploaded. + * @param {Object} [options] Additional Telegram query options + * @return {Promise} + * @see https://core.telegram.org/bots/api#sendDocument + */ +TelegramBot.prototype.sendDocument = function (chatId, doc, options) { + var opts = { + qs: options || {} + }; + opts.qs.chat_id = chatId; + var content = this._formatSendData('document', doc); + opts.formData = content[0]; + opts.qs.document = content[1]; + return this._request('sendDocument', opts); +}; + /** * Send chat action. * `typing` for text messages, From 16b9d2b69599216924e42594b00462219bdd27f1 Mon Sep 17 00:00:00 2001 From: Riddler Date: Tue, 7 Jul 2015 13:54:57 +0530 Subject: [PATCH 2/3] Add SendDocument Test Add SendDocument Test --- test/index.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/index.js b/test/index.js index 29946bb..84b3af5 100644 --- a/test/index.js +++ b/test/index.js @@ -203,3 +203,45 @@ describe('Telegram', function () { }); + + + describe('#sendDocument', function () { + var documentId; + it('should send a document from file', function (done) { + var bot = new Telegram(TOKEN); + var document = __dirname+'/bot.gif'; + bot.sendDocument(USERID, document).then(function (resp) { + resp.should.be.an.instanceOf(Object); + documentId = resp.document.file_id; + done(); + }); + }); + + it('should send a photo from id', function (done) { + var bot = new Telegram(TOKEN); + // Send the same photo as before + var document = documentId; + bot.sendPhoto(USERID, document).then(function (resp) { + resp.should.be.an.instanceOf(Object); + done(); + }); + }); + + it('should send a photo from fs.readStream', function (done) { + var bot = new Telegram(TOKEN); + var document = fs.createReadStream(__dirname+'/bot.gif'); + bot.sendDocument(USERID, document).then(function (resp) { + resp.should.be.an.instanceOf(Object); + done(); + }); + }); + + it('should send a document from request Stream', function (done) { + var bot = new Telegram(TOKEN); + var document = request('https://telegram.org/img/t_logo.png'); + bot.sendDocument(USERID, document).then(function (resp) { + resp.should.be.an.instanceOf(Object); + done(); + }); + }); + }); From ad8bf01f56a51da48a9bd8b2d4bc0120ad15e08a Mon Sep 17 00:00:00 2001 From: Riddler Date: Tue, 7 Jul 2015 13:58:20 +0530 Subject: [PATCH 3/3] Add SendDocument Test --- test/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.js b/test/index.js index 84b3af5..cd4adb2 100644 --- a/test/index.js +++ b/test/index.js @@ -217,7 +217,7 @@ describe('Telegram', function () { }); }); - it('should send a photo from id', function (done) { + it('should send a document from id', function (done) { var bot = new Telegram(TOKEN); // Send the same photo as before var document = documentId; @@ -227,7 +227,7 @@ describe('Telegram', function () { }); }); - it('should send a photo from fs.readStream', function (done) { + it('should send a document from fs.readStream', function (done) { var bot = new Telegram(TOKEN); var document = fs.createReadStream(__dirname+'/bot.gif'); bot.sendDocument(USERID, document).then(function (resp) {