From 75437a630a152ec16e53184102be6f720dc097fc Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Mon, 18 Nov 2024 14:31:09 +0530 Subject: [PATCH 1/8] API/createInvoiceLink --- lib/src/televerse/api/raw_api.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/televerse/api/raw_api.dart b/lib/src/televerse/api/raw_api.dart index d5e3872..482b4b6 100644 --- a/lib/src/televerse/api/raw_api.dart +++ b/lib/src/televerse/api/raw_api.dart @@ -3241,6 +3241,8 @@ class RawAPI { bool? sendPhoneNumberToProvider, bool? sendEmailToProvider, bool? isFlexible, + int? subscriptionPeriod, + String? businessConnectionId, }) async { final params = { "title": title, @@ -3263,6 +3265,8 @@ class RawAPI { "send_phone_number_to_provider": sendPhoneNumberToProvider, "send_email_to_provider": sendEmailToProvider, "is_flexible": isFlexible, + "subscription_period": subscriptionPeriod, + "business_connection_id": businessConnectionId, }; final response = await _makeApiCall( From e00ae90766f79784ee2b0b643072b706954022db Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Mon, 18 Nov 2024 14:38:19 +0530 Subject: [PATCH 2/8] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Star=20Subscription=20?= =?UTF-8?q?changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telegram/models/successful_payment.dart | 12 +++++++++ .../models/transaction_partner_user.dart | 6 +++++ lib/src/televerse/api/raw_api.dart | 26 +++++++++++++++++++ lib/src/types/methods.dart | 3 +++ 4 files changed, 47 insertions(+) diff --git a/lib/src/telegram/models/successful_payment.dart b/lib/src/telegram/models/successful_payment.dart index 6a0c4c8..c884b86 100644 --- a/lib/src/telegram/models/successful_payment.dart +++ b/lib/src/telegram/models/successful_payment.dart @@ -23,6 +23,12 @@ class SuccessfulPayment { /// Provider payment identifier final String providerPaymentChargeId; + /// Optional. True, if the payment is a recurring payment for a subscription + final bool? isRecurring; + + /// Optional. True, if the payment is the first payment for a subscription + final bool? isFirstRecurring; + /// Constructs a [SuccessfulPayment] object const SuccessfulPayment({ required this.currency, @@ -32,6 +38,8 @@ class SuccessfulPayment { this.orderInfo, required this.telegramPaymentChargeId, required this.providerPaymentChargeId, + this.isRecurring, + this.isFirstRecurring, }); /// Converts a [SuccessfulPayment] object to a JSON object @@ -44,6 +52,8 @@ class SuccessfulPayment { 'order_info': orderInfo?.toJson(), 'telegram_payment_charge_id': telegramPaymentChargeId, 'provider_payment_charge_id': providerPaymentChargeId, + 'is_recurring': isRecurring, + 'is_first_recurring': isFirstRecurring, }..removeWhere(_nullFilter); } @@ -59,6 +69,8 @@ class SuccessfulPayment { : null, telegramPaymentChargeId: json['telegram_payment_charge_id']!, providerPaymentChargeId: json['provider_payment_charge_id']!, + isRecurring: json['is_recurring'], + isFirstRecurring: json['is_first_recurring'], ); } } diff --git a/lib/src/telegram/models/transaction_partner_user.dart b/lib/src/telegram/models/transaction_partner_user.dart index 5f528c5..8cc8713 100644 --- a/lib/src/telegram/models/transaction_partner_user.dart +++ b/lib/src/telegram/models/transaction_partner_user.dart @@ -17,12 +17,16 @@ class TransactionPartnerUser extends TransactionPartner { /// Optional. Bot-specified paid media payload final String? paidMediaPayload; + /// Optional. The duration of the paid subscription. + final int? subscriptionPeriod; + /// Constructs a [TransactionPartnerUser] object. const TransactionPartnerUser({ required this.user, this.invoicePayload, this.paidMedia, this.paidMediaPayload, + this.subscriptionPeriod, }); /// Creates a [TransactionPartnerUser] object from JSON. @@ -38,6 +42,7 @@ class TransactionPartnerUser extends TransactionPartner { ) : null, paidMediaPayload: json['paid_media_payload'], + subscriptionPeriod: json['subscription_period'], ); } @@ -50,6 +55,7 @@ class TransactionPartnerUser extends TransactionPartner { 'invoice_payload': invoicePayload, 'paid_media': paidMedia?.map((e) => e.toJson()).toList(), 'paid_media_payload': paidMediaPayload, + 'subscription_period': subscriptionPeriod, }..removeWhere(_nullFilter); } } diff --git a/lib/src/televerse/api/raw_api.dart b/lib/src/televerse/api/raw_api.dart index 482b4b6..8cbe744 100644 --- a/lib/src/televerse/api/raw_api.dart +++ b/lib/src/televerse/api/raw_api.dart @@ -4120,4 +4120,30 @@ class RawAPI { return ChatInviteLink.fromJson(response); } + + /// Allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars. + /// Returns `true` on success. + /// + /// Parameters: + /// - [userId] (int, required): Identifier of the user whose subscription will be edited. + /// - [telegramPaymentChargeId] (String, required): Telegram payment identifier for the subscription. + /// - [isCanceled] (bool, required): Pass `true` to cancel the extension of the user subscription; the subscription must + /// be active until the end of the current subscription period. Pass `false` to allow the user to re-enable a subscription + /// that was previously canceled by the bot. + Future editUserStarSubscription({ + required int userId, + required String telegramPaymentChargeId, + required bool isCanceled, + }) async { + final params = { + "user_id": userId, + "telegram_payment_charge_id": telegramPaymentChargeId, + "is_canceled": isCanceled, + }; + + return await _makeApiBoolCall( + APIMethod.editUserStarSubscription, + payload: Payload(params), + ); + } } diff --git a/lib/src/types/methods.dart b/lib/src/types/methods.dart index d2aad94..6d00f31 100644 --- a/lib/src/types/methods.dart +++ b/lib/src/types/methods.dart @@ -385,6 +385,9 @@ enum APIMethod { /// Use this method to edit a subscription invite link created by the bot. editChatSubscriptionInviteLink._("editChatSubscriptionInviteLink"), + + /// Edit user's star subscription + editUserStarSubscription._("editUserStarSubscription"), ; /// The name of the method. From 27bf9ff0844b70c85d302d2065982405dacb727d Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Mon, 18 Nov 2024 14:43:27 +0530 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=8C=90=20Emoji=20Status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/televerse/api/raw_api.dart | 26 ++++++++++++++++++++++++++ lib/src/types/methods.dart | 3 +++ 2 files changed, 29 insertions(+) diff --git a/lib/src/televerse/api/raw_api.dart b/lib/src/televerse/api/raw_api.dart index 8cbe744..a5057cf 100644 --- a/lib/src/televerse/api/raw_api.dart +++ b/lib/src/televerse/api/raw_api.dart @@ -4146,4 +4146,30 @@ class RawAPI { payload: Payload(params), ); } + + /// Changes the emoji status for a given user who previously allowed the bot to manage their emoji status via the Mini App method requestEmojiStatusAccess. + /// Returns `true` on success. + /// + /// Parameters: + /// - [userId] (int, required): Unique identifier of the target user. + /// - [emojiStatusCustomEmojiId] (String, optional): Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status. + /// - [emojiStatusExpirationDate] (int, optional): Expiration date of the emoji status, in Unix time, if any. + Future setUserEmojiStatus({ + required int userId, + String? emojiStatusCustomEmojiId, + int? emojiStatusExpirationDate, + }) async { + final params = { + "user_id": userId, + "emoji_status_custom_emoji_id": emojiStatusCustomEmojiId, + "emoji_status_expiration_date": emojiStatusExpirationDate, + }; + + final response = await _makeApiBoolCall( + APIMethod.setUserEmojiStatus, + payload: Payload(params), + ); + + return response == true; + } } diff --git a/lib/src/types/methods.dart b/lib/src/types/methods.dart index 6d00f31..bd9cd2b 100644 --- a/lib/src/types/methods.dart +++ b/lib/src/types/methods.dart @@ -388,6 +388,9 @@ enum APIMethod { /// Edit user's star subscription editUserStarSubscription._("editUserStarSubscription"), + + /// Changes the emoji status for a given user + setUserEmojiStatus._("setUserEmojiStatus"), ; /// The name of the method. From 70be6476a6394c7681d54567c38b1cf16d6a404b Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Mon, 18 Nov 2024 14:49:28 +0530 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=A4=9D=20Media=20Sharing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/telegram/models/models.dart | 3 ++ .../models/prepared_inline_message.dart | 33 +++++++++++++++++ lib/src/televerse/api/raw_api.dart | 35 +++++++++++++++++++ lib/src/types/methods.dart | 3 ++ 4 files changed, 74 insertions(+) create mode 100644 lib/src/telegram/models/prepared_inline_message.dart diff --git a/lib/src/telegram/models/models.dart b/lib/src/telegram/models/models.dart index 315f6f2..bcfac21 100644 --- a/lib/src/telegram/models/models.dart +++ b/lib/src/telegram/models/models.dart @@ -278,3 +278,6 @@ part 'paid_media_purchased.dart'; // Bot API 7.11 part 'copy_text_button.dart'; part 'transaction_partner_telegram_api.dart'; + +// Bot API 8.0 +part 'prepared_inline_message.dart'; diff --git a/lib/src/telegram/models/prepared_inline_message.dart b/lib/src/telegram/models/prepared_inline_message.dart new file mode 100644 index 0000000..a72d8c6 --- /dev/null +++ b/lib/src/telegram/models/prepared_inline_message.dart @@ -0,0 +1,33 @@ +part of 'models.dart'; + +/// Describes an inline message to be sent by a user of a Mini App. +class PreparedInlineMessage { + /// Unique identifier of the prepared message. + final String id; + + /// Expiration date of the prepared message, in Unix time. + /// Expired prepared messages can no longer be used. + final int expirationDate; + + /// Creates a [PreparedInlineMessage] object. + const PreparedInlineMessage({ + required this.id, + required this.expirationDate, + }); + + /// Creates a [PreparedInlineMessage] object from a JSON map. + factory PreparedInlineMessage.fromJson(Map json) { + return PreparedInlineMessage( + id: json['id'], + expirationDate: json['expiration_date'], + ); + } + + /// Converts this object to a JSON map. + Map toJson() { + return { + 'id': id, + 'expiration_date': expirationDate, + }; + } +} diff --git a/lib/src/televerse/api/raw_api.dart b/lib/src/televerse/api/raw_api.dart index a5057cf..c144f3b 100644 --- a/lib/src/televerse/api/raw_api.dart +++ b/lib/src/televerse/api/raw_api.dart @@ -4172,4 +4172,39 @@ class RawAPI { return response == true; } + + /// Stores a message that can be sent by a user of a Mini App. + /// Returns a [PreparedInlineMessage] object. + /// + /// Parameters: + /// - [userId] (int, required): Unique identifier of the target user that can use the prepared message. + /// - [result] (InlineQueryResult, required): A JSON-serialized object describing the message to be sent. + /// - [allowUserChats] (bool, optional): Pass `true` if the message can be sent to private chats with users. + /// - [allowBotChats] (bool, optional): Pass `true` if the message can be sent to private chats with bots. + /// - [allowGroupChats] (bool, optional): Pass `true` if the message can be sent to group and supergroup chats. + /// - [allowChannelChats] (bool, optional): Pass `true` if the message can be sent to channel chats. + Future savePreparedInlineMessage({ + required int userId, + required InlineQueryResult result, + bool? allowUserChats, + bool? allowBotChats, + bool? allowGroupChats, + bool? allowChannelChats, + }) async { + final params = { + "user_id": userId, + "result": result.toJson(), + "allow_user_chats": allowUserChats, + "allow_bot_chats": allowBotChats, + "allow_group_chats": allowGroupChats, + "allow_channel_chats": allowChannelChats, + }; + + final response = await _makeApiJsonCall( + APIMethod.savePreparedInlineMessage, + payload: Payload(params), + ); + + return PreparedInlineMessage.fromJson(response); + } } diff --git a/lib/src/types/methods.dart b/lib/src/types/methods.dart index bd9cd2b..b4f53f0 100644 --- a/lib/src/types/methods.dart +++ b/lib/src/types/methods.dart @@ -391,6 +391,9 @@ enum APIMethod { /// Changes the emoji status for a given user setUserEmojiStatus._("setUserEmojiStatus"), + + /// Stores a message that can be sent by a user of a Mini App + savePreparedInlineMessage._("savePreparedInlineMessage"), ; /// The name of the method. From f06c8a4b745274eb2b9d1e084defc37db6d14ef0 Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Mon, 18 Nov 2024 14:57:04 +0530 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=8E=81=20Gifts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/telegram/models/gift.dart | 50 +++++++++++++++++++ lib/src/telegram/models/gifts.dart | 28 +++++++++++ lib/src/telegram/models/models.dart | 2 + .../models/transaction_partner_user.dart | 6 +++ lib/src/televerse/api/raw_api.dart | 44 ++++++++++++++++ lib/src/types/methods.dart | 6 +++ 6 files changed, 136 insertions(+) create mode 100644 lib/src/telegram/models/gift.dart create mode 100644 lib/src/telegram/models/gifts.dart diff --git a/lib/src/telegram/models/gift.dart b/lib/src/telegram/models/gift.dart new file mode 100644 index 0000000..3a1085b --- /dev/null +++ b/lib/src/telegram/models/gift.dart @@ -0,0 +1,50 @@ +part of 'models.dart'; + +/// Represents a gift that can be sent by the bot. +class Gift { + /// Unique identifier of the gift. + final String id; + + /// The sticker that represents the gift. + final Sticker sticker; + + /// The number of Telegram Stars that must be paid to send the sticker. + final int starCount; + + /// Optional. The total number of gifts of this type that can be sent; for limited gifts only. + final int? totalCount; + + /// Optional. The number of remaining gifts of this type that can be sent; for limited gifts only. + final int? remainingCount; + + /// Creates a [Gift] object. + const Gift({ + required this.id, + required this.sticker, + required this.starCount, + this.totalCount, + this.remainingCount, + }); + + /// Creates a [Gift] object from a JSON map. + factory Gift.fromJson(Map json) { + return Gift( + id: json['id'], + sticker: Sticker.fromJson(json['sticker']), + starCount: json['star_count'], + totalCount: json['total_count'], + remainingCount: json['remaining_count'], + ); + } + + /// Converts this object to a JSON map. + Map toJson() { + return { + 'id': id, + 'sticker': sticker.toJson(), + 'star_count': starCount, + 'total_count': totalCount, + 'remaining_count': remainingCount, + }; + } +} diff --git a/lib/src/telegram/models/gifts.dart b/lib/src/telegram/models/gifts.dart new file mode 100644 index 0000000..ca17b8d --- /dev/null +++ b/lib/src/telegram/models/gifts.dart @@ -0,0 +1,28 @@ +part of 'models.dart'; + +/// Represents a list of gifts. +class Gifts { + /// The list of gifts. + final List gifts; + + /// Creates a [Gifts] object. + const Gifts({ + required this.gifts, + }); + + /// Creates a [Gifts] object from a JSON map. + factory Gifts.fromJson(Map json) { + return Gifts( + gifts: List.from( + (json['gifts'] as List).map((gift) => Gift.fromJson(gift)), + ), + ); + } + + /// Converts this object to a JSON map. + Map toJson() { + return { + 'gifts': gifts.map((gift) => gift.toJson()).toList(), + }; + } +} diff --git a/lib/src/telegram/models/models.dart b/lib/src/telegram/models/models.dart index bcfac21..866bf06 100644 --- a/lib/src/telegram/models/models.dart +++ b/lib/src/telegram/models/models.dart @@ -281,3 +281,5 @@ part 'transaction_partner_telegram_api.dart'; // Bot API 8.0 part 'prepared_inline_message.dart'; +part 'gift.dart'; +part 'gifts.dart'; diff --git a/lib/src/telegram/models/transaction_partner_user.dart b/lib/src/telegram/models/transaction_partner_user.dart index 8cc8713..d57a409 100644 --- a/lib/src/telegram/models/transaction_partner_user.dart +++ b/lib/src/telegram/models/transaction_partner_user.dart @@ -20,6 +20,9 @@ class TransactionPartnerUser extends TransactionPartner { /// Optional. The duration of the paid subscription. final int? subscriptionPeriod; + /// Optional. The gift sent to the user by the bot. + final Gift? gift; + /// Constructs a [TransactionPartnerUser] object. const TransactionPartnerUser({ required this.user, @@ -27,6 +30,7 @@ class TransactionPartnerUser extends TransactionPartner { this.paidMedia, this.paidMediaPayload, this.subscriptionPeriod, + this.gift, }); /// Creates a [TransactionPartnerUser] object from JSON. @@ -43,6 +47,7 @@ class TransactionPartnerUser extends TransactionPartner { : null, paidMediaPayload: json['paid_media_payload'], subscriptionPeriod: json['subscription_period'], + gift: json['gift'] != null ? Gift.fromJson(json['gift']) : null, ); } @@ -56,6 +61,7 @@ class TransactionPartnerUser extends TransactionPartner { 'paid_media': paidMedia?.map((e) => e.toJson()).toList(), 'paid_media_payload': paidMediaPayload, 'subscription_period': subscriptionPeriod, + 'gift': gift?.toJson(), }..removeWhere(_nullFilter); } } diff --git a/lib/src/televerse/api/raw_api.dart b/lib/src/televerse/api/raw_api.dart index c144f3b..23959ad 100644 --- a/lib/src/televerse/api/raw_api.dart +++ b/lib/src/televerse/api/raw_api.dart @@ -4207,4 +4207,48 @@ class RawAPI { return PreparedInlineMessage.fromJson(response); } + + /// Returns the list of gifts that can be sent by the bot to users. + /// Requires no parameters. Returns a [Gifts] object. + Future getAvailableGifts() async { + final response = await _makeApiJsonCall( + APIMethod.getAvailableGifts, + ); + + return Gifts.fromJson(response); + } + + /// Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. + /// Returns `true` on success. + /// + /// Parameters: + /// - [userId] (int, required): Unique identifier of the target user that will receive the gift. + /// - [giftId] (String, required): Identifier of the gift. + /// - [text] (String, optional): Text that will be shown along with the gift; 0-255 characters. + /// - [textParseMode] (String, optional): Mode for parsing entities in the text. Entities other than + /// “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored. + /// - [textEntities] (List, optional): A JSON-serialized list of special entities + /// that appear in the gift text. Can be specified instead of `textParseMode`. + Future sendGift({ + required int userId, + required String giftId, + String? text, + String? textParseMode, + List? textEntities, + }) async { + final params = { + "user_id": userId, + "gift_id": giftId, + "text": text, + "text_parse_mode": textParseMode, + "text_entities": textEntities?.map((e) => e.toJson()).toList(), + }; + + final response = await _makeApiJsonCall( + APIMethod.sendGift, + payload: Payload(params), + ); + + return response == true; + } } diff --git a/lib/src/types/methods.dart b/lib/src/types/methods.dart index b4f53f0..4f2d5ac 100644 --- a/lib/src/types/methods.dart +++ b/lib/src/types/methods.dart @@ -394,6 +394,12 @@ enum APIMethod { /// Stores a message that can be sent by a user of a Mini App savePreparedInlineMessage._("savePreparedInlineMessage"), + + /// Returns the list of gifts that can be sent by the bot to users + getAvailableGifts._("getAvailableGifts"), + + /// Sends a gift to the given user. + sendGift._("sendGift"), ; /// The name of the method. From f2edfb9d9e51e379c081cd21b6753b125cc3efed Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Mon, 18 Nov 2024 15:05:41 +0530 Subject: [PATCH 6/8] =?UTF-8?q?=E2=84=B9=EF=B8=8F=20Version=20and=20change?= =?UTF-8?q?log=20info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++++++ pubspec.yaml | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ede9e2b..942b771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 1.28.0 + +- 🤖 Bot API 8.0 +- Updated `RawAPI.createInvoiceLink` to the docs. +- Updated `SuccessfulPayment`, `TransactionPartnerUser` to reflect the new Star Subscription features. +- 🆕 Added new API Methods - `editUserStarSubscription`, `setUserEmojiStatus`, `savePreparedInlineMessage`, `getAvailableGifts`, `sendGift`. +- 🆕 Added new classes - `PreparedInlineMessage`, `Gift`, `Gifts`. + # 1.27.3 - ⚠️ Removed `baseURL` from `Bot` primary constructor. diff --git a/pubspec.yaml b/pubspec.yaml index 2b039f2..cd7a45b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: televerse -description: Televerse lets you create your own efficient Telegram bots with ease in Dart. Supports latest Telegram Bot API - 7.11! -version: 1.27.3 +description: Televerse lets you create your own efficient Telegram bots with ease in Dart. Supports latest Telegram Bot API - 8.0! +version: 1.28.0 homepage: https://televerse.xooniverse.com repository: https://github.com/xooniverse/televerse topics: From f6779b2e2210f54d2bc0780a0f2537f526d52df1 Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Mon, 18 Nov 2024 15:10:11 +0530 Subject: [PATCH 7/8] =?UTF-8?q?=E2=9C=8D=EF=B8=8F=20Briefing=20about=20Bot?= =?UTF-8?q?=20API=208.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0ab808f..5d84c68 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Pub Version](https://img.shields.io/pub/v/televerse?color=blue&logo=blue)](https://pub.dev/packages/televerse) ![GitHub](https://img.shields.io/github/license/xooniverse/televerse?color=green) -![](https://shields.io/badge/Latest-Bot%20API%207.11-blue) +![](https://shields.io/badge/Latest-Bot%20API%208.0-blue) @@ -12,7 +12,7 @@ --- -🤖 `Bot API version: Bot API 7.11 (October 31, 2024)` 🎃 +🤖 `Bot API version: Bot API 8.0 (November 17, 2024)` 🎃 Televerse is a powerful, easy-to-use, and highly customizable Telegram bot framework built with Dart programming language. It provides a complete and @@ -22,13 +22,13 @@ public interface, making it easy for developers to write strictly typed code. ## 🔥 What's latest? -### 🤖 Bot API 7.11 🎃 +### 🤖 Bot API 8.0 🎃 -(🗓️ October 31, 2024) +(🗓️ November 17, 2024) -In a nutshell, this update brigngs support for broadcasting upto 1000 Messages per second. New Copy Text Inline Button, and more. +In a nutshell, this update majorly is about Telegram Mini Apps, though we have a few new methods for Bot API including `editUserStarSubscription`, `getAvailableGifts` etc. Being said that, now Bots can send Gifts to the user. 🎁 -Checkout [changelog](https://core.telegram.org/bots/api-changelog#october-31-2024) for more +Checkout [changelog](https://core.telegram.org/bots/api-changelog#november-17-2024) for more details! 🚀 ### 🎉 Support for Custom Contexts! From f485ee73c38492652032722419bf27dd471e58da Mon Sep 17 00:00:00 2001 From: Sreelal TS Date: Mon, 18 Nov 2024 15:22:30 +0530 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=8E=81=20Supports=20sending=20Gifts?= =?UTF-8?q?=20via=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/televerse/api/raw_api.dart | 8 +++----- lib/src/televerse/context/methods.dart | 27 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/src/televerse/api/raw_api.dart b/lib/src/televerse/api/raw_api.dart index 23959ad..e0d172a 100644 --- a/lib/src/televerse/api/raw_api.dart +++ b/lib/src/televerse/api/raw_api.dart @@ -4233,22 +4233,20 @@ class RawAPI { required int userId, required String giftId, String? text, - String? textParseMode, + ParseMode? textParseMode, List? textEntities, }) async { final params = { "user_id": userId, "gift_id": giftId, "text": text, - "text_parse_mode": textParseMode, + "text_parse_mode": textParseMode?.value, "text_entities": textEntities?.map((e) => e.toJson()).toList(), }; - final response = await _makeApiJsonCall( + return await _makeApiBoolCall( APIMethod.sendGift, payload: Payload(params), ); - - return response == true; } } diff --git a/lib/src/televerse/context/methods.dart b/lib/src/televerse/context/methods.dart index 1649b86..eb33948 100644 --- a/lib/src/televerse/context/methods.dart +++ b/lib/src/televerse/context/methods.dart @@ -1918,4 +1918,31 @@ extension ContextAwareMethods on Context { replyMarkup: replyMarkup, ); } + + /// Context Aware method for sending a gift to the author of the message. + /// + /// This method depends on the `from` parameter of the incoming update. + Future sendGift( + String giftId, { + String? text, + ParseMode? textParseMode, + List? textEntities, + }) async { + api._addContext(this); + _verifyInfo([_from?.id], APIMethod.sendGift); + + return api.sendGift( + userId: _from!.id, + giftId: giftId, + text: text, + textParseMode: textParseMode, + textEntities: textEntities, + ); + } + + /// Get the available gifts for the user + Future getAvailableGifts() async { + api._addContext(this); + return api.getAvailableGifts(); + } }