diff --git a/README.md b/README.md index 9b7d7b2..b706ef3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=RxTelegram_RxTelegram.Bot&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=RxTelegram_RxTelegram.Bot) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=RxTelegram_RxTelegram.Bot&metric=coverage)](https://sonarcloud.io/summary/new_code?id=RxTelegram_RxTelegram.Bot) -RxTelegram.Bot supports Telegram Bot API 7.8 (as at July 31, 2024). +RxTelegram.Bot supports Telegram Bot API 7.9 (as at August 14, 2024). This is a reactive designed .NET Library for the Telegram Bot API. It works with the official [Reactive Extentions](https://github.com/dotnet/reactive). diff --git a/src/RxTelegram.Bot/ITelegramBot.cs b/src/RxTelegram.Bot/ITelegramBot.cs index 8d82b88..d8821ac 100644 --- a/src/RxTelegram.Bot/ITelegramBot.cs +++ b/src/RxTelegram.Bot/ITelegramBot.cs @@ -19,6 +19,7 @@ using RxTelegram.Bot.Interface.Games.Requests; using RxTelegram.Bot.Interface.InlineMode; using RxTelegram.Bot.Interface.Passport.Requests; +using RxTelegram.Bot.Interface.Payments; using RxTelegram.Bot.Interface.Payments.Requests; using RxTelegram.Bot.Interface.Reaction.Requests; using RxTelegram.Bot.Interface.Setup; @@ -1207,4 +1208,52 @@ Task GetBusinessConnection( /// Propagates notification that operations should be canceled. /// Returns an array of on success. Task CopyMessages(CopyMessages copyMessages, CancellationToken cancellationToken = default); + + /// + /// Refunds a successful payment in Telegram Stars. + /// + /// Information about the payment + /// Propagates notification that operations should be canceled. + /// Returns True on success. + Task RefundStarPayment(RefundStarPayment refundStarPayment, CancellationToken cancellationToken = default); + + /// + /// Returns the bot's Telegram Star transactions in chronological order. + /// + /// Information about the transactions + /// Propagates notification that operations should be canceled. + /// On success, returns a object. + Task GetStarTransactions( + GetStarTransactions getStarTransactions, + CancellationToken cancellationToken = default); + + /// + /// Use this method to send paid media to channel chats. + /// + /// Details for the media to send + /// Propagates notification that operations should be canceled. + /// On success, the sent is returned. + Task SendPaidMedia(SendPaidMedia sendPaidMedia, CancellationToken cancellationToken = default); + + /// + /// Use this method to create a subscription invite link for a channel chat. + /// The bot must have the can_invite_users administrator rights. + /// The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method . + /// + /// Details for the invite link + /// Propagates notification that operations should be canceled. + /// Returns the new invite link as a object. + Task CreateChatSubscriptionInviteLink( + CreateChatSubscriptionInviteLink createChatSubscriptionInviteLink, + CancellationToken cancellationToken = default); + + /// + /// Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights + /// + /// Details for the invite link + /// Propagates notification that operations should be canceled. + /// Returns the new invite link as a object. + Task EditChatSubscriptionInviteLink( + EditChatSubscriptionInviteLink editChatSubscriptionInviteLink, + CancellationToken cancellationToken = default); } diff --git a/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Chats/CreateChatSubscriptionInviteLink.cs b/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Chats/CreateChatSubscriptionInviteLink.cs new file mode 100644 index 0000000..0d0cd85 --- /dev/null +++ b/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Chats/CreateChatSubscriptionInviteLink.cs @@ -0,0 +1,30 @@ +using RxTelegram.Bot.Interface.BaseTypes.Requests.Base; +using RxTelegram.Bot.Validation; + +namespace RxTelegram.Bot.Interface.BaseTypes.Requests.Chats; + +/// +/// Use this method to create a subscription invite link for a channel chat. +/// The bot must have the can_invite_users administrator rights. +/// The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method . +/// Returns the new invite link as a ChatInviteLink object. +/// +public class CreateChatSubscriptionInviteLink : BaseRequest +{ + /// + /// Invite link name; 0-32 characters + /// + public string Name { get; set; } + + /// + /// The number of seconds the subscription will be active for before the next payment. Currently, it must always be 2592000 (30 days). + /// + public int SubscriptionPeriod { get; set; } + + /// + /// 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 + /// + public int SubscriptionPrice { get; set; } + + protected override IValidationResult Validate() => this.CreateValidation(); +} diff --git a/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Chats/EditChatSubscriptionInviteLink.cs b/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Chats/EditChatSubscriptionInviteLink.cs new file mode 100644 index 0000000..04ec009 --- /dev/null +++ b/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Chats/EditChatSubscriptionInviteLink.cs @@ -0,0 +1,22 @@ +using RxTelegram.Bot.Interface.BaseTypes.Requests.Base; +using RxTelegram.Bot.Validation; + +namespace RxTelegram.Bot.Interface.BaseTypes.Requests.Chats; + +/// +/// Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. +/// +public class EditChatSubscriptionInviteLink : BaseRequest +{ + /// + /// The invite link to edit + /// + public string InviteLink { get; set; } + + /// + /// Invite link name; 0-32 characters + /// + public string Name { get; set; } + + protected override IValidationResult Validate() => this.CreateValidation(); +} diff --git a/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Messages/SendPaidMedia.cs b/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Messages/SendPaidMedia.cs index 7a2057f..1ed0f83 100644 --- a/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Messages/SendPaidMedia.cs +++ b/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Messages/SendPaidMedia.cs @@ -11,6 +11,11 @@ namespace RxTelegram.Bot.Interface.BaseTypes.Requests.Messages; /// public class SendPaidMedia : BaseTextRequest { + /// + /// Unique identifier of the business connection on behalf of which the message will be sent + /// + public string BusinessConnectionId { get; set; } + /// /// The number of Telegram Stars that must be paid to buy access to the media /// diff --git a/src/RxTelegram.Bot/Interface/Payments/TransactionPartnerUser.cs b/src/RxTelegram.Bot/Interface/Payments/TransactionPartnerUser.cs index 75b59f4..88342e0 100644 --- a/src/RxTelegram.Bot/Interface/Payments/TransactionPartnerUser.cs +++ b/src/RxTelegram.Bot/Interface/Payments/TransactionPartnerUser.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using RxTelegram.Bot.Interface.BaseTypes; using RxTelegram.Bot.Interface.BaseTypes.Enums; @@ -22,4 +23,6 @@ public class TransactionPartnerUser : TransactionPartner /// Optional. Bot-specified invoice payload /// public string InvoicePayload { get; set; } + + public List PaidMedia { get; set; } } diff --git a/src/RxTelegram.Bot/Interface/Reaction/Enums/ReactionType.cs b/src/RxTelegram.Bot/Interface/Reaction/Enums/ReactionType.cs index 8a9bd46..1120891 100644 --- a/src/RxTelegram.Bot/Interface/Reaction/Enums/ReactionType.cs +++ b/src/RxTelegram.Bot/Interface/Reaction/Enums/ReactionType.cs @@ -8,5 +8,8 @@ public enum ReactionType Emoji, [ImplementationType(typeof(ReactionTypeCustomEmoji))] - CustomEmoji + CustomEmoji, + + [ImplementationType(typeof(ReactionTypePaid))] + Paid } diff --git a/src/RxTelegram.Bot/Interface/Reaction/ReactionTypePaid.cs b/src/RxTelegram.Bot/Interface/Reaction/ReactionTypePaid.cs new file mode 100644 index 0000000..4100f30 --- /dev/null +++ b/src/RxTelegram.Bot/Interface/Reaction/ReactionTypePaid.cs @@ -0,0 +1,6 @@ +namespace RxTelegram.Bot.Interface.Reaction; + +public class ReactionTypePaid : ReactionType +{ + public override Enums.ReactionType Type { get; set; } = Enums.ReactionType.Paid; +} diff --git a/src/RxTelegram.Bot/RxTelegram.Bot.csproj b/src/RxTelegram.Bot/RxTelegram.Bot.csproj index 0899502..efbb67c 100644 --- a/src/RxTelegram.Bot/RxTelegram.Bot.csproj +++ b/src/RxTelegram.Bot/RxTelegram.Bot.csproj @@ -10,7 +10,7 @@ https://github.com/RxTelegram/RxTelegram.Bot git Telegram;Bot;Api;Rx;Reactive;Observable;RxTelegram;RxTelegram.Bot - 7.8.0 + 7.9.0 icon.png true bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml diff --git a/src/RxTelegram.Bot/TelegramBot.cs b/src/RxTelegram.Bot/TelegramBot.cs index d4c3422..b626fca 100644 --- a/src/RxTelegram.Bot/TelegramBot.cs +++ b/src/RxTelegram.Bot/TelegramBot.cs @@ -1347,7 +1347,9 @@ public Task RefundStarPayment(RefundStarPayment refundStarPayment, Cancell /// Information about the transactions /// Propagates notification that operations should be canceled. /// On success, returns a object. - public Task GetStarTransactions(GetStarTransactions getStarTransactions, CancellationToken cancellationToken = default) => + public Task GetStarTransactions( + GetStarTransactions getStarTransactions, + CancellationToken cancellationToken = default) => Post("getStarTransactions", getStarTransactions, cancellationToken); /// @@ -1358,4 +1360,28 @@ public Task GetStarTransactions(GetStarTransactions getStarTra /// On success, the sent is returned. public Task SendPaidMedia(SendPaidMedia sendPaidMedia, CancellationToken cancellationToken = default) => Post("sendPaidMedia", sendPaidMedia, cancellationToken); + + /// + /// Use this method to create a subscription invite link for a channel chat. + /// The bot must have the can_invite_users administrator rights. + /// The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method . + /// + /// Details for the invite link + /// Propagates notification that operations should be canceled. + /// Returns the new invite link as a object. + public Task CreateChatSubscriptionInviteLink( + CreateChatSubscriptionInviteLink createChatSubscriptionInviteLink, + CancellationToken cancellationToken = default) => + Post("createChatSubscriptionInviteLink", createChatSubscriptionInviteLink, cancellationToken); + + /// + /// Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights + /// + /// Details for the invite link + /// Propagates notification that operations should be canceled. + /// Returns the new invite link as a object. + public Task EditChatSubscriptionInviteLink( + EditChatSubscriptionInviteLink editChatSubscriptionInviteLink, + CancellationToken cancellationToken = default) => + Post("editChatSubscriptionInviteLink", editChatSubscriptionInviteLink, cancellationToken); } diff --git a/src/RxTelegram.Bot/Validation/ValidationResultFactory.cs b/src/RxTelegram.Bot/Validation/ValidationResultFactory.cs index 1bc6d6f..4c5c9fa 100644 --- a/src/RxTelegram.Bot/Validation/ValidationResultFactory.cs +++ b/src/RxTelegram.Bot/Validation/ValidationResultFactory.cs @@ -655,4 +655,14 @@ public static ValidationResult CreateValidation(this RefundSt public static ValidationResult CreateValidation(this SendPaidMedia value) => new ValidationResult(value).ValidateRequired(x => x.StarCount) .ValidateRequired(x => x.Media); + + public static ValidationResult CreateValidation(this CreateChatSubscriptionInviteLink value) => + new ValidationResult(value).ValidateRequired(x => x.ChatId) + .ValidateRequired(x => x.Name) + .ValidateRequired(x => x.SubscriptionPeriod) + .ValidateRequired(x => x.SubscriptionPrice); + + public static ValidationResult CreateValidation(this EditChatSubscriptionInviteLink value) => + new ValidationResult(value).ValidateRequired(x => x.ChatId) + .ValidateRequired(x => x.InviteLink); }