From fea59f455c18279c3c9c1a4713b3183117a2a69f Mon Sep 17 00:00:00 2001 From: danielperez9430 Date: Fri, 3 May 2024 20:30:33 +0200 Subject: [PATCH] feat: Support Telegram Bot API 7.2 --- CHANGELOG.md | 16 +++++++++ README.md | 2 +- package.json | 2 +- src/telegram.js | 90 +++++++++++++++++++++++++++++++++++++------------ 4 files changed, 87 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dea215e..0d7c133 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.66.0][0.66.0] - 2024-05-03 + +1. Support Telegram Bot API 7.2 (@danielperez9430) + * getBusinessConnection + * replaceStickerInSet + +2. Support for updates: (@danielperez9430) + * business_connection + * business_message + * edited_business_message + * deleted_business_messages + +3. Minor fixes: (@danielperez9430) + * getUserChatBoosts + ## [0.65.1][0.65.1] - 2024-03-09 1. Support for updates (@danielperez9430) @@ -66,6 +81,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). * Fix add thumb in sendAudio, sendVideo and sendVideoNote * Fix getMyCommands and setMyCommands * Suggested tip amounts stringify in sendInvoice + ## [0.60.0][0.60.0] - 2022-10-06 1. Support Telegram Bot API v6.3 (@danielperez9430) diff --git a/README.md b/README.md index fd2ee6f..89ac212 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.7.1-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) +[![Bot API](https://img.shields.io/badge/Bot%20API-v.7.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) diff --git a/package.json b/package.json index 3e4813b..808f779 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-telegram-bot-api", - "version": "0.65.1", + "version": "0.66.0", "description": "Telegram Bot API", "main": "./index.js", "directories": { diff --git a/src/telegram.js b/src/telegram.js index 1855fa7..4ea3f6c 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -677,6 +677,10 @@ class TelegramBot extends EventEmitter { const editedMessage = update.edited_message; const channelPost = update.channel_post; const editedChannelPost = update.edited_channel_post; + const businessConnection = update.business_connection; + const businesssMessage = update.business_message; + const editedBusinessMessage = update.edited_business_message; + const deletedBusinessMessage = update.deleted_business_messages; const messageReaction = update.message_reaction; const messageReactionCount = update.message_reaction_count; const inlineQuery = update.inline_query; @@ -759,6 +763,18 @@ class TelegramBot extends EventEmitter { if (editedChannelPost.caption) { this.emit('edited_channel_post_caption', editedChannelPost); } + } else if (businessConnection) { + debug('Process Update business_connection %j', businessConnection); + this.emit('business_connection', businessConnection); + } else if (businesssMessage) { + debug('Process Update business_message %j', businesssMessage); + this.emit('business_message', businesssMessage); + } else if (editedBusinessMessage) { + debug('Process Update edited_business_message %j', editedBusinessMessage); + this.emit('edited_business_message', editedBusinessMessage); + } else if (deletedBusinessMessage) { + debug('Process Update deleted_business_messages %j', deletedBusinessMessage); + this.emit('deleted_business_messages', deletedBusinessMessage); } else if (messageReaction) { debug('Process Update message_reaction %j', messageReaction); this.emit('message_reaction', messageReaction); @@ -2240,7 +2256,20 @@ class TelegramBot extends EventEmitter { getUserChatBoosts(chatId, pollId, form = {}) { form.chat_id = chatId; form.message_id = pollId; - return this._request('stopPoll', { form }); + return this._request('getUserChatBoosts', { form }); + } + + /** + * Use this method to get information about the connection of the bot with a business account + * + * @param {Number|String} businessConnectionId Unique identifier for the group/channel + * @param {Object} [options] Additional Telegram query options + * @return {Promise} On success, returns [BusinessConnection](https://core.telegram.org/bots/api#businessconnection) object + * @see https://core.telegram.org/bots/api#getbusinessconnection + */ + getBusinessConnection(businessConnectionId, form = {}) { + form.business_connection_id = businessConnectionId; + return this._request('getBusinessConnection', { form }); } /** @@ -2614,7 +2643,6 @@ class TelegramBot extends EventEmitter { * @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"*). Can contain only english letters, digits and underscores. * Must begin with a letter, can't contain consecutive underscores and must end in `"_by_"`. `` is case insensitive. 1-64 characters. - * @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. @@ -2648,9 +2676,11 @@ class TelegramBot extends EventEmitter { * * You must use exactly one of the fields *png_sticker*, *tgs_sticker*, or *webm_sticker* * - * Animated stickers can be added to animated sticker sets and only to them: - * - Animated sticker sets can have up to 50 stickers. - * - Static sticker sets can have up to 120 stickers + * Animated stickers can be added to animated sticker sets and only to them + * + * Note: + * - Emoji sticker sets can have up to 200 sticker + * - Static or Animated sticker sets can have up to 120 stickers * * @param {Number} userId User identifier of sticker set owner * @param {String} name Sticker set name @@ -2716,6 +2746,24 @@ class TelegramBot extends EventEmitter { return this._request('deleteStickerFromSet', { form }); } + /** + * Use this method to replace an existing sticker in a sticker set with a new one + * + * @param {Number} user_id User identifier of the sticker set owner + * @param {String} name Sticker set name + * @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#replacestickerinset + * @todo Add tests for this method! + */ + replaceStickerInSet(userId, name, oldSticker, form = {}) { + form.user_id = userId; + form.name = name; + form.old_sticker = oldSticker; + return this._request('deleteStickerFromSet', { form }); + } + /** * Use this method to change the list of emoji assigned to a regular or custom emoji sticker. @@ -3023,22 +3071,22 @@ class TelegramBot extends EventEmitter { } - /** - * Use this method to delete a message, including service messages, with the following limitations: - * - A message can only be deleted if it was sent less than 48 hours ago. - * - A dice message can only be deleted if it was sent more than 24 hours ago. - * - Bots can delete outgoing messages in groups and supergroups. - * - Bots can delete incoming messages in groups, supergroups and channels. - * - Bots granted `can_post_messages` permissions can delete outgoing messages in channels. - * - If the bot is an administrator of a group, it can delete any message there. - * - If the bot has `can_delete_messages` permission in a supergroup, it can delete any message there. - * - * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) - * @param {Number} messageId Unique identifier of the target message - * @param {Object} [options] Additional Telegram query options - * @return {Promise} True on success - * @see https://core.telegram.org/bots/api#deletemessage - */ + /** + * Use this method to delete a message, including service messages, with the following limitations: + * - A message can only be deleted if it was sent less than 48 hours ago. + * - A dice message can only be deleted if it was sent more than 24 hours ago. + * - Bots can delete outgoing messages in groups and supergroups. + * - Bots can delete incoming messages in groups, supergroups and channels. + * - Bots granted `can_post_messages` permissions can delete outgoing messages in channels. + * - If the bot is an administrator of a group, it can delete any message there. + * - If the bot has `can_delete_messages` permission in a supergroup, it can delete any message there. + * + * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param {Number} messageId Unique identifier of the target message + * @param {Object} [options] Additional Telegram query options + * @return {Promise} True on success + * @see https://core.telegram.org/bots/api#deletemessage + */ deleteMessage(chatId, messageId, form = {}) { form.chat_id = chatId; form.message_id = messageId;