diff --git a/src/telegram.js b/src/telegram.js index dd0516c..7c4858d 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -315,6 +315,26 @@ TelegramBot.prototype.sendDocument = function (chatId, doc, options) { return this._request('sendDocument', opts); }; +/** + * Send .webp stickers. + * @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#sendsticker + */ +TelegramBot.prototype.sendSticker = function (chatId, sticker, options) { + var opts = { + qs: options || {} + }; + opts.qs.chat_id = chatId; + var content = this._formatSendData('sticker', sticker); + opts.formData = content[0]; + opts.qs.sticker = content[1]; + return this._request('sendSticker', opts); +}; + /** * Send chat action. * `typing` for text messages, diff --git a/test/index.js b/test/index.js index 944e645..72a7d0a 100644 --- a/test/index.js +++ b/test/index.js @@ -241,5 +241,45 @@ describe('Telegram', function () { }); }); }); - + + describe('#sendSticker', function () { + var stickerId; + it('should send a sticker from file', function (done) { + var bot = new Telegram(TOKEN); + var sticker = __dirname+'/sticker.webp'; + bot.sendSticker(USERID, sticker).then(function (resp) { + resp.should.be.an.instanceOf(Object); + stickerId = resp.sticker.file_id; + done(); + }); + }); + + it('should send a sticker from id', function (done) { + var bot = new Telegram(TOKEN); + // Send the same photo as before + bot.sendSticker(USERID, stickerId).then(function (resp) { + resp.should.be.an.instanceOf(Object); + done(); + }); + }); + + it('should send a sticker from fs.readStream', function (done) { + var bot = new Telegram(TOKEN); + var sticker = fs.createReadStream(__dirname+'/sticker.webp'); + bot.sendSticker(USERID, sticker).then(function (resp) { + resp.should.be.an.instanceOf(Object); + done(); + }); + }); + + it('should send a sticker from request Stream', function (done) { + var bot = new Telegram(TOKEN); + var sticker = request('https://www.gstatic.com/webp/gallery3/1_webp_ll.webp'); + bot.sendSticker(USERID, sticker).then(function (resp) { + resp.should.be.an.instanceOf(Object); + done(); + }); + }); + }); + }); diff --git a/test/sticker.webp b/test/sticker.webp new file mode 100644 index 0000000..ba39447 Binary files /dev/null and b/test/sticker.webp differ