diff --git a/src/telegram.js b/src/telegram.js index 7c4858d..cf9f0ba 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -335,6 +335,27 @@ TelegramBot.prototype.sendSticker = function (chatId, sticker, options) { return this._request('sendSticker', opts); }; +/** + * Send video files, Telegram clients support mp4 videos (other formats may be sent whith `sendDocument`) + * @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#sendvideo + */ +TelegramBot.prototype.sendVideo = function (chatId, video, options) { + var opts = { + qs: options || {} + }; + opts.qs.chat_id = chatId; + var content = this._formatSendData('video', video); + opts.formData = content[0]; + opts.qs.video = content[1]; + return this._request('sendVideo', opts); +}; + + /** * Send chat action. * `typing` for text messages, diff --git a/test/index.js b/test/index.js index 72a7d0a..13326b7 100644 --- a/test/index.js +++ b/test/index.js @@ -282,4 +282,44 @@ describe('Telegram', function () { }); }); + describe('#sendVideo', function () { + var videoId; + it('should send a video from file', function (done) { + var bot = new Telegram(TOKEN); + var video = __dirname+'/video.mp4'; + bot.sendVideo(USERID, video).then(function (resp) { + resp.should.be.an.instanceOf(Object); + videoId = resp.video.file_id; + done(); + }); + }); + + it('should send a video from id', function (done) { + var bot = new Telegram(TOKEN); + // Send the same photo as before + bot.sendVideo(USERID, videoId).then(function (resp) { + resp.should.be.an.instanceOf(Object); + done(); + }); + }); + + it('should send a video from fs.readStream', function (done) { + var bot = new Telegram(TOKEN); + var video = fs.createReadStream(__dirname+'/video.mp4'); + bot.sendVideo(USERID, video).then(function (resp) { + resp.should.be.an.instanceOf(Object); + done(); + }); + }); + + it('should send a video from request Stream', function (done) { + var bot = new Telegram(TOKEN); + var sticker = request('http://techslides.com/demos/sample-videos/small.mp4'); + bot.sendVideo(USERID, sticker).then(function (resp) { + resp.should.be.an.instanceOf(Object); + done(); + }); + }); + }); + }); diff --git a/test/video.mp4 b/test/video.mp4 new file mode 100644 index 0000000..1fc4788 Binary files /dev/null and b/test/video.mp4 differ