mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-22 18:07:16 +00:00
feat: Telegram Bot API Support 6.6 + 6.7 [WIP] (#1069)
* feat: Telegram Bot API Support * refactor: uploadStickerFile * feat: Support Telegram Bot API v6.7 * fix: tests * feat: Test for deleteStickerSet
This commit is contained in:
parent
2885db0e31
commit
542002ec0d
14
CHANGELOG.md
14
CHANGELOG.md
@ -3,6 +3,20 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [0.62.0][0.62.0] - 2023-03-19
|
||||
|
||||
1. Support Telegram Bot API v6.6 (@danielperez9430)
|
||||
* setMyDescription
|
||||
* getMyDescription
|
||||
* setMyShortDescription
|
||||
* getMyShortDescription
|
||||
* setCustomEmojiStickerSetThumbnail
|
||||
* setStickerSetTitle
|
||||
* deleteStickerSet
|
||||
* setStickerEmojiList
|
||||
* setStickerKeywords
|
||||
* setStickerMaskPosition
|
||||
|
||||
## [0.61.0][0.61.0] - 2022-12-30
|
||||
|
||||
1. Support Telegram Bot API v6.4 (@danielperez9430)
|
||||
|
220
doc/api.md
220
doc/api.md
@ -103,6 +103,12 @@ TelegramBot
|
||||
* [.setMyCommands(commands, [options])](#TelegramBot+setMyCommands) ⇒ <code>Promise</code>
|
||||
* [.deleteMyCommands([options])](#TelegramBot+deleteMyCommands) ⇒ <code>Promise</code>
|
||||
* [.getMyCommands([options])](#TelegramBot+getMyCommands) ⇒ <code>Promise</code>
|
||||
* [.setMyName([options])](#TelegramBot+setMyName) ⇒ <code>Promise</code>
|
||||
* [.getMyName([options])](#TelegramBot+getMyName) ⇒ <code>Promise</code>
|
||||
* [.setMyDescription([options])](#TelegramBot+setMyDescription) ⇒ <code>Promise</code>
|
||||
* [.getMyDescription([options])](#TelegramBot+getMyDescription) ⇒ <code>Promise</code>
|
||||
* [.setMyShortDescription([options])](#TelegramBot+setMyShortDescription) ⇒ <code>Promise</code>
|
||||
* [.getMyShortDescription([options])](#TelegramBot+getMyShortDescription) ⇒ <code>Promise</code>
|
||||
* [.setChatMenuButton([options])](#TelegramBot+setChatMenuButton) ⇒ <code>Promise</code>
|
||||
* [.getChatMenuButton([options])](#TelegramBot+getChatMenuButton) ⇒ <code>Promise</code>
|
||||
* [.setMyDefaultAdministratorRights([options])](#TelegramBot+setMyDefaultAdministratorRights) ⇒ <code>Promise</code>
|
||||
@ -116,12 +122,18 @@ TelegramBot
|
||||
* [.sendSticker(chatId, sticker, [options], [fileOptions])](#TelegramBot+sendSticker) ⇒ <code>Promise</code>
|
||||
* [.getStickerSet(name, [options])](#TelegramBot+getStickerSet) ⇒ <code>Promise</code>
|
||||
* [.getCustomEmojiStickers(custom_emoji_ids, [options])](#TelegramBot+getCustomEmojiStickers) ⇒ <code>Promise</code>
|
||||
* [.uploadStickerFile(userId, pngSticker, [options], [fileOptions])](#TelegramBot+uploadStickerFile) ⇒ <code>Promise</code>
|
||||
* [.uploadStickerFile(userId, sticker, stickerFormat, [options], [fileOptions])](#TelegramBot+uploadStickerFile) ⇒ <code>Promise</code>
|
||||
* [.createNewStickerSet(userId, name, title, pngSticker, emojis, [options], [fileOptions])](#TelegramBot+createNewStickerSet) ⇒ <code>Promise</code>
|
||||
* [.addStickerToSet(userId, name, sticker, emojis, stickerType, [options], [fileOptions])](#TelegramBot+addStickerToSet) ⇒ <code>Promise</code>
|
||||
* [.setStickerPositionInSet(sticker, position, [options])](#TelegramBot+setStickerPositionInSet) ⇒ <code>Promise</code>
|
||||
* [.deleteStickerFromSet(sticker, [options])](#TelegramBot+deleteStickerFromSet) ⇒ <code>Promise</code>
|
||||
* [.setStickerSetThumb(userId, name, pngThumb, [options], [fileOptions])](#TelegramBot+setStickerSetThumb) ⇒ <code>Promise</code>
|
||||
* [.setStickerEmojiList(sticker, emojiList, [options])](#TelegramBot+setStickerEmojiList) ⇒ <code>Promise</code>
|
||||
* [.setStickerKeywords(sticker, [options])](#TelegramBot+setStickerKeywords) ⇒ <code>Promise</code>
|
||||
* [.setStickerMaskPosition(sticker, [options])](#TelegramBot+setStickerMaskPosition) ⇒ <code>Promise</code>
|
||||
* [.setStickerSetTitle(name, title, [options])](#TelegramBot+setStickerSetTitle) ⇒ <code>Promise</code>
|
||||
* [.setStickerSetThumbnail(userId, name, thumbnail, [options], [fileOptions])](#TelegramBot+setStickerSetThumbnail) ⇒ <code>Promise</code>
|
||||
* [.setCustomEmojiStickerSetThumbnail(name, [options])](#TelegramBot+setCustomEmojiStickerSetThumbnail) ⇒ <code>Promise</code>
|
||||
* [.deleteStickerSet(name, [options])](#TelegramBot+deleteStickerSet) ⇒ <code>Promise</code>
|
||||
* [.answerInlineQuery(inlineQueryId, results, [options])](#TelegramBot+answerInlineQuery) ⇒ <code>Promise</code>
|
||||
* [.answerWebAppQuery(webAppQueryId, result, [options])](#TelegramBot+answerWebAppQuery) ⇒ <code>Promise</code>
|
||||
* [.sendInvoice(chatId, title, description, payload, providerToken, currency, prices, [options])](#TelegramBot+sendInvoice) ⇒ <code>Promise</code>
|
||||
@ -1632,6 +1644,87 @@ Use this method to get the current list of the bot's commands for the given scop
|
||||
| --- | --- | --- |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+setMyName"></a>
|
||||
|
||||
### telegramBot.setMyName([options]) ⇒ <code>Promise</code>
|
||||
Use this method to change the bot's name.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - True on success
|
||||
**See**: https://core.telegram.org/bots/api#setmyname
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+getMyName"></a>
|
||||
|
||||
### telegramBot.getMyName([options]) ⇒ <code>Promise</code>
|
||||
Use this method to get the current bot name for the given user language.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - [BotName](https://core.telegram.org/bots/api#botname) on success
|
||||
**See**: https://core.telegram.org/bots/api#getmyname
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+setMyDescription"></a>
|
||||
|
||||
### telegramBot.setMyDescription([options]) ⇒ <code>Promise</code>
|
||||
Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty.
|
||||
|
||||
Returns True on success.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - True on success
|
||||
**See**: https://core.telegram.org/bots/api#setmydescription
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+getMyDescription"></a>
|
||||
|
||||
### telegramBot.getMyDescription([options]) ⇒ <code>Promise</code>
|
||||
Use this method to get the current bot description for the given user language.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - Returns [BotDescription](https://core.telegram.org/bots/api#botdescription) on success.
|
||||
**See**: https://core.telegram.org/bots/api#getmydescription
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+setMyShortDescription"></a>
|
||||
|
||||
### telegramBot.setMyShortDescription([options]) ⇒ <code>Promise</code>
|
||||
Use this method to change the bot's short description, which is shown on the bot's profile page
|
||||
and is sent together with the link when users share the bot.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - Returns True on success.
|
||||
**See**: https://core.telegram.org/bots/api#setmyshortdescription
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+getMyShortDescription"></a>
|
||||
|
||||
### telegramBot.getMyShortDescription([options]) ⇒ <code>Promise</code>
|
||||
Use this method to get the current bot short description for the given user language.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - Returns [BotShortDescription](https://core.telegram.org/bots/api#botshortdescription) on success.
|
||||
**See**: https://core.telegram.org/bots/api#getmyshortdescription
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+setChatMenuButton"></a>
|
||||
|
||||
### telegramBot.setChatMenuButton([options]) ⇒ <code>Promise</code>
|
||||
@ -1839,20 +1932,21 @@ Use this method to get information about custom emoji stickers by their identifi
|
||||
|
||||
<a name="TelegramBot+uploadStickerFile"></a>
|
||||
|
||||
### telegramBot.uploadStickerFile(userId, pngSticker, [options], [fileOptions]) ⇒ <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
|
||||
### telegramBot.uploadStickerFile(userId, sticker, stickerFormat, [options], [fileOptions]) ⇒ <code>Promise</code>
|
||||
Use this method to upload a file with a sticker for later use in *createNewStickerSet* and *addStickerToSet* methods (can be used multiple
|
||||
times).
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - On success, a [File](https://core.telegram.org/bots/api#file) object is returned
|
||||
**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 |
|
||||
| [fileOptions] | <code>Object</code> | Optional file related meta-data |
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| userId | <code>Number</code> | | User identifier of sticker file owner |
|
||||
| sticker | <code>String</code> \| <code>stream.Stream</code> \| <code>Buffer</code> | | A file path or a Stream with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. Can also be a `file_id` previously uploaded. |
|
||||
| stickerFormat | <code>String</code> | <code>static</code> | Allow values: `static`, `animated` or `video` |
|
||||
| [options] | <code>Object</code> | | Additional Telegram query options |
|
||||
| [fileOptions] | <code>Object</code> | | Optional file related meta-data |
|
||||
|
||||
<a name="TelegramBot+createNewStickerSet"></a>
|
||||
|
||||
@ -1935,25 +2029,123 @@ Use this method to delete a sticker from a set created by the bot.
|
||||
| sticker | <code>String</code> | File identifier of the sticker |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+setStickerSetThumb"></a>
|
||||
<a name="TelegramBot+setStickerEmojiList"></a>
|
||||
|
||||
### telegramBot.setStickerSetThumb(userId, name, pngThumb, [options], [fileOptions]) ⇒ <code>Promise</code>
|
||||
### telegramBot.setStickerEmojiList(sticker, emojiList, [options]) ⇒ <code>Promise</code>
|
||||
Use this method to change the list of emoji assigned to a regular or custom emoji sticker.
|
||||
|
||||
The sticker must belong to a sticker set created by the bot.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - True on success
|
||||
**See**: https://core.telegram.org/bots/api#setstickeremojilist
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| sticker | <code>String</code> | File identifier of the sticker |
|
||||
| emojiList | <code>Array</code> | A JSON-serialized list of 1-20 emoji associated with the sticker |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+setStickerKeywords"></a>
|
||||
|
||||
### telegramBot.setStickerKeywords(sticker, [options]) ⇒ <code>Promise</code>
|
||||
Use this method to change the list of emoji assigned to a `regular` or `custom emoji` sticker.
|
||||
|
||||
The sticker must belong to a sticker set created by the bot.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - True on success
|
||||
**See**: https://core.telegram.org/bots/api#setstickerkeywords
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| sticker | <code>String</code> | File identifier of the sticker |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+setStickerMaskPosition"></a>
|
||||
|
||||
### telegramBot.setStickerMaskPosition(sticker, [options]) ⇒ <code>Promise</code>
|
||||
Use this method to change the [mask position](https://core.telegram.org/bots/api#maskposition) of a mask sticker.
|
||||
|
||||
The sticker must belong to a sticker set created by the bot.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - True on success
|
||||
**See**: https://core.telegram.org/bots/api#setstickermaskposition
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| sticker | <code>String</code> | File identifier of the sticker |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+setStickerSetTitle"></a>
|
||||
|
||||
### telegramBot.setStickerSetTitle(name, title, [options]) ⇒ <code>Promise</code>
|
||||
Use this method to set the title of a created sticker set.
|
||||
|
||||
The sticker must belong to a sticker set created by the bot.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - True on success
|
||||
**See**: https://core.telegram.org/bots/api#setstickersettitle
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>String</code> | Sticker set name |
|
||||
| title | <code>String</code> | Sticker set title, 1-64 characters |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+setStickerSetThumbnail"></a>
|
||||
|
||||
### telegramBot.setStickerSetThumbnail(userId, name, thumbnail, [options], [fileOptions]) ⇒ <code>Promise</code>
|
||||
Use this method to add a thumb to a set created by the bot.
|
||||
|
||||
Animated thumbnails can be set for animated sticker sets only. Video thumbnails can be set only for video sticker sets only
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - True on success
|
||||
**See**: https://core.telegram.org/bots/api#setstickersetthumb
|
||||
**See**: https://core.telegram.org/bots/api#setstickersetthumbnail
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| userId | <code>Number</code> | User identifier of sticker set owner |
|
||||
| name | <code>String</code> | Sticker set name |
|
||||
| pngThumb | <code>String</code> \| <code>stream.Stream</code> \| <code>Buffer</code> | A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, a TGS animation with the thumbnail up to 32 kilobytes in size or a WEBM video with the thumbnail up to 32 kilobytes in size. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one. Animated sticker set thumbnails can't be uploaded via HTTP URL. |
|
||||
| thumbnail | <code>String</code> \| <code>stream.Stream</code> \| <code>Buffer</code> | A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, a TGS animation with the thumbnail up to 32 kilobytes in size or a WEBM video with the thumbnail up to 32 kilobytes in size. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one. Animated sticker set thumbnails can't be uploaded via HTTP URL. |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
| [fileOptions] | <code>Object</code> | Optional file related meta-data |
|
||||
|
||||
<a name="TelegramBot+setCustomEmojiStickerSetThumbnail"></a>
|
||||
|
||||
### telegramBot.setCustomEmojiStickerSetThumbnail(name, [options]) ⇒ <code>Promise</code>
|
||||
Use this method to set the thumbnail of a custom emoji sticker set.
|
||||
|
||||
The sticker must belong to a sticker set created by the bot.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - True on success
|
||||
**See**: https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>String</code> | Sticker set name |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+deleteStickerSet"></a>
|
||||
|
||||
### telegramBot.deleteStickerSet(name, [options]) ⇒ <code>Promise</code>
|
||||
Use this method to delete a sticker set that was created by the bot.
|
||||
|
||||
The sticker must belong to a sticker set created by the bot.
|
||||
|
||||
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
|
||||
**Returns**: <code>Promise</code> - True on success
|
||||
**See**: https://core.telegram.org/bots/api#deletestickerset
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| name | <code>String</code> | Sticker set name |
|
||||
| [options] | <code>Object</code> | Additional Telegram query options |
|
||||
|
||||
<a name="TelegramBot+answerInlineQuery"></a>
|
||||
|
||||
### telegramBot.answerInlineQuery(inlineQueryId, results, [options]) ⇒ <code>Promise</code>
|
||||
|
209
src/telegram.js
209
src/telegram.js
@ -237,7 +237,7 @@ class TelegramBot extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
_fixAddFileThumb(options, opts) {
|
||||
_fixAddFileThumbnail(options, opts) {
|
||||
if (options.thumb) {
|
||||
if (opts.formData === null) {
|
||||
opts.formData = {};
|
||||
@ -248,7 +248,7 @@ class TelegramBot extends EventEmitter {
|
||||
|
||||
if (formData) {
|
||||
opts.formData[attachName] = formData[attachName];
|
||||
opts.qs.thumb = `attach://${attachName}`;
|
||||
opts.qs.thumbnail = `attach://${attachName}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1003,7 +1003,7 @@ class TelegramBot extends EventEmitter {
|
||||
const sendData = this._formatSendData('audio', audio, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.audio = sendData[1];
|
||||
this._fixAddFileThumb(options, opts);
|
||||
this._fixAddFileThumbnail(options, opts);
|
||||
} catch (ex) {
|
||||
return Promise.reject(ex);
|
||||
}
|
||||
@ -1031,7 +1031,7 @@ class TelegramBot extends EventEmitter {
|
||||
const sendData = this._formatSendData('document', doc, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.document = sendData[1];
|
||||
this._fixAddFileThumb(options, opts);
|
||||
this._fixAddFileThumbnail(options, opts);
|
||||
} catch (ex) {
|
||||
return Promise.reject(ex);
|
||||
}
|
||||
@ -1060,7 +1060,7 @@ class TelegramBot extends EventEmitter {
|
||||
const sendData = this._formatSendData('video', video, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.video = sendData[1];
|
||||
this._fixAddFileThumb(options, opts);
|
||||
this._fixAddFileThumbnail(options, opts);
|
||||
} catch (ex) {
|
||||
return Promise.reject(ex);
|
||||
}
|
||||
@ -1143,7 +1143,7 @@ class TelegramBot extends EventEmitter {
|
||||
const sendData = this._formatSendData('video_note', videoNote, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.video_note = sendData[1];
|
||||
this._fixAddFileThumb(options, opts);
|
||||
this._fixAddFileThumbnail(options, opts);
|
||||
} catch (ex) {
|
||||
return Promise.reject(ex);
|
||||
}
|
||||
@ -1469,7 +1469,6 @@ class TelegramBot extends EventEmitter {
|
||||
* The bot **must be an administrator** in the chat for this to work
|
||||
* and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user.
|
||||
*
|
||||
*
|
||||
* @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
|
||||
* @param {Number} userId
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
@ -2159,6 +2158,75 @@ class TelegramBot extends EventEmitter {
|
||||
return this._request('getMyCommands', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to change the bot's name.
|
||||
*
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} True on success
|
||||
* @see https://core.telegram.org/bots/api#setmyname
|
||||
*/
|
||||
setMyName(form = {}) {
|
||||
return this._request('setMyName', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to get the current bot name for the given user language.
|
||||
*
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} [BotName](https://core.telegram.org/bots/api#botname) on success
|
||||
* @see https://core.telegram.org/bots/api#getmyname
|
||||
*/
|
||||
getMyName(form = {}) {
|
||||
return this._request('getMyName', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty.
|
||||
*
|
||||
* Returns True on success.
|
||||
*
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} True on success
|
||||
* @see https://core.telegram.org/bots/api#setmydescription
|
||||
*/
|
||||
setMyDescription(form = {}) {
|
||||
return this._request('setMyDescription', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to get the current bot description for the given user language.
|
||||
*
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} Returns [BotDescription](https://core.telegram.org/bots/api#botdescription) on success.
|
||||
* @see https://core.telegram.org/bots/api#getmydescription
|
||||
*/
|
||||
getMyDescription(form = {}) {
|
||||
return this._request('getMyDescription', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to change the bot's short description, which is shown on the bot's profile page
|
||||
* and is sent together with the link when users share the bot.
|
||||
*
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} Returns True on success.
|
||||
* @see https://core.telegram.org/bots/api#setmyshortdescription
|
||||
*/
|
||||
setMyShortDescription(form = {}) {
|
||||
return this._request('setMyShortDescription', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to get the current bot short description for the given user language.
|
||||
*
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} Returns [BotShortDescription](https://core.telegram.org/bots/api#botshortdescription) on success.
|
||||
* @see https://core.telegram.org/bots/api#getmyshortdescription
|
||||
*/
|
||||
getMyShortDescription(form = {}) {
|
||||
return this._request('getMyShortDescription', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to change the bot's menu button in a private chat, or the default menu button.
|
||||
*
|
||||
@ -2397,26 +2465,28 @@ class TelegramBot extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to upload a .png file with a sticker for later use in *createNewStickerSet* and *addStickerToSet* methods (can be used multiple
|
||||
* Use this method to upload a file with a sticker for later use in *createNewStickerSet* and *addStickerToSet* methods (can be used multiple
|
||||
* times).
|
||||
*
|
||||
* @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 {String|stream.Stream|Buffer} sticker A file path or a Stream with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. Can also be a `file_id` previously uploaded.
|
||||
* @param {String} stickerFormat Allow values: `static`, `animated` or `video`
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @param {Object} [fileOptions] Optional file related meta-data
|
||||
* @return {Promise} On success, a [File](https://core.telegram.org/bots/api#file) object is returned
|
||||
* @see https://core.telegram.org/bots/api#uploadstickerfile
|
||||
*/
|
||||
uploadStickerFile(userId, pngSticker, options = {}, fileOptions = {}) {
|
||||
uploadStickerFile(userId, sticker, stickerFormat = 'static', options = {}, fileOptions = {}) {
|
||||
const opts = {
|
||||
qs: options,
|
||||
};
|
||||
opts.qs.user_id = userId;
|
||||
opts.qs.sticker_format = stickerFormat;
|
||||
|
||||
try {
|
||||
const sendData = this._formatSendData('png_sticker', pngSticker, fileOptions);
|
||||
const sendData = this._formatSendData('sticker', sticker, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.png_sticker = sendData[1];
|
||||
opts.qs.sticker = sendData[1];
|
||||
} catch (ex) {
|
||||
return Promise.reject(ex);
|
||||
}
|
||||
@ -2536,6 +2606,76 @@ class TelegramBot extends EventEmitter {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use this method to change the list of emoji assigned to a regular or custom emoji sticker.
|
||||
*
|
||||
* The sticker must belong to a sticker set created by the bot.
|
||||
*
|
||||
* @param {String} sticker File identifier of the sticker
|
||||
* @param { Array } emojiList A JSON-serialized list of 1-20 emoji associated with the sticker
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} True on success
|
||||
* @see https://core.telegram.org/bots/api#setstickeremojilist
|
||||
*/
|
||||
setStickerEmojiList(sticker, emojiList, form = {}) {
|
||||
form.sticker = sticker;
|
||||
form.emoji_list = stringify(emojiList);
|
||||
return this._request('setStickerEmojiList', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to change the list of emoji assigned to a `regular` or `custom emoji` sticker.
|
||||
*
|
||||
* The sticker must belong to a sticker set created by the bot.
|
||||
*
|
||||
* @param {String} sticker File identifier of the sticker
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} True on success
|
||||
* @see https://core.telegram.org/bots/api#setstickerkeywords
|
||||
*/
|
||||
setStickerKeywords(sticker, form = {}) {
|
||||
form.sticker = sticker;
|
||||
if (form.keywords) {
|
||||
form.keywords = stringify(form.keywords);
|
||||
}
|
||||
return this._request('setStickerKeywords', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to change the [mask position](https://core.telegram.org/bots/api#maskposition) of a mask sticker.
|
||||
*
|
||||
* The sticker must belong to a sticker set created by the bot.
|
||||
*
|
||||
* @param {String} sticker File identifier of the sticker
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} True on success
|
||||
* @see https://core.telegram.org/bots/api#setstickermaskposition
|
||||
*/
|
||||
setStickerMaskPosition(sticker, form = {}) {
|
||||
form.sticker = sticker;
|
||||
if (form.mask_position) {
|
||||
form.mask_position = stringify(form.mask_position);
|
||||
}
|
||||
return this._request('setStickerMaskPosition', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to set the title of a created sticker set.
|
||||
*
|
||||
* The sticker must belong to a sticker set created by the bot.
|
||||
*
|
||||
* @param {String} name Sticker set name
|
||||
* @param {String} title Sticker set title, 1-64 characters
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} True on success
|
||||
* @see https://core.telegram.org/bots/api#setstickersettitle
|
||||
*/
|
||||
setStickerSetTitle(name, title, form = {}) {
|
||||
form.name = name;
|
||||
form.title = title;
|
||||
return this._request('setStickerSetTitle', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to add a thumb to a set created by the bot.
|
||||
*
|
||||
@ -2543,7 +2683,7 @@ class TelegramBot extends EventEmitter {
|
||||
*
|
||||
* @param {Number} userId User identifier of sticker set owner
|
||||
* @param {String} name Sticker set name
|
||||
* @param {String|stream.Stream|Buffer} pngThumb A PNG image with the thumbnail,
|
||||
* @param {String|stream.Stream|Buffer} thumbnail A .WEBP or .PNG image with the thumbnail,
|
||||
* must be up to 128 kilobytes in size and have width and height exactly 100px,
|
||||
* a TGS animation with the thumbnail up to 32 kilobytes in size or a WEBM video with the thumbnail up to 32 kilobytes in size.
|
||||
*
|
||||
@ -2552,9 +2692,9 @@ class TelegramBot extends EventEmitter {
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @param {Object} [fileOptions] Optional file related meta-data
|
||||
* @return {Promise} True on success
|
||||
* @see https://core.telegram.org/bots/api#setstickersetthumb
|
||||
* @see https://core.telegram.org/bots/api#setstickersetthumbnail
|
||||
*/
|
||||
setStickerSetThumb(userId, name, pngThumb, options = {}, fileOptions = {}) {
|
||||
setStickerSetThumbnail(userId, name, thumbnail, options = {}, fileOptions = {}) {
|
||||
const opts = {
|
||||
qs: options,
|
||||
};
|
||||
@ -2562,13 +2702,44 @@ class TelegramBot extends EventEmitter {
|
||||
opts.qs.name = name;
|
||||
opts.qs.mask_position = stringify(options.mask_position);
|
||||
try {
|
||||
const sendData = this._formatSendData('thumb', pngThumb, fileOptions);
|
||||
const sendData = this._formatSendData('thumbnail', thumbnail, fileOptions);
|
||||
opts.formData = sendData[0];
|
||||
opts.qs.thumb = sendData[1];
|
||||
opts.qs.thumbnail = sendData[1];
|
||||
} catch (ex) {
|
||||
return Promise.reject(ex);
|
||||
}
|
||||
return this._request('setStickerSetThumb', opts);
|
||||
return this._request('setStickerSetThumbnail', opts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use this method to set the thumbnail of a custom emoji sticker set.
|
||||
*
|
||||
* The sticker must belong to a sticker set created by the bot.
|
||||
*
|
||||
* @param {String} name Sticker set name
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} True on success
|
||||
* @see https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
|
||||
*/
|
||||
setCustomEmojiStickerSetThumbnail(name, form = {}) {
|
||||
form.name = name;
|
||||
return this._request('setCustomEmojiStickerSetThumbnail', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to delete a sticker set that was created by the bot.
|
||||
*
|
||||
* The sticker must belong to a sticker set created by the bot.
|
||||
*
|
||||
* @param {String} name Sticker set name
|
||||
* @param {Object} [options] Additional Telegram query options
|
||||
* @return {Promise} True on success
|
||||
* @see https://core.telegram.org/bots/api#deletestickerset
|
||||
*/
|
||||
deleteStickerSet(name, form = {}) {
|
||||
form.name = name;
|
||||
return this._request('deleteStickerSet', { form });
|
||||
}
|
||||
|
||||
/**
|
||||
|
164
test/telegram.js
164
test/telegram.js
@ -50,6 +50,7 @@ let GAME_MSG_ID;
|
||||
let BOT_USERNAME;
|
||||
let CHAT_INFO;
|
||||
let STICKER_FILE_ID_FROM_SET;
|
||||
let STICKERS_FROM_BOT_SET;
|
||||
|
||||
before(function beforeAll() {
|
||||
utils.startStaticServer(staticPort);
|
||||
@ -1418,6 +1419,74 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setMyDescription', function getMyCommandsSuite() {
|
||||
it('should set bot description for users with a specific lang code', function test() {
|
||||
return bot.setMyDescription({ description: 'Bot description' }).then(resp => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
it('should set bot description for Spanish users', function test() {
|
||||
return bot.setMyDescription({ description: 'Spanish bot description', language_code: 'es' }).then(resp => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setMyName', function setMyNameSuite() {
|
||||
it('should set bot name for Spanish users', function test() {
|
||||
return bot.setMyName({ name: 'Spanish Bot', language_code: 'es' }).then(resp => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getMyName', function setMyNameSuite() {
|
||||
it('should get bot name for Spanish users', function test() {
|
||||
return bot.getMyName({ language_code: 'es' }).then(resp => {
|
||||
assert.ok(is.equal(resp.name, 'Spanish Bot'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getMyDescription', function getMyDescriptionSuite() {
|
||||
it('should get bot description for a user without lang code', function test() {
|
||||
return bot.getMyDescription().then(resp => {
|
||||
assert.ok(is.equal(resp.description, 'Bot description'));
|
||||
});
|
||||
});
|
||||
it('should get bot description for Spanish users', function test() {
|
||||
return bot.getMyDescription({ language_code: 'es' }).then(resp => {
|
||||
assert.ok(is.equal(resp.description, 'Spanish bot description'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setMyShortDescription', function setMyShortDescriptionSuite() {
|
||||
it('should set sort bot description for a user without lang code', function test() {
|
||||
return bot.setMyShortDescription({ short_description: 'Bot sort description' }).then(resp => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
it('should set sort description for Spanish users', function test() {
|
||||
return bot.setMyShortDescription({ short_description: 'Spanish bot sort description', language_code: 'es' }).then(resp => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getMyShortDescription', function getMyShortDescriptionSuite() {
|
||||
it('should get bot sort description for a user without lang code', function test() {
|
||||
return bot.getMyShortDescription().then(resp => {
|
||||
assert.ok(is.equal(resp.short_description, 'Bot sort description'));
|
||||
});
|
||||
});
|
||||
it('should get bot sort description for Spanish users', function test() {
|
||||
return bot.getMyShortDescription({ language_code: 'es' }).then(resp => {
|
||||
assert.ok(is.equal(resp.short_description, 'Spanish bot sort description'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getMyCommands', function getMyCommandsSuite() {
|
||||
it('should get bot commands', function test() {
|
||||
return bot.getMyCommands().then(resp => {
|
||||
@ -1781,16 +1850,105 @@ describe('TelegramBot', function telegramSuite() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setStickerSetThumb', function setStickerSetThumbSuite() {
|
||||
describe('#setStickerEmojiList', function setStickerEmojiListSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'setStickerSetThumb', this);
|
||||
utils.handleRatelimit(bot, 'setStickerEmojiList', this);
|
||||
});
|
||||
|
||||
it('should get the list for the given sticker of the bot sticker pack', function test(done) {
|
||||
const stickerPackName = `s${CURRENT_TIMESTAMP}_by_${BOT_USERNAME}`;
|
||||
|
||||
bot.getStickerSet(stickerPackName).then(resp => {
|
||||
STICKERS_FROM_BOT_SET = resp.stickers;
|
||||
assert.ok(is.array(STICKERS_FROM_BOT_SET));
|
||||
});
|
||||
|
||||
setTimeout(() => done(), 2000);
|
||||
});
|
||||
|
||||
it('should set a emoji list for the given sticker', function test() {
|
||||
assert.ok(is.equal(STICKERS_FROM_BOT_SET[0].type, 'regular'));
|
||||
|
||||
bot.setStickerEmojiList(STICKERS_FROM_BOT_SET[0].file_id, ['🥳', '😀', '😇']).then((resp) => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setStickerKeywords', function setStickerKeywordsSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'setStickerKeywords', this);
|
||||
});
|
||||
it('should set a keywords list for the given sticker', function test() {
|
||||
assert.ok(is.equal(STICKERS_FROM_BOT_SET[0].type, 'regular'));
|
||||
bot.setStickerKeywords(STICKERS_FROM_BOT_SET[0].file_id, { keywords: ['house', 'cat'] }).then((resp) => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#setStickerMaskPosition', function setStickerKeywordsSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'setStickerMaskPosition', this);
|
||||
});
|
||||
it('should delete a sticker from a set', function test() {
|
||||
bot.setStickerMaskPosition(STICKER_FILE_ID_FROM_SET, { point: 'eyes', scale: 2, x_shift: 1, y_shift: 1 }).then((resp) => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setStickerSetTitle', function setStickerSetTitleSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'setStickerSetTitle', this);
|
||||
});
|
||||
it('should set a new sticker set title', function test() {
|
||||
const stickerPackName = `s${CURRENT_TIMESTAMP}_by_${BOT_USERNAME}`;
|
||||
|
||||
bot.setStickerSetTitle(stickerPackName, 'New title').then((resp) => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setStickerSetThumbnail', function setStickerSetThumbnailSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'setStickerSetThumbnail', this);
|
||||
});
|
||||
|
||||
it('should set a sticker set thumb', function test() {
|
||||
const stickerThumb = `${__dirname}/data/sticker_thumb.png`;
|
||||
const stickerPackName = `s${CURRENT_TIMESTAMP}_by_${BOT_USERNAME}`;
|
||||
|
||||
bot.setStickerSetThumb(USERID, stickerPackName, stickerThumb).then((resp) => {
|
||||
bot.setStickerSetThumbnail(USERID, stickerPackName, stickerThumb).then((resp) => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#setCustomEmojiStickerSetThumbnail', function setCustomEmojiStickerSetThumbnailSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'setCustomEmojiStickerSetThumbnail', this);
|
||||
});
|
||||
|
||||
it('should set a custom emoji sticjer set as thumbnail', function test() {
|
||||
const stickerPackName = `s${CURRENT_TIMESTAMP}_by_${BOT_USERNAME}`;
|
||||
|
||||
bot.setCustomEmojiStickerSetThumbnail(stickerPackName, { custom_emoji_id: null }).then((resp) => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#deleteStickerSet', function deleteStickerSetSuite() {
|
||||
before(function before() {
|
||||
utils.handleRatelimit(bot, 'deleteStickerSet', this);
|
||||
});
|
||||
|
||||
it('should delete sticker set', function test() {
|
||||
const stickerPackName = `s${CURRENT_TIMESTAMP}_by_${BOT_USERNAME}`;
|
||||
|
||||
bot.deleteStickerSet(stickerPackName).then((resp) => {
|
||||
assert.ok(is.boolean(resp));
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user