From fe4afd65338d902b014bf3172af1f194b156a1f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Mon, 15 Aug 2022 21:44:44 +0200 Subject: [PATCH] feat: Support Bot API v6.2 (#996) * docs: Update readme and add Typescript types * feat: getCustomEmojiStickers * feat: Add getCustomEmojiStickers test + fix other test * fix: docs * docs: Update changelog + docs --- CHANGELOG.md | 27 +++++++++++++++++---------- README.md | 19 +++++++++++++------ doc/api.md | 17 ++++++++++++++++- src/telegram.js | 15 ++++++++++++++- test/telegram.js | 26 ++++++++++++++++++++++++-- 5 files changed, 84 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc10f64..c567e95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,30 +3,37 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [0.59.0][0.59.0] - 2022-07-19 +## [0.59.0][0.59.0] - 2022-08-15 -1. Remove dependencies: (@danielperez9430) +1. Support Telegrm Bot API v6.3 (@danielperez9430) + * getCustomEmojiStickers + +2. Support test enviroment (@tinsaeDev & @kamikazechaser) + +3. Remove dependencies: (@danielperez9430) * Remove *bluebird* => Use NodeJS Native Promises * Remove *depd* => Use node native deprecate util for warnings * Remove contributor dev dependency and add list of contributors in the readme -2. Remove legacy methods: (@danielperez9430) +4. Remove legacy methods: (@danielperez9430) * getChatMembersCount * kickChatMember -3. Docs: (@danielperez9430) - * Update the docs of functions - * Order functions follow the Telegram bot API docs in src/telegram.js +5. Docs: (@danielperez9430) + * Update the docs of the methods + * Order methods follow the Telegram bot API docs in src/telegram.js + * Update README -4. Fix: (@danielperez9430) +6. Fix: (@danielperez9430) * addStickerToSet() -> Allow to send tgs_sticker + webm_sticker * Remove mandatory param β€œstart_parameter” from sendInvoice, because in the docs is a optional param - * Fix some tests + * getStickerSet test fix deprecated response value "contains_masks" change to "sticker_type" + * Fix some other tests -5. New Test: (@danielperez9430) +7. New Test: (@danielperez9430) * deleteStickerFromSet * setStickerPositionInSet - + * getCustomEmojiStickers ## [0.58.0][0.58.0] - 2022-06-22 diff --git a/README.md b/README.md index 7268177..d8416a3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Node.js module to interact with the official [Telegram Bot API](https://core.telegram.org/bots/api). -[![Bot API](https://img.shields.io/badge/Bot%20API-v.6.1-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) +[![Bot API](https://img.shields.io/badge/Bot%20API-v.6.2-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) [![npm package](https://img.shields.io/npm/v/node-telegram-bot-api?logo=npm&style=flat-square)](https://www.npmjs.org/package/node-telegram-bot-api) [![Build Status](https://img.shields.io/travis/yagop/node-telegram-bot-api/master?style=flat-square&logo=travis)](https://travis-ci.org/yagop/node-telegram-bot-api) [![Coverage Status](https://img.shields.io/codecov/c/github/yagop/node-telegram-bot-api?style=flat-square&logo=codecov)](https://codecov.io/gh/yagop/node-telegram-bot-api) @@ -16,13 +16,20 @@ Node.js module to interact with the official [Telegram Bot API](https://core.tel -## Install +## πŸ“¦ Install ```sh npm i node-telegram-bot-api ``` -## Usage +
+ +> ✍️ **Note:** If you use Typescript you can install this package that contains type definitions for this library +>```sh +>npm install --save @types/node-telegram-bot-api +>``` + +## πŸš€ Usage ```js const TelegramBot = require('node-telegram-bot-api'); @@ -56,7 +63,7 @@ bot.on('message', (msg) => { }); ``` -## Documentation +## πŸ“š Documentation * [Usage][usage] * [Examples][examples] @@ -71,7 +78,7 @@ Code for the latest release resides on the **release** branch. Experimental features reside on the **experimental** branch._ -## Community +## πŸ’­ Community We thank all the developers in the Open-Source community who continuously take their time and effort in advancing this project. @@ -93,7 +100,7 @@ Some things built using this library that might interest you: * [beetube-bot](https://github.com/kodjunkie/beetube-bot): A telegram bot for music, videos, movies, EDM tracks, torrent downloads, files and more. -## Contributors +## πŸ‘₯ Contributors

diff --git a/doc/api.md b/doc/api.md index fb1a2fd..4324c6c 100644 --- a/doc/api.md +++ b/doc/api.md @@ -103,6 +103,7 @@ TelegramBot * [.deleteMessage(chatId, messageId, [options])](#TelegramBot+deleteMessage) β‡’ Promise * [.sendSticker(chatId, sticker, [options], [fileOptions])](#TelegramBot+sendSticker) β‡’ Promise * [.getStickerSet(name, [options])](#TelegramBot+getStickerSet) β‡’ Promise + * [.getCustomEmojiStickers(custom_emoji_ids, [options])](#TelegramBot+getCustomEmojiStickers) β‡’ Promise * [.uploadStickerFile(userId, pngSticker, [options], [fileOptions])](#TelegramBot+uploadStickerFile) β‡’ Promise * [.createNewStickerSet(userId, name, title, pngSticker, emojis, [options], [fileOptions])](#TelegramBot+createNewStickerSet) β‡’ Promise * [.addStickerToSet(userId, name, sticker, emojis, stickerType, [options], [fileOptions])](#TelegramBot+addStickerToSet) β‡’ Promise @@ -1619,10 +1620,24 @@ Use this method to get a sticker set. | name | String | Name of the sticker set | | [options] | Object | Additional Telegram query options | + + +### telegramBot.getCustomEmojiStickers(custom_emoji_ids, [options]) β‡’ Promise +Use this method to get information about custom emoji stickers by their identifiers. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - Array of [Sticker](https://core.telegram.org/bots/api#sticker) objects. +**See**: https://core.telegram.org/bots/api#getcustomemojistickers + +| Param | Type | Description | +| --- | --- | --- | +| custom_emoji_ids | Array | List of custom emoji identifiers. At most 200 custom emoji identifiers can be specified. | +| [options] | Object | Additional Telegram query options | + ### telegramBot.uploadStickerFile(userId, pngSticker, [options], [fileOptions]) β‡’ Promise -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 .png file with a sticker for later use in *createNewStickerSet* and *addStickerToSet* methods (can be used multiple times). **Kind**: instance method of [TelegramBot](#TelegramBot) diff --git a/src/telegram.js b/src/telegram.js index 6e99ff1..5dd529f 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -2160,7 +2160,20 @@ 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 get information about custom emoji stickers by their identifiers. + * + * @param {Array} custom_emoji_ids List of custom emoji identifiers. At most 200 custom emoji identifiers can be specified. + * @param {Object} [options] Additional Telegram query options + * @return {Promise} Array of [Sticker](https://core.telegram.org/bots/api#sticker) objects. + * @see https://core.telegram.org/bots/api#getcustomemojistickers + */ + getCustomEmojiStickers(customEmojiIds, form = {}) { + form.custom_emoji_ids = stringify(customEmojiIds); + return this._request('getCustomEmojiStickers', { 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). * * @param {Number} userId User identifier of sticker file owner diff --git a/test/telegram.js b/test/telegram.js index 060ab05..dac7efb 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -1694,7 +1694,7 @@ describe('TelegramBot', function telegramSuite() { assert.ok(is.object(resp)); assert.strictEqual(resp.name.toLowerCase(), STICKER_SET_NAME); assert.ok(is.string(resp.title)); - assert.ok(is.boolean(resp.contains_masks)); + assert.ok(is.string(resp.sticker_type)); assert.ok(is.array(resp.stickers)); }); }); @@ -1706,12 +1706,34 @@ describe('TelegramBot', function telegramSuite() { assert.ok(is.object(resp)); assert.strictEqual(resp.name.toLowerCase(), stickerPackName.toLowerCase()); assert.ok(is.string(resp.title)); - assert.ok(is.boolean(resp.contains_masks)); + assert.ok(is.string(resp.sticker_type)); assert.ok(is.array(resp.stickers)); }); }); }); + describe('#getCustomEmojiStickers', function getCustomEmojiStickersSuite() { + const CHERRY_EMOJI_STICKERS_ID = ['5380109565226391871', '5431711346724968789']; + const STICKER_EMOJI_SET_NAME = 'CherryEmoji'; + + it('should get the custom emoji stickers', function test() { + return bot.getCustomEmojiStickers([CHERRY_EMOJI_STICKERS_ID[0]]).then(resp => { + assert.ok(is.array(resp)); + assert.ok(is.object(resp[0])); + assert.ok(is.string(resp[0].set_name) && resp[0].set_name === STICKER_EMOJI_SET_NAME); + assert.ok(resp[0].custom_emoji_id === CHERRY_EMOJI_STICKERS_ID[0]); + }); + }); + it('should get 2 custom emoji stickers', function test() { + return bot.getCustomEmojiStickers(CHERRY_EMOJI_STICKERS_ID).then(resp => { + assert.ok(is.array(resp) && resp.length === 2); + assert.ok(is.object(resp[1])); + assert.ok(is.string(resp[1].set_name) && resp[1].set_name === STICKER_EMOJI_SET_NAME); + assert.ok(resp[1].custom_emoji_id === CHERRY_EMOJI_STICKERS_ID[1]); + }); + }); + }); + describe('#addStickerToSet', function addStickerToSetSuite() { before(function before() {