sendSticker method

experimental
yago 11 years ago
parent 146157f648
commit ebfe676ddd
  1. 20
      src/telegram.js
  2. 40
      test/index.js
  3. BIN
      test/sticker.webp

@ -315,6 +315,26 @@ TelegramBot.prototype.sendDocument = function (chatId, doc, options) {
return this._request('sendDocument', opts); 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. * Send chat action.
* `typing` for text messages, * `typing` for text messages,

@ -242,4 +242,44 @@ 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();
});
});
});
}); });

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Loading…
Cancel
Save