From 65ef0a2fcccf96e1823b76654ffc909347f5876b Mon Sep 17 00:00:00 2001 From: danielperez9430 Date: Wed, 8 May 2024 15:36:52 +0200 Subject: [PATCH] feat: Support Telegram Bot API 7.3 --- CHANGELOG.md | 2 +- README.md | 2 +- doc/api.md | 87 +++++++++++++++++++++++++++++++++++++++++++++---- src/telegram.js | 4 +-- 4 files changed, 84 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d7c133..9091b88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ 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) +1. Support Telegram Bot API 7.2 & 7.3 (@danielperez9430) * getBusinessConnection * replaceStickerInSet diff --git a/README.md b/README.md index 89ac212..b8101ec 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.2-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) +[![Bot API](https://img.shields.io/badge/Bot%20API-v.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 1fb3270..2207b00 100644 --- a/doc/api.md +++ b/doc/api.md @@ -40,6 +40,7 @@ TelegramBot * [.close([options])](#TelegramBot+close) ⇒ Promise * [.sendMessage(chatId, text, [options])](#TelegramBot+sendMessage) ⇒ Promise * [.forwardMessage(chatId, fromChatId, messageId, [options])](#TelegramBot+forwardMessage) ⇒ Promise + * [.forwardMessages(chatId, fromChatId, messageIds, [options])](#TelegramBot+forwardMessages) ⇒ Promise * [.copyMessage(chatId, fromChatId, messageId, [options])](#TelegramBot+copyMessage) ⇒ Promise * [.copyMessages(chatId, fromChatId, messageIds, [options])](#TelegramBot+copyMessages) ⇒ Promise * [.sendPhoto(chatId, photo, [options], [fileOptions])](#TelegramBot+sendPhoto) ⇒ Promise @@ -103,6 +104,8 @@ TelegramBot * [.unhideGeneralForumTopic(chatId, [options])](#TelegramBot+unhideGeneralForumTopic) ⇒ Promise * [.unpinAllGeneralForumTopicMessages(chatId, [options])](#TelegramBot+unpinAllGeneralForumTopicMessages) ⇒ Promise * [.answerCallbackQuery(callbackQueryId, [options])](#TelegramBot+answerCallbackQuery) ⇒ Promise + * [.getUserChatBoosts(chatId, user_id, [options])](#TelegramBot+getUserChatBoosts) ⇒ Promise + * [.getBusinessConnection(businessConnectionId, [options])](#TelegramBot+getBusinessConnection) ⇒ Promise * [.setMyCommands(commands, [options])](#TelegramBot+setMyCommands) ⇒ Promise * [.deleteMyCommands([options])](#TelegramBot+deleteMyCommands) ⇒ Promise * [.getMyCommands([options])](#TelegramBot+getMyCommands) ⇒ Promise @@ -129,6 +132,7 @@ TelegramBot * [.addStickerToSet(userId, name, sticker, emojis, stickerType, [options], [fileOptions])](#TelegramBot+addStickerToSet) ⇒ Promise * [.setStickerPositionInSet(sticker, position, [options])](#TelegramBot+setStickerPositionInSet) ⇒ Promise * [.deleteStickerFromSet(sticker, [options])](#TelegramBot+deleteStickerFromSet) ⇒ Promise + * [.replaceStickerInSet(user_id, name, sticker, [options])](#TelegramBot+replaceStickerInSet) ⇒ Promise * [.setStickerEmojiList(sticker, emojiList, [options])](#TelegramBot+setStickerEmojiList) ⇒ Promise * [.setStickerKeywords(sticker, [options])](#TelegramBot+setStickerKeywords) ⇒ Promise * [.setStickerMaskPosition(sticker, [options])](#TelegramBot+setStickerMaskPosition) ⇒ Promise @@ -547,6 +551,23 @@ Forward messages of any kind. | messageId | Number \| String | Unique message identifier in the chat specified in fromChatId | | [options] | Object | Additional Telegram query options | + + +### telegramBot.forwardMessages(chatId, fromChatId, messageIds, [options]) ⇒ Promise +Use this method to forward multiple messages of any kind. +If some of the specified messages can't be found or forwarded, they are skipped. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - An array of MessageId of the sent messages on success +**See**: https://core.telegram.org/bots/api#forwardmessages + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) or username of the target channel (in the format `@channelusername`) | +| fromChatId | Number \| String | Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`) | +| messageIds | [ 'Array' ].<(Number\|String)> | Identifiers of 1-100 messages in the chat from_chat_id to forward. The identifiers must be specified in a strictly increasing order. | +| [options] | Object | Additional Telegram query options | + ### telegramBot.copyMessage(chatId, fromChatId, messageId, [options]) ⇒ Promise @@ -691,7 +712,7 @@ Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without s ### telegramBot.sendVoice(chatId, voice, [options], [fileOptions]) ⇒ Promise Send voice -**Your audio must be in an .OGG file encoded with OPUS** (other formats may be sent as Audio or Document) +**Your audio must be in an .OGG file encoded with OPUS**, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document) **Kind**: instance method of [TelegramBot](#TelegramBot) **Returns**: Promise - On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned @@ -912,7 +933,7 @@ Use this method to change the chosen reactions on a message. **Kind**: instance method of [TelegramBot](#TelegramBot) **Returns**: [ 'Promise' ].<Boolean> - True on success -**See**: https://core.telegram.org/bots/api#setMessageReaction +**See**: https://core.telegram.org/bots/api#setmessagereaction | Param | Type | Description | | --- | --- | --- | @@ -1344,7 +1365,7 @@ Use this method to get up to date information about the chat username of a user, group or channel, etc.). **Kind**: instance method of [TelegramBot](#TelegramBot) -**Returns**: Promise - [Chat](https://core.telegram.org/bots/api#chat) object on success +**Returns**: Promise - [ChatFullInfo](https://core.telegram.org/bots/api#chatfullinfo) object on success **See**: https://core.telegram.org/bots/api#getchat | Param | Type | Description | @@ -1657,6 +1678,36 @@ that are being deprecated. | callbackQueryId | String | Unique identifier for the query to be answered | | [options] | Object | Additional Telegram query options | + + +### telegramBot.getUserChatBoosts(chatId, user_id, [options]) ⇒ Promise +Use this method to get the list of boosts added to a chat by a use. +Requires administrator rights in the chat + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - On success, returns a [UserChatBoosts](https://core.telegram.org/bots/api#userchatboosts) object +**See**: https://core.telegram.org/bots/api#getuserchatboosts + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the group/channel | +| user_id | Number | Unique identifier of the target user | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.getBusinessConnection(businessConnectionId, [options]) ⇒ Promise +Use this method to get information about the connection of the bot with a business account + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - On success, returns [BusinessConnection](https://core.telegram.org/bots/api#businessconnection) object +**See**: https://core.telegram.org/bots/api#getbusinessconnection + +| Param | Type | Description | +| --- | --- | --- | +| businessConnectionId | Number \| String | Unique identifier for the group/channel | +| [options] | Object | Additional Telegram query options | + ### telegramBot.setMyCommands(commands, [options]) ⇒ Promise @@ -2013,9 +2064,11 @@ Use this method to add a new sticker to a set created by the bot. 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 **Kind**: instance method of [TelegramBot](#TelegramBot) **Returns**: Promise - True on success @@ -2064,6 +2117,26 @@ Use this method to delete a sticker from a set created by the bot. | sticker | String | File identifier of the sticker | | [options] | Object | Additional Telegram query options | + + +### telegramBot.replaceStickerInSet(user_id, name, sticker, [options]) ⇒ Promise +Use this method to replace an existing sticker in a sticker set with a new one + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - True on success +**See**: https://core.telegram.org/bots/api#replacestickerinset +**Todo** + +- [ ] Add tests for this method! + + +| Param | Type | Description | +| --- | --- | --- | +| user_id | Number | User identifier of the sticker set owner | +| name | String | Sticker set name | +| sticker | String | File identifier of the sticker | +| [options] | Object | Additional Telegram query options | + ### telegramBot.setStickerEmojiList(sticker, emojiList, [options]) ⇒ Promise @@ -2366,7 +2439,7 @@ Use this method to delete multiple messages simultaneously. If some of the speci **Kind**: instance method of [TelegramBot](#TelegramBot) **Returns**: [ 'Promise' ].<Boolean> - True on success -**See**: https://core.telegram.org/bots/api#deleteMessages +**See**: https://core.telegram.org/bots/api#deletemessages | Param | Type | Description | | --- | --- | --- | diff --git a/src/telegram.js b/src/telegram.js index 4ea3f6c..e8f8685 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1193,7 +1193,7 @@ class TelegramBot extends EventEmitter { /** * Send voice * - * **Your audio must be in an .OGG file encoded with OPUS** (other formats may be sent as Audio or Document) + * **Your audio must be in an .OGG file encoded with OPUS**, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document) * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) * @param {String|stream.Stream|Buffer} voice A file path, Stream or Buffer. * Can also be a `file_id` previously uploaded. @@ -1916,7 +1916,7 @@ class TelegramBot extends EventEmitter { * username of a user, group or channel, etc.). * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) or channel * @param {Object} [options] Additional Telegram query options - * @return {Promise} [Chat](https://core.telegram.org/bots/api#chat) object on success + * @return {Promise} [ChatFullInfo](https://core.telegram.org/bots/api#chatfullinfo) object on success * @see https://core.telegram.org/bots/api#getchat */ getChat(chatId, form = {}) {