From 9acdf1aeb58d5b20a8e94c5835b324726bbaf836 Mon Sep 17 00:00:00 2001 From: Niklas Weimann Date: Sat, 21 Dec 2024 10:42:08 +0100 Subject: [PATCH 1/3] Add support for api v8.0 Signed-off-by: Niklas Weimann --- .../Inline/SavePreparedInlineMessage.cs | 43 +++++++++++++++++ .../Requests/Users/SetUserEmojiStatus.cs | 28 +++++++++++ .../BotCommandScopeChatMember.cs | 2 +- .../InlineMode/PreparedInlineMessage.cs | 17 +++++++ .../Payments/Requests/CreateInvoiceLink.cs | 16 +++++++ .../Requests/EditUserStarSubscription.cs | 29 +++++++++++ .../Payments/Requests/GetStarTransactions.cs | 7 ++- .../Interface/Payments/SuccessfulPayment.cs | 17 ++++++- .../Payments/TransactionPartnerUser.cs | 11 +++++ src/RxTelegram.Bot/Interface/Stickers/Gift.cs | 32 +++++++++++++ .../Interface/Stickers/Gifts.cs | 11 +++++ .../Interface/Stickers/Requests/SendGift.cs | 40 ++++++++++++++++ src/RxTelegram.Bot/TelegramBot.cs | 48 +++++++++++++++++++ .../Validation/ValidationResultFactory.cs | 19 ++++++++ 14 files changed, 317 insertions(+), 3 deletions(-) create mode 100644 src/RxTelegram.Bot/Interface/BaseTypes/Requests/Inline/SavePreparedInlineMessage.cs create mode 100644 src/RxTelegram.Bot/Interface/BaseTypes/Requests/Users/SetUserEmojiStatus.cs create mode 100644 src/RxTelegram.Bot/Interface/InlineMode/PreparedInlineMessage.cs create mode 100644 src/RxTelegram.Bot/Interface/Payments/Requests/EditUserStarSubscription.cs create mode 100644 src/RxTelegram.Bot/Interface/Stickers/Gift.cs create mode 100644 src/RxTelegram.Bot/Interface/Stickers/Gifts.cs create mode 100644 src/RxTelegram.Bot/Interface/Stickers/Requests/SendGift.cs diff --git a/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Inline/SavePreparedInlineMessage.cs b/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Inline/SavePreparedInlineMessage.cs new file mode 100644 index 0000000..6bb64f1 --- /dev/null +++ b/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Inline/SavePreparedInlineMessage.cs @@ -0,0 +1,43 @@ +using RxTelegram.Bot.Interface.InlineMode.InlineQueryResults; +using RxTelegram.Bot.Interface.Validation; +using RxTelegram.Bot.Validation; + +namespace RxTelegram.Bot.Interface.BaseTypes.Requests.Inline; + +/// +/// Stores a message that can be sent by a user of a Mini App. Returns a PreparedInlineMessage object. +/// +public class SavePreparedInlineMessage : BaseValidation +{ + /// + /// Unique identifier of the target user that can use the prepared message + /// + public long UserId { get; set; } + + /// + /// A JSON-serialized object describing the message to be sent + /// + public BaseInlineQueryResult Result { get; set; } + + /// + /// Pass True if the message can be sent to private chats with users + /// + public bool AllowUserChats { get; set; } + + /// + /// Pass True if the message can be sent to private chats with bots + /// + public bool AllowBotChats { get; set; } + + /// + /// Pass True if the message can be sent to group and supergroup chats + /// + public bool AllowGroupChats { get; set; } + + /// + /// Pass True if the message can be sent to channel chats + /// + public bool AllowChannelChats { get; set; } + + protected override IValidationResult Validate() => this.CreateValidation(); +} diff --git a/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Users/SetUserEmojiStatus.cs b/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Users/SetUserEmojiStatus.cs new file mode 100644 index 0000000..0a5169d --- /dev/null +++ b/src/RxTelegram.Bot/Interface/BaseTypes/Requests/Users/SetUserEmojiStatus.cs @@ -0,0 +1,28 @@ +using RxTelegram.Bot.Interface.Validation; +using RxTelegram.Bot.Validation; + +namespace RxTelegram.Bot.Interface.BaseTypes.Requests.Users; + +/// +/// Changes the emoji status for a given user that previously allowed the bot to manage their +/// emoji status via the Mini App method . Returns True on success. +/// +public class SetUserEmojiStatus : BaseValidation +{ + /// + /// Unique identifier of the target user + /// + public long UserId { get; set; } + + /// + /// Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status. + /// + public string EmojiStatusCustomEmojiId { get; set; } + + /// + /// Expiration date of the emoji status, if any + /// + public int EmojiStatusExpirationDate { get; set; } + + protected override IValidationResult Validate() => this.CreateValidation(); +} diff --git a/src/RxTelegram.Bot/Interface/BotCommandScope/BotCommandScopeChatMember.cs b/src/RxTelegram.Bot/Interface/BotCommandScope/BotCommandScopeChatMember.cs index ac8694b..e8e274a 100644 --- a/src/RxTelegram.Bot/Interface/BotCommandScope/BotCommandScopeChatMember.cs +++ b/src/RxTelegram.Bot/Interface/BotCommandScope/BotCommandScopeChatMember.cs @@ -22,5 +22,5 @@ public class BotCommandScopeChatMember : BotCommandScopeBase /// /// Unique identifier of the target user /// - public int UserId { get; set; } + public long UserId { get; set; } } diff --git a/src/RxTelegram.Bot/Interface/InlineMode/PreparedInlineMessage.cs b/src/RxTelegram.Bot/Interface/InlineMode/PreparedInlineMessage.cs new file mode 100644 index 0000000..548432f --- /dev/null +++ b/src/RxTelegram.Bot/Interface/InlineMode/PreparedInlineMessage.cs @@ -0,0 +1,17 @@ +namespace RxTelegram.Bot.Interface.InlineMode; + +/// +/// Describes an inline message to be sent by a user of a Mini App. +/// +public class PreparedInlineMessage +{ + /// + /// Unique identifier of the prepared message + /// + public string Id { get; set; } + + /// + /// Expiration date of the prepared message, in Unix time. Expired prepared messages can no longer be used + /// + public int ExpirationDate { get; set; } +} diff --git a/src/RxTelegram.Bot/Interface/Payments/Requests/CreateInvoiceLink.cs b/src/RxTelegram.Bot/Interface/Payments/Requests/CreateInvoiceLink.cs index 65b5df6..86566cb 100644 --- a/src/RxTelegram.Bot/Interface/Payments/Requests/CreateInvoiceLink.cs +++ b/src/RxTelegram.Bot/Interface/Payments/Requests/CreateInvoiceLink.cs @@ -9,6 +9,12 @@ namespace RxTelegram.Bot.Interface.Payments.Requests; /// public class CreateInvoiceLink : BaseValidation { + /// + /// Unique identifier of the business connection on behalf of which the link will be created. + /// For payments in Telegram Stars only. + /// + public string BusinessConnectionId { get; set; } + /// /// Product name, 1-32 characters /// @@ -40,6 +46,16 @@ public class CreateInvoiceLink : BaseValidation /// public List Prices { get; set; } + /// + /// The number of seconds the subscription will be active for before the next payment. + /// The currency must be set to “XTR” (Telegram Stars) if the parameter is used. + /// Currently, it must always be 2592000 (30 days) if specified. + /// Any number of subscriptions can be active for a given bot at the same time, + /// including multiple concurrent subscriptions from the same user. + /// Subscription price must not exceed 2500 Telegram Stars. + /// + public int SubscriptionPeriod { get; set; } + /// /// The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). /// diff --git a/src/RxTelegram.Bot/Interface/Payments/Requests/EditUserStarSubscription.cs b/src/RxTelegram.Bot/Interface/Payments/Requests/EditUserStarSubscription.cs new file mode 100644 index 0000000..57460e2 --- /dev/null +++ b/src/RxTelegram.Bot/Interface/Payments/Requests/EditUserStarSubscription.cs @@ -0,0 +1,29 @@ +using RxTelegram.Bot.Interface.Validation; +using RxTelegram.Bot.Validation; + +namespace RxTelegram.Bot.Interface.Payments.Requests; + +/// +/// Allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars. Returns True on success. +/// +public class EditUserStarSubscription : BaseValidation +{ + /// + /// Identifier of the user whose subscription will be edited + /// + public long UserId { get; set; } + + /// + /// Telegram payment identifier for the subscription + /// + public string TelegramPaymentChargeId { get; set; } + + /// + /// Pass True to cancel extension of the user subscription; + /// the subscription must be active up to 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. + /// + public bool IsCanceled { get; set; } + + protected override IValidationResult Validate() => this.CreateValidation(); +} diff --git a/src/RxTelegram.Bot/Interface/Payments/Requests/GetStarTransactions.cs b/src/RxTelegram.Bot/Interface/Payments/Requests/GetStarTransactions.cs index f8a4e3b..bbb225a 100644 --- a/src/RxTelegram.Bot/Interface/Payments/Requests/GetStarTransactions.cs +++ b/src/RxTelegram.Bot/Interface/Payments/Requests/GetStarTransactions.cs @@ -1,10 +1,13 @@ +using RxTelegram.Bot.Interface.Validation; +using RxTelegram.Bot.Validation; + namespace RxTelegram.Bot.Interface.Payments.Requests; /// /// Returns the bot's Telegram Star transactions in chronological order. /// On success, returns a StarTransactions object. /// -public class GetStarTransactions +public class GetStarTransactions : BaseValidation { /// /// Number of transactions to skip in the response @@ -15,4 +18,6 @@ public class GetStarTransactions /// The maximum number of transactions to be retrieved. Values between 1-100 are accepted. Defaults to 100. /// public int? Limit { get; set; } + + protected override IValidationResult Validate() => this.CreateValidation(); } diff --git a/src/RxTelegram.Bot/Interface/Payments/SuccessfulPayment.cs b/src/RxTelegram.Bot/Interface/Payments/SuccessfulPayment.cs index bedbc5c..e79cabc 100644 --- a/src/RxTelegram.Bot/Interface/Payments/SuccessfulPayment.cs +++ b/src/RxTelegram.Bot/Interface/Payments/SuccessfulPayment.cs @@ -24,6 +24,21 @@ public class SuccessfulPayment /// public string InvoicePayload { get; set; } + /// + /// Optional. Expiration date of the subscription, in Unix time; for recurring payments only + /// + public int SubscriptionExpirationDate { get; set; } + + /// + /// Optional. True, if the payment is a recurring payment for a subscription + /// + public bool IsRecurring { get; set; } + + /// + /// Optional. True, if the payment is the first payment for a subscription + /// + public bool IsFirstRecurring { get; set; } + /// /// Optional. Identifier of the shipping option chosen by the user /// @@ -43,4 +58,4 @@ public class SuccessfulPayment /// Provider payment identifier /// public string ProviderPaymentChargeId { get; set; } -} \ No newline at end of file +} diff --git a/src/RxTelegram.Bot/Interface/Payments/TransactionPartnerUser.cs b/src/RxTelegram.Bot/Interface/Payments/TransactionPartnerUser.cs index dfef942..3953d53 100644 --- a/src/RxTelegram.Bot/Interface/Payments/TransactionPartnerUser.cs +++ b/src/RxTelegram.Bot/Interface/Payments/TransactionPartnerUser.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using RxTelegram.Bot.Interface.BaseTypes; using RxTelegram.Bot.Interface.BaseTypes.Enums; +using RxTelegram.Bot.Interface.Stickers; namespace RxTelegram.Bot.Interface.Payments; @@ -24,6 +25,11 @@ public class TransactionPartnerUser : TransactionPartner /// public string InvoicePayload { get; set; } + /// + /// Optional. The duration of the paid subscription + /// + public int? SubscriptionPeriod { get; set; } + /// /// Optional. Information about the paid media bought by the user /// @@ -33,4 +39,9 @@ public class TransactionPartnerUser : TransactionPartner /// Optional. Bot-specified paid media payload /// public string PaidMediaPayload { get; set; } + + /// + /// Optional. The gift sent to the user by the bot + /// + public Gift Gift { get; set; } } diff --git a/src/RxTelegram.Bot/Interface/Stickers/Gift.cs b/src/RxTelegram.Bot/Interface/Stickers/Gift.cs new file mode 100644 index 0000000..8b21216 --- /dev/null +++ b/src/RxTelegram.Bot/Interface/Stickers/Gift.cs @@ -0,0 +1,32 @@ +namespace RxTelegram.Bot.Interface.Stickers; + +/// +/// This object represents a gift that can be sent by the bot. +/// +public class Gift +{ + /// + /// Unique identifier of the gift + /// + public string Id { get; set; } + + /// + /// The sticker that represents the gift + /// + public Sticker Sticker { get; set; } + + /// + /// The number of Telegram Stars that must be paid to send the sticker + /// + public int StarCount { get; set; } + + /// + /// Optional. The total number of the gifts of this type that can be sent; for limited gifts only + /// + public int TotalCount { get; set; } + + /// + /// Optional. The number of remaining gifts of this type that can be sent; for limited gifts only + /// + public int RemainingCount { get; set; } +} diff --git a/src/RxTelegram.Bot/Interface/Stickers/Gifts.cs b/src/RxTelegram.Bot/Interface/Stickers/Gifts.cs new file mode 100644 index 0000000..a6371d1 --- /dev/null +++ b/src/RxTelegram.Bot/Interface/Stickers/Gifts.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace RxTelegram.Bot.Interface.Stickers; + +/// +/// This object represent a list of gifts. +/// +public class GiftsObject +{ + public List Gifts { get; set; } +} diff --git a/src/RxTelegram.Bot/Interface/Stickers/Requests/SendGift.cs b/src/RxTelegram.Bot/Interface/Stickers/Requests/SendGift.cs new file mode 100644 index 0000000..3012585 --- /dev/null +++ b/src/RxTelegram.Bot/Interface/Stickers/Requests/SendGift.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using RxTelegram.Bot.Interface.BaseTypes; +using RxTelegram.Bot.Interface.Validation; +using RxTelegram.Bot.Validation; + +namespace RxTelegram.Bot.Interface.Stickers.Requests; + +/// +/// Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. Returns True on success. +/// +public class SendGift : BaseValidation +{ + /// + /// Unique identifier of the target user that will receive the gift + /// + public long UserId { get; set; } + + /// + /// Identifier of the gift + /// + public string GiftId { get; set; } + + /// + /// Text that will be shown along with the gift; 0-255 characters + /// + public string Text { get; set; } + + /// + /// Mode for parsing entities in the text. + /// + public string TextParseMode { get; set; } + + /// + /// A JSON-serialized list of special entities that appear in the gift text. It can be specified instead of text_parse_mode. + /// Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored. + /// + public List TextEntities { get; set; } + + protected override IValidationResult Validate() => this.CreateValidation(); +} diff --git a/src/RxTelegram.Bot/TelegramBot.cs b/src/RxTelegram.Bot/TelegramBot.cs index b626fca..98e258b 100644 --- a/src/RxTelegram.Bot/TelegramBot.cs +++ b/src/RxTelegram.Bot/TelegramBot.cs @@ -1384,4 +1384,52 @@ public Task EditChatSubscriptionInviteLink( EditChatSubscriptionInviteLink editChatSubscriptionInviteLink, CancellationToken cancellationToken = default) => Post("editChatSubscriptionInviteLink", editChatSubscriptionInviteLink, cancellationToken); + + /// + /// Allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars. + /// + /// Details for the subscription update + /// Propagates notification that operations should be canceled. + /// Returns True on success. + public Task EditUserStarSubscription( + EditUserStarSubscription editUserStarSubscription, + CancellationToken cancellationToken = default) => + Post("editUserStarSubscription", editUserStarSubscription, cancellationToken); + + /// + /// Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method requestEmojiStatusAccess + /// + /// Status to set for the user + /// Propagates notification that operations should be canceled. + /// Returns True on success. + public Task SetUserEmojiStatus(SetUserEmojiStatus setUserEmojiStatus, CancellationToken cancellationToken = default) => + Post("setUserEmojiStatus", setUserEmojiStatus, cancellationToken); + + /// + /// Stores a message that can be sent by a user of a Mini App + /// + /// Prepared inline Message to save + /// Propagates notification that operations should be canceled. + /// Returns a object. + public Task SavePreparedInlineMessage( + SavePreparedInlineMessage savePreparedInlineMessage, + CancellationToken cancellationToken = default) => + Post("savePreparedInlineMessage", savePreparedInlineMessage, cancellationToken); + + /// + /// Returns the list of gifts that can be sent by the bot to users. Requires no parameters. + /// + /// Propagates notification that operations should be canceled. + /// Returns a object. + public Task GetAvailableGifts(CancellationToken cancellationToken = default) => + Get("getAvailableGifts", cancellationToken); + + /// + /// Sends a gift to the given user. The gift can't be converted to Telegram Stars by the user. + /// + /// The gift to send + /// Propagates notification that operations should be canceled. + /// Returns True on success. + public Task SendGift(SendGift sendGift, CancellationToken cancellationToken = default) => + Post("sendGift", sendGift, cancellationToken); } diff --git a/src/RxTelegram.Bot/Validation/ValidationResultFactory.cs b/src/RxTelegram.Bot/Validation/ValidationResultFactory.cs index 4c5c9fa..6991d70 100644 --- a/src/RxTelegram.Bot/Validation/ValidationResultFactory.cs +++ b/src/RxTelegram.Bot/Validation/ValidationResultFactory.cs @@ -2,6 +2,7 @@ using System.Linq; using RxTelegram.Bot.Interface.BaseTypes.Enums; using RxTelegram.Bot.Interface.BaseTypes.InputMedia; +using RxTelegram.Bot.Interface.BaseTypes.Requests; using RxTelegram.Bot.Interface.BaseTypes.Requests.Attachments; using RxTelegram.Bot.Interface.BaseTypes.Requests.Bot; using RxTelegram.Bot.Interface.BaseTypes.Requests.Callbacks; @@ -665,4 +666,22 @@ public static ValidationResult CreateValidatio public static ValidationResult CreateValidation(this EditChatSubscriptionInviteLink value) => new ValidationResult(value).ValidateRequired(x => x.ChatId) .ValidateRequired(x => x.InviteLink); + + public static ValidationResult CreateValidation(this GetStarTransactions value) => new(value); + + public static ValidationResult CreateValidation(this EditUserStarSubscription value) => + new ValidationResult(value).ValidateRequired(x => x.UserId) + .ValidateRequired(x => x.TelegramPaymentChargeId) + .ValidateRequired(x => x.IsCanceled); + + public static ValidationResult CreateValidation(this SetUserEmojiStatus value) => + new ValidationResult(value).ValidateRequired(x => x.UserId); + + public static ValidationResult CreateValidation(this SavePreparedInlineMessage value) => + new ValidationResult(value).ValidateRequired(x => x.UserId) + .ValidateRequired(x => x.Result); + + public static ValidationResult CreateValidation(this SendGift value) => new ValidationResult(value) + .ValidateRequired(x => x.UserId) + .ValidateRequired(x => x.GiftId); } From 34f106234dcc81c6191e8f8d815442affdc5f4c0 Mon Sep 17 00:00:00 2001 From: Niklas Weimann Date: Sat, 21 Dec 2024 13:17:45 +0100 Subject: [PATCH 2/3] Update workflow Signed-off-by: Niklas Weimann --- .github/workflows/main.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d8cf08e..fa283cf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: Setup dotnet '8.0.x' + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + - name: Display dotnet version + run: dotnet --version - name: Build run: dotnet build --configuration Release test: From e75f1392b7d0ed7965bce600d825d08a6e1a76c4 Mon Sep 17 00:00:00 2001 From: Niklas Weimann Date: Sat, 21 Dec 2024 13:21:24 +0100 Subject: [PATCH 3/3] Update workflow Signed-off-by: Niklas Weimann --- .github/workflows/main.yml | 12 ++++++++++++ .github/workflows/publish.yml | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fa283cf..441a1ba 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,6 +30,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: Setup dotnet '8.0.x' + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + - name: Display dotnet version + run: dotnet --version - name: Test run: dotnet test --configuration Release sonarqube: @@ -45,6 +51,12 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Setup dotnet '8.0.x' + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + - name: Display dotnet version + run: dotnet --version - name: Cache SonarCloud packages uses: actions/cache@v4 with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c1abcd2..590d720 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,6 +10,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: Setup dotnet '8.0.x' + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + - name: Display dotnet version + run: dotnet --version - name: Build run: dotnet build --configuration Release test: @@ -18,6 +24,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: Setup dotnet '8.0.x' + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + - name: Display dotnet version + run: dotnet --version - name: Test run: dotnet test --configuration Release sonarqube: @@ -33,6 +45,12 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Setup dotnet '8.0.x' + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + - name: Display dotnet version + run: dotnet --version - name: Cache SonarCloud packages uses: actions/cache@v4 with: