mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-09-01 23:05:21 +00:00
sendSticker method
This commit is contained in:
@@ -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,
|
||||||
|
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
BIN
test/sticker.webp
Normal file
BIN
test/sticker.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
Reference in New Issue
Block a user