From 01c3ea77c9cc6090a2c39a58c69f77266b9a1bac Mon Sep 17 00:00:00 2001 From: danielperez9430 Date: Wed, 16 Apr 2025 10:07:23 +0200 Subject: [PATCH] feat: Support Telegram Bot API 7.10 --- CHANGELOG.md | 8 ++++++ README.md | 2 +- doc/api.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ src/telegram.js | 4 +++ 4 files changed, 81 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d067fc..99e415d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.68.0][0.68.0] - UNRELEASE + +1. Support Telegram Bot API 7.10 (@danielperez9430) + * Update: `purchased_paid_media` + +2. Support Telegram Bot API 7.6 (@danielperez9430) + * sendPaidMedia + ## [0.67.0][0.67.0] - 2024-05-30 1. Support Telegram Bot API 7.4 (@danielperez9430) diff --git a/README.md b/README.md index 4b95a7e..f9e16a6 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.4-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) +[![Bot API](https://img.shields.io/badge/Bot%20API-v.7.10-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) [![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 52a066f..593478e 100644 --- a/doc/api.md +++ b/doc/api.md @@ -50,6 +50,7 @@ TelegramBot * [.sendAnimation(chatId, animation, [options], [fileOptions])](#TelegramBot+sendAnimation) ⇒ Promise * [.sendVoice(chatId, voice, [options], [fileOptions])](#TelegramBot+sendVoice) ⇒ Promise * [.sendVideoNote(chatId, videoNote, [options], [fileOptions])](#TelegramBot+sendVideoNote) ⇒ Promise + * [.sendPaidMedia(chatId, starCount, media, [options])](#TelegramBot+sendPaidMedia) ⇒ Promise * [.sendMediaGroup(chatId, media, [options])](#TelegramBot+sendMediaGroup) ⇒ Promise * [.sendLocation(chatId, latitude, longitude, [options])](#TelegramBot+sendLocation) ⇒ Promise * [.editMessageLiveLocation(latitude, longitude, [options])](#TelegramBot+editMessageLiveLocation) ⇒ Promise @@ -73,6 +74,8 @@ TelegramBot * [.exportChatInviteLink(chatId, [options])](#TelegramBot+exportChatInviteLink) ⇒ Promise * [.createChatInviteLink(chatId, [options])](#TelegramBot+createChatInviteLink) ⇒ Object * [.editChatInviteLink(chatId, inviteLink, [options])](#TelegramBot+editChatInviteLink) ⇒ Promise + * [.createChatSubscriptionInviteLink(chatId, subscriptionPeriod, subscriptionPrice, [options])](#TelegramBot+createChatSubscriptionInviteLink) ⇒ Promise + * [.editChatSubscriptionInviteLink(chatId, inviteLink, [options])](#TelegramBot+editChatSubscriptionInviteLink) ⇒ Promise * [.revokeChatInviteLink(chatId, inviteLink, [options])](#TelegramBot+revokeChatInviteLink) ⇒ Promise * [.approveChatJoinRequest(chatId, userId, [options])](#TelegramBot+approveChatJoinRequest) ⇒ Promise * [.declineChatJoinRequest(chatId, userId, [options])](#TelegramBot+declineChatJoinRequest) ⇒ Promise @@ -146,6 +149,7 @@ TelegramBot * [.createInvoiceLink(title, description, payload, providerToken, currency, prices, [options])](#TelegramBot+createInvoiceLink) ⇒ Promise * [.answerShippingQuery(shippingQueryId, ok, [options])](#TelegramBot+answerShippingQuery) ⇒ Promise * [.answerPreCheckoutQuery(preCheckoutQueryId, ok, [options])](#TelegramBot+answerPreCheckoutQuery) ⇒ Promise + * [.getStarTransactions([options])](#TelegramBot+getStarTransactions) ⇒ Promise * [.refundStarPayment(userId, telegramPaymentChargeId, [options])](#TelegramBot+refundStarPayment) ⇒ Promise * [.sendGame(chatId, gameShortName, [options])](#TelegramBot+sendGame) ⇒ Promise * [.setGameScore(userId, score, [options])](#TelegramBot+setGameScore) ⇒ Promise @@ -752,6 +756,22 @@ Telegram clients support **rounded square MPEG4 videos** of up to 1 minute long. | [options] | Object | Additional Telegram query options | | [fileOptions] | Object | Optional file related meta-data | + + +### telegramBot.sendPaidMedia(chatId, starCount, media, [options]) ⇒ Promise +Use this method to send paid media. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned +**See**: https://core.telegram.org/bots/api#sendpaidmedia + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) | +| starCount | Number | The number of Telegram Stars that must be paid to buy access to the media; 1-10000 | +| media | String \| stream.Stream \| Buffer | A file path or Stream. | +| [options] | Object | Additional Telegram query options | + ### telegramBot.sendMediaGroup(chatId, media, [options]) ⇒ Promise @@ -1172,6 +1192,41 @@ The bot **must be an administrator in the chat** for this to work and must have | inviteLink | String | Text with the invite link to edit | | [options] | Object | Additional Telegram query options | + + +### telegramBot.createChatSubscriptionInviteLink(chatId, subscriptionPeriod, subscriptionPrice, [options]) ⇒ Promise +Use this method to create a subscription invite link for a channel chat. + +The bot must have the can_invite_users administrator rights + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - The new invite link as a [ChatInviteLink](https://core.telegram.org/bots/api#chatinvitelink) object +**See**: https://core.telegram.org/bots/api#createchatsubscriptioninvitelink + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) | +| subscriptionPeriod | Number | The number of seconds the subscription will be active for before the next payment. Currently, it must always be 2592000 (30 days) | +| subscriptionPrice | Number | The amount of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat (1-2500) | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.editChatSubscriptionInviteLink(chatId, inviteLink, [options]) ⇒ Promise +Use this method to edit a subscription invite link created by the bot. + +The bot must have the can_invite_users administrator rights + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - The new invite link as a [ChatInviteLink](https://core.telegram.org/bots/api#chatinvitelink) object +**See**: https://core.telegram.org/bots/api#editchatsubscriptioninvitelink + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) | +| inviteLink | String | The invite link to edit | +| [options] | Object | Additional Telegram query options | + ### telegramBot.revokeChatInviteLink(chatId, inviteLink, [options]) ⇒ Promise @@ -2365,6 +2420,19 @@ an [Update](https://core.telegram.org/bots/api#update) with the field *pre_check | ok | Boolean | Specify if every order details are ok | | [options] | Object | Additional Telegram query options | + + +### telegramBot.getStarTransactions([options]) ⇒ Promise +Use this method for get the bot's Telegram Star transactions in chronological order + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Promise - On success, returns a [StarTransactions](https://core.telegram.org/bots/api#startransactions) object +**See**: https://core.telegram.org/bots/api#getstartransactions + +| Param | Type | Description | +| --- | --- | --- | +| [options] | Object | Additional Telegram query options | + ### telegramBot.refundStarPayment(userId, telegramPaymentChargeId, [options]) ⇒ Promise diff --git a/src/telegram.js b/src/telegram.js index 338e602..86efa41 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -761,6 +761,7 @@ class TelegramBot extends EventEmitter { const callbackQuery = update.callback_query; const shippingQuery = update.shipping_query; const preCheckoutQuery = update.pre_checkout_query; + const purchasedPaidMedia = update.purchased_paid_media; const poll = update.poll; const pollAnswer = update.poll_answer; const myChatMember = update.my_chat_member; @@ -869,6 +870,9 @@ class TelegramBot extends EventEmitter { } else if (preCheckoutQuery) { debug('Process Update pre_checkout_query %j', preCheckoutQuery); this.emit('pre_checkout_query', preCheckoutQuery); + } else if (purchasedPaidMedia) { + debug('Process Update purchased_paid_media %j', purchasedPaidMedia); + this.emit('purchased_paid_media', purchasedPaidMedia); } else if (poll) { debug('Process Update poll %j', poll); this.emit('poll', poll);