From ab5928669b210de256bd1e53b2b12ffa1b29c3da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Sun, 6 Nov 2022 02:54:23 +0100 Subject: [PATCH] feat: Telegram Bot API v6.3 (#1020) * feat: Telegram Topics * update docs * fix: test * update: docs --- CHANGELOG.md | 14 ++++++ README.md | 2 +- doc/api.md | 120 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- src/telegram.js | 115 +++++++++++++++++++++++++++++++++++++++++++++ test/telegram.js | 3 +- 6 files changed, 253 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b429af4..b959b3b 100644 --- a/CHANGELOG.md +++ b/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.60.0][0.60.0] - 2022-10-06 + +1. Support Telegram Bot API v6.3 (@danielperez9430) + * createForumTopic + * closeForumTopic + * reopenForumTopic + * deleteForumTopic + * unpinAllForumTopicMessages + * getForumTopicIconStickers + +2. Fix test getMyDefaultAdministratorRights (@danielperez9430) + +3. Fix parse entities - (@toniop99) + ## [0.59.0][0.59.0] - 2022-08-15 1. Support Telegram Bot API v6.2 (@danielperez9430) diff --git a/README.md b/README.md index 211a716..420370b 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.2-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) +[![Bot API](https://img.shields.io/badge/Bot%20API-v.6.3-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) diff --git a/doc/api.md b/doc/api.md index 4324c6c..21e5fa0 100644 --- a/doc/api.md +++ b/doc/api.md @@ -87,6 +87,13 @@ TelegramBot * [.getChatMember(chatId, userId, [options])](#TelegramBot+getChatMember) ⇒ Promise * [.setChatStickerSet(chatId, stickerSetName, [options])](#TelegramBot+setChatStickerSet) ⇒ Promise * [.deleteChatStickerSet(chatId, [options])](#TelegramBot+deleteChatStickerSet) ⇒ Promise + * [.getForumTopicIconStickers(chatId, [options])](#TelegramBot+getForumTopicIconStickers) ⇒ Promise + * [.createForumTopic(chatId, name, [options])](#TelegramBot+createForumTopic) + * [.editForumTopic(chatId, messageThreadId, name, iconCustomEmojiId, [options])](#TelegramBot+editForumTopic) ⇒ Promise + * [.closeForumTopic(chatId, messageThreadId, [options])](#TelegramBot+closeForumTopic) ⇒ Promise + * [.reopenForumTopic(chatId, messageThreadId, [options])](#TelegramBot+reopenForumTopic) ⇒ Promise + * [.deleteForumTopic(chatId, messageThreadId, [options])](#TelegramBot+deleteForumTopic) ⇒ Promise + * [.unpinAllForumTopicMessages(chatId, messageThreadId, [options])](#TelegramBot+unpinAllForumTopicMessages) ⇒ Promise * [.answerCallbackQuery(callbackQueryId, [options])](#TelegramBot+answerCallbackQuery) ⇒ Promise * [.setMyCommands(commands, [options])](#TelegramBot+setMyCommands) ⇒ Promise * [.deleteMyCommands([options])](#TelegramBot+deleteMyCommands) ⇒ Promise @@ -1365,6 +1372,119 @@ Use the field `can_set_sticker_set` optionally returned in [getChat](https://cor | chatId | Number \| String | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) | | [options] | Object | Additional Telegram query options | + + +### telegramBot.getForumTopicIconStickers(chatId, [options]) ⇒ Promise +Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. + +**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#getforumtopiciconstickers + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.createForumTopic(chatId, name, [options]) +Use this method to create a topic in a forum supergroup chat. +The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. + +Returns information about the created topic as a [ForumTopic](https://core.telegram.org/bots/api#forumtopic) object. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#createforumtopic + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) | +| name | String | Topic name, 1-128 characters | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.editForumTopic(chatId, messageThreadId, name, iconCustomEmojiId, [options]) ⇒ Promise +Use this method to edit name and icon of a topic in a forum supergroup chat. +The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - True on success +**See**: https://core.telegram.org/bots/api#editforumtopic + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) | +| messageThreadId | Number | Unique identifier for the target message thread of the forum topic | +| name | String | New topic name, 1-128 characters | +| iconCustomEmojiId | String | New unique identifier of the custom emoji shown as the topic icon. Use [getForumTopicIconStickers](https://core.telegram.org/bots/api#getforumtopiciconstickers) to get all allowed custom emoji identifiers | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.closeForumTopic(chatId, messageThreadId, [options]) ⇒ Promise +Use this method to close an open topic in a forum supergroup chat. +The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - True on success +**See**: https://core.telegram.org/bots/api#closeforumtopic + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) | +| messageThreadId | Number | Unique identifier for the target message thread of the forum topic | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.reopenForumTopic(chatId, messageThreadId, [options]) ⇒ Promise +Use this method to reopen a closed topic in a forum supergroup chat. +The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - True on success +**See**: https://core.telegram.org/bots/api#reopenforumtopic + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) | +| messageThreadId | Number | Unique identifier for the target message thread of the forum topic | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.deleteForumTopic(chatId, messageThreadId, [options]) ⇒ Promise +Use this method to delete a forum topic along with all its messages in a forum supergroup chat. +The bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - True on success +**See**: https://core.telegram.org/bots/api#deleteforumtopic + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) | +| messageThreadId | Number | Unique identifier for the target message thread of the forum topic | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.unpinAllForumTopicMessages(chatId, messageThreadId, [options]) ⇒ Promise +Use this method to clear the list of pinned messages in a forum topic. +The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - True on success +**See**: https://core.telegram.org/bots/api#unpinallforumtopicmessages + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) | +| messageThreadId | Number | Unique identifier for the target message thread of the forum topic | +| [options] | Object | Additional Telegram query options | + ### telegramBot.answerCallbackQuery(callbackQueryId, [options]) ⇒ Promise diff --git a/package.json b/package.json index 3cf3fd1..233da35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-telegram-bot-api", - "version": "0.59.0", + "version": "0.60.0", "description": "Telegram Bot API", "main": "./index.js", "directories": { diff --git a/src/telegram.js b/src/telegram.js index 168172b..5e7ef8e 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1880,6 +1880,121 @@ class TelegramBot extends EventEmitter { return this._request('deleteChatStickerSet', { form }); } + /** + * Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. + * + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) + * @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#getforumtopiciconstickers + */ + getForumTopicIconStickers(chatId, form = {}) { + form.chat_id = chatId; + return this._request('getForumTopicIconStickers', { form }); + } + + /** + * Use this method to create a topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. + * + * Returns information about the created topic as a [ForumTopic](https://core.telegram.org/bots/api#forumtopic) object. + * + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) + * @param {String} name Topic name, 1-128 characters + * @param {Object} [options] Additional Telegram query options + * @see https://core.telegram.org/bots/api#createforumtopic + */ + createForumTopic(chatId, name, form = {}) { + form.chat_id = chatId; + form.name = name; + return this._request('createForumTopic', { form }); + } + + /** + * Use this method to edit name and icon of a topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. + * + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) + * @param {Number} messageThreadId Unique identifier for the target message thread of the forum topic + * @param {String} name New topic name, 1-128 characters + * @param {String} iconCustomEmojiId New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers + * @param {Object} [options] Additional Telegram query options + * @return {Promise} True on success + * @see https://core.telegram.org/bots/api#editforumtopic + */ + editForumTopic(chatId, messageThreadId, name, iconCustomEmojiId, form = {}) { + form.chat_id = chatId; + form.message_thread_id = messageThreadId; + form.name = name; + form.icon_custom_emoji_id = iconCustomEmojiId; + return this._request('editForumTopic', { form }); + } + + /** + * Use this method to close an open topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. + * + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) + * @param {Number} messageThreadId Unique identifier for the target message thread of the forum topic + * @param {Object} [options] Additional Telegram query options + * @return {Promise} True on success + * @see https://core.telegram.org/bots/api#closeforumtopic + */ + closeForumTopic(chatId, messageThreadId, form = {}) { + form.chat_id = chatId; + form.message_thread_id = messageThreadId; + return this._request('closeForumTopic', { form }); + } + + /** + * Use this method to reopen a closed topic in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. + * + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) + * @param {Number} messageThreadId Unique identifier for the target message thread of the forum topic + * @param {Object} [options] Additional Telegram query options + * @return {Promise} True on success + * @see https://core.telegram.org/bots/api#reopenforumtopic + */ + reopenForumTopic(chatId, messageThreadId, form = {}) { + form.chat_id = chatId; + form.message_thread_id = messageThreadId; + return this._request('reopenForumTopic', { form }); + } + + /** + * Use this method to delete a forum topic along with all its messages in a forum supergroup chat. + * The bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights. + * + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) + * @param {Number} messageThreadId Unique identifier for the target message thread of the forum topic + * @param {Object} [options] Additional Telegram query options + * @return {Promise} True on success + * @see https://core.telegram.org/bots/api#deleteforumtopic + */ + deleteForumTopic(chatId, messageThreadId, form = {}) { + form.chat_id = chatId; + form.message_thread_id = messageThreadId; + return this._request('deleteForumTopic', { form }); + } + + /** + * Use this method to clear the list of pinned messages in a forum topic. + * The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. + * + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) + * @param {Number} messageThreadId Unique identifier for the target message thread of the forum topic + * @param {Object} [options] Additional Telegram query options + * @return {Promise} True on success + * @see https://core.telegram.org/bots/api#unpinallforumtopicmessages + */ + unpinAllForumTopicMessages(chatId, messageThreadId, form = {}) { + form.chat_id = chatId; + form.message_thread_id = messageThreadId; + return this._request('unpinAllForumTopicMessages', { form }); + } + + /** * Use this method to send answers to callback queries sent from * [inline keyboards](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating). diff --git a/test/telegram.js b/test/telegram.js index dac7efb..55284d4 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -1485,7 +1485,8 @@ describe('TelegramBot', function telegramSuite() { can_pin_messages: true, can_promote_members: false, can_manage_video_chats: false, - is_anonymous: false + is_anonymous: false, + can_manage_topics: false, })); }); });