mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-22 18:07:16 +00:00
src/telegram: Add TelegramBot#uploadStickerFile
Notes: * Closes PR #430 References: * FR: https://github.com/yagop/node-telegram-bot-api/issues/407 * PR: https://github.com/yagop/node-telegram-bot-api/pull/430 * PR-by: @CapacitorSet
This commit is contained in:
parent
a2d85b889a
commit
8fd243e6a8
@ -7,7 +7,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
Added:
|
||||
|
||||
1. (#429) Add *TelegramBot#getStickerSet* (by @CapacitorSet, @LibertyLocked)
|
||||
1. Add methods:
|
||||
* (#429) Add *TelegramBot#getStickerSet* (by @CapacitorSet, @LibertyLocked)
|
||||
* (#430) Add *TelegramBot#uploadStickerFile* (by @CapacitorSet)
|
||||
|
||||
|
||||
* * *
|
||||
|
16
doc/api.md
16
doc/api.md
@ -76,6 +76,7 @@ TelegramBot
|
||||
* [.answerShippingQuery(shippingQueryId, ok, [options])](#TelegramBot+answerShippingQuery) ⇒ <code>Promise</code>
|
||||
* [.answerPreCheckoutQuery(preCheckoutQueryId, ok, [options])](#TelegramBot+answerPreCheckoutQuery) ⇒ <code>Promise</code>
|
||||
* [.getStickerSet(name, [options])](#TelegramBot+getStickerSet) ⇒ <code>Promise</code>
|
||||
* [.uploadStickerFile(userId, pngSticker, [options])](#TelegramBot+uploadStickerFile) ⇒ <code>Promise</code>
|
||||
* _static_
|
||||
* [.Promise](#TelegramBot.Promise)
|
||||
|
||||
@ -991,6 +992,21 @@ Use this method to get a sticker set. On success, a [StickerSet](https://core.te
|
||||
| name | <code>String</code> | Name of the sticker set |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+uploadStickerFile"></a>
|
||||
|
||||
### telegramBot.uploadStickerFile(userId, pngSticker, [options]) ⇒ <code>Promise</code>
|
||||
Use this method to upload a .png file with a sticker for later use in *createNewStickerSet* and *addStickerToSet* methods (can be used multiple
|
||||
times). Returns the uploaded [File](https://core.telegram.org/bots/api#file) on success.
|
||||
|
||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||
**See**: https://core.telegram.org/bots/api#uploadstickerfile
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| userId | <code>Number</code> | User identifier of sticker file owner |
|
||||
| pngSticker | <code>String</code> | <code>stream.Stream</code> | <code>Buffer</code> | A file path or a Stream. Can also be a `file_id` previously uploaded. **Png** image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot.Promise"></a>
|
||||
|
||||
### TelegramBot.Promise
|
||||
|
@ -1512,6 +1512,32 @@ class TelegramBot extends EventEmitter {
|
||||
form.name = name;
|
||||
return this._request('getStickerSet', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to upload a .png file with a sticker for later use in *createNewStickerSet* and *addStickerToSet* methods (can be used multiple
|
||||
* times). Returns the uploaded [File](https://core.telegram.org/bots/api#file) on success.
|
||||
*
|
||||
* @param {Number} userId User identifier of sticker file owner
|
||||
* @param {String|stream.Stream|Buffer} pngSticker A file path or a Stream. Can also be a `file_id` previously uploaded. **Png** image with the
|
||||
* sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise}
|
||||
* @see https://core.telegram.org/bots/api#uploadstickerfile
|
||||
*/
|
||||
uploadStickerFile(userId, pngSticker, options = {}) {
|
||||
const opts = {
|
||||
qs: options,
|
||||
};
|
||||
opts.qs.user_id = userId;
|
||||
try {
|
||||
const sendData = this._formatSendData('png_sticker', pngSticker);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.png_sticker = sendData[1];
|
||||
} catch (ex) {
|
||||
return Promise.reject(ex);
|
||||
}
|
||||
return this._request('uploadStickerFile', opts);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TelegramBot;
|
||||
|
BIN
test/data/sticker.png
Normal file
BIN
test/data/sticker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 182 KiB |
@ -1371,4 +1371,18 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#uploadStickerFile', function sendPhotoSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'uploadStickerFile', this);
|
||||
});
|
||||
it('should upload a sticker from file', function test() {
|
||||
const sticker = `${__dirname}/data/sticker.png`;
|
||||
return bot.uploadStickerFile(USERID, sticker).then(resp => {
|
||||
assert.ok(is.object(resp));
|
||||
assert.ok(is.string(resp.file_id));
|
||||
});
|
||||
});
|
||||
// Other tests (eg. Buffer, URL) are skipped, because they rely on the same features as sendPhoto.
|
||||
});
|
||||
}); // End Telegram
|
||||
|
Loading…
x
Reference in New Issue
Block a user