mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-31 06:16:07 +00:00
src/telegram: Add API v3.2 methods
Notes: Add methods: * TelegramBot#createNewStickerSet * TelegramBot#addStickerToSet * TelegramBot#setStickerPositionInSet * TelegramBot#deleteStickerFromSet Tests are missing! References: * FR: https://github.com/yagop/node-telegram-bot-api/issues/407
This commit is contained in:
@@ -8,8 +8,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
Added:
|
Added:
|
||||||
|
|
||||||
1. Add methods:
|
1. Add methods:
|
||||||
* (#429) Add *TelegramBot#getStickerSet* (by @CapacitorSet, @LibertyLocked)
|
* (#429) *TelegramBot#getStickerSet* (by @CapacitorSet, @LibertyLocked)
|
||||||
* (#430) Add *TelegramBot#uploadStickerFile* (by @CapacitorSet)
|
* (#430) *TelegramBot#uploadStickerFile* (by @CapacitorSet)
|
||||||
|
* *TelegramBot#createNewStickerSet*, *TelegramBot#addStickerToSet*, *TelegramBot#setStickerPositionInSet*, *TelegramBot#deleteStickerFromSet* (by @GochoMugo)
|
||||||
|
|
||||||
|
|
||||||
* * *
|
* * *
|
||||||
|
83
doc/api.md
83
doc/api.md
@@ -77,6 +77,10 @@ TelegramBot
|
|||||||
* [.answerPreCheckoutQuery(preCheckoutQueryId, ok, [options])](#TelegramBot+answerPreCheckoutQuery) ⇒ <code>Promise</code>
|
* [.answerPreCheckoutQuery(preCheckoutQueryId, ok, [options])](#TelegramBot+answerPreCheckoutQuery) ⇒ <code>Promise</code>
|
||||||
* [.getStickerSet(name, [options])](#TelegramBot+getStickerSet) ⇒ <code>Promise</code>
|
* [.getStickerSet(name, [options])](#TelegramBot+getStickerSet) ⇒ <code>Promise</code>
|
||||||
* [.uploadStickerFile(userId, pngSticker, [options])](#TelegramBot+uploadStickerFile) ⇒ <code>Promise</code>
|
* [.uploadStickerFile(userId, pngSticker, [options])](#TelegramBot+uploadStickerFile) ⇒ <code>Promise</code>
|
||||||
|
* [.createNewStickerSet(userId, name, title, pngSticker, emojis, [options])](#TelegramBot+createNewStickerSet) ⇒ <code>Promise</code>
|
||||||
|
* [.addStickerToSet(userId, name, pngSticker, emojis, [options])](#TelegramBot+addStickerToSet) ⇒ <code>Promise</code>
|
||||||
|
* [.setStickerPositionInSet(sticker, position)](#TelegramBot+setStickerPositionInSet) ⇒ <code>Promise</code>
|
||||||
|
* [.deleteStickerFromSet(sticker)](#TelegramBot+deleteStickerFromSet) ⇒ <code>Promise</code>
|
||||||
* _static_
|
* _static_
|
||||||
* [.Promise](#TelegramBot.Promise)
|
* [.Promise](#TelegramBot.Promise)
|
||||||
|
|
||||||
@@ -1007,6 +1011,85 @@ times). Returns the uploaded [File](https://core.telegram.org/bots/api#file) on
|
|||||||
| 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. |
|
| 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 |
|
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||||
|
|
||||||
|
<a name="TelegramBot+createNewStickerSet"></a>
|
||||||
|
|
||||||
|
### telegramBot.createNewStickerSet(userId, name, title, pngSticker, emojis, [options]) ⇒ <code>Promise</code>
|
||||||
|
Use this method to create new sticker set owned by a user.
|
||||||
|
The bot will be able to edit the created sticker set.
|
||||||
|
Returns True on success.
|
||||||
|
|
||||||
|
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||||
|
**See**: https://core.telegram.org/bots/api#createnewstickerset
|
||||||
|
**Todo**
|
||||||
|
|
||||||
|
- [ ] Add tests for this method!
|
||||||
|
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| userId | <code>Number</code> | User identifier of created sticker set owner |
|
||||||
|
| name | <code>String</code> | Short name of sticker set, to be used in `t.me/addstickers/` URLs (e.g., *animals*) |
|
||||||
|
| title | <code>String</code> | Sticker set title, 1-64 characters |
|
||||||
|
| pngSticker | <code>String</code> | <code>stream.Stream</code> | <code>Buffer</code> | 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. |
|
||||||
|
| emojis | <code>String</code> | One or more emoji corresponding to the sticker |
|
||||||
|
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||||
|
|
||||||
|
<a name="TelegramBot+addStickerToSet"></a>
|
||||||
|
|
||||||
|
### telegramBot.addStickerToSet(userId, name, pngSticker, emojis, [options]) ⇒ <code>Promise</code>
|
||||||
|
Use this method to add a new sticker to a set created by the bot.
|
||||||
|
Returns True on success.
|
||||||
|
|
||||||
|
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||||
|
**See**: https://core.telegram.org/bots/api#addstickertoset
|
||||||
|
**Todo**
|
||||||
|
|
||||||
|
- [ ] Add tests for this method!
|
||||||
|
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| userId | <code>Number</code> | User identifier of sticker set owner |
|
||||||
|
| name | <code>String</code> | Sticker set name |
|
||||||
|
| pngSticker | <code>String</code> | <code>stream.Stream</code> | <code>Buffer</code> | 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 |
|
||||||
|
| emojis | <code>String</code> | One or more emoji corresponding to the sticker |
|
||||||
|
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||||
|
|
||||||
|
<a name="TelegramBot+setStickerPositionInSet"></a>
|
||||||
|
|
||||||
|
### telegramBot.setStickerPositionInSet(sticker, position) ⇒ <code>Promise</code>
|
||||||
|
Use this method to move a sticker in a set created by the bot to a specific position.
|
||||||
|
Returns True on success.
|
||||||
|
|
||||||
|
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||||
|
**See**: https://core.telegram.org/bots/api#setstickerpositioninset
|
||||||
|
**Todo**
|
||||||
|
|
||||||
|
- [ ] Add tests for this method!
|
||||||
|
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| sticker | <code>String</code> | File identifier of the sticker |
|
||||||
|
| position | <code>Number</code> | New sticker position in the set, zero-based |
|
||||||
|
|
||||||
|
<a name="TelegramBot+deleteStickerFromSet"></a>
|
||||||
|
|
||||||
|
### telegramBot.deleteStickerFromSet(sticker) ⇒ <code>Promise</code>
|
||||||
|
Use this method to delete a sticker from a set created by the bot.
|
||||||
|
Returns True on success.
|
||||||
|
|
||||||
|
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||||
|
**See**: https://core.telegram.org/bots/api#deletestickerfromset
|
||||||
|
**Todo**
|
||||||
|
|
||||||
|
- [ ] Add tests for this method!
|
||||||
|
|
||||||
|
|
||||||
|
| Param | Type | Description |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| sticker | <code>String</code> | File identifier of the sticker |
|
||||||
|
|
||||||
<a name="TelegramBot.Promise"></a>
|
<a name="TelegramBot.Promise"></a>
|
||||||
|
|
||||||
### TelegramBot.Promise
|
### TelegramBot.Promise
|
||||||
|
@@ -1538,6 +1538,105 @@ class TelegramBot extends EventEmitter {
|
|||||||
}
|
}
|
||||||
return this._request('uploadStickerFile', opts);
|
return this._request('uploadStickerFile', opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this method to create new sticker set owned by a user.
|
||||||
|
* The bot will be able to edit the created sticker set.
|
||||||
|
* Returns True on success.
|
||||||
|
*
|
||||||
|
* @param {Number} userId User identifier of created sticker set owner
|
||||||
|
* @param {String} name Short name of sticker set, to be used in `t.me/addstickers/` URLs (e.g., *animals*)
|
||||||
|
* @param {String} title Sticker set title, 1-64 characters
|
||||||
|
* @param {String|stream.Stream|Buffer} pngSticker 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 {String} emojis One or more emoji corresponding to the sticker
|
||||||
|
* @param {Object} [options] Additional Telegram query options
|
||||||
|
* @return {Promise}
|
||||||
|
* @see https://core.telegram.org/bots/api#createnewstickerset
|
||||||
|
* @todo Add tests for this method!
|
||||||
|
*/
|
||||||
|
createNewStickerSet(userId, name, title, pngSticker, emojis, options = {}) {
|
||||||
|
const opts = {
|
||||||
|
qs: options,
|
||||||
|
};
|
||||||
|
opts.qs.user_id = userId;
|
||||||
|
opts.qs.name = name;
|
||||||
|
opts.qs.title = title;
|
||||||
|
opts.qs.emojis = emojis;
|
||||||
|
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('createNewStickerSet', opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this method to add a new sticker to a set created by the bot.
|
||||||
|
* Returns True on success.
|
||||||
|
*
|
||||||
|
* @param {Number} userId User identifier of sticker set owner
|
||||||
|
* @param {String} name Sticker set name
|
||||||
|
* @param {String|stream.Stream|Buffer} pngSticker 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 {String} emojis One or more emoji corresponding to the sticker
|
||||||
|
* @param {Object} [options] Additional Telegram query options
|
||||||
|
* @return {Promise}
|
||||||
|
* @see https://core.telegram.org/bots/api#addstickertoset
|
||||||
|
* @todo Add tests for this method!
|
||||||
|
*/
|
||||||
|
addStickerToSet(userId, name, pngSticker, emojis, options = {}) {
|
||||||
|
const opts = {
|
||||||
|
qs: options,
|
||||||
|
};
|
||||||
|
opts.qs.user_id = userId;
|
||||||
|
opts.qs.name = name;
|
||||||
|
opts.qs.emojis = emojis;
|
||||||
|
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('addStickerToSet', opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this method to move a sticker in a set created by the bot to a specific position.
|
||||||
|
* Returns True on success.
|
||||||
|
*
|
||||||
|
* @param {String} sticker File identifier of the sticker
|
||||||
|
* @param {Number} position New sticker position in the set, zero-based
|
||||||
|
* @return {Promise}
|
||||||
|
* @see https://core.telegram.org/bots/api#setstickerpositioninset
|
||||||
|
* @todo Add tests for this method!
|
||||||
|
*/
|
||||||
|
setStickerPositionInSet(sticker, position) {
|
||||||
|
const form = {
|
||||||
|
sticker,
|
||||||
|
position,
|
||||||
|
};
|
||||||
|
return this._request('setStickerPositionInSet', { form });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this method to delete a sticker from a set created by the bot.
|
||||||
|
* Returns True on success.
|
||||||
|
*
|
||||||
|
* @param {String} sticker File identifier of the sticker
|
||||||
|
* @return {Promise}
|
||||||
|
* @see https://core.telegram.org/bots/api#deletestickerfromset
|
||||||
|
* @todo Add tests for this method!
|
||||||
|
*/
|
||||||
|
deleteStickerFromSet(sticker) {
|
||||||
|
const form = {
|
||||||
|
sticker,
|
||||||
|
};
|
||||||
|
return this._request('deleteStickerFromSet', { form });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = TelegramBot;
|
module.exports = TelegramBot;
|
||||||
|
Reference in New Issue
Block a user