From 20722bf70a3c29c45c010b07756a2441b7ffc123 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:30:17 +0200 Subject: [PATCH 01/34] Added the class BusinessBotRights and replaced the field can_reply with the field rights of the type BusinessBotRights in the class BusinessConnection --- .../model/business/BusinessBotRights.kt | 20 +++++++++++++++++++ .../model/business/BusinessConnection.java | 15 +++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/business/BusinessBotRights.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/business/BusinessBotRights.kt b/library/src/main/java/com/pengrad/telegrambot/model/business/BusinessBotRights.kt new file mode 100644 index 00000000..91b4a563 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/business/BusinessBotRights.kt @@ -0,0 +1,20 @@ +package com.pengrad.telegrambot.model.business + +data class BusinessBotRights( + @get:JvmName("canReply") val canReply: Boolean, + @get:JvmName("canReadMessages") val canReadMessages: Boolean, + @get:JvmName("canDeleteSentMessages") val canDeleteSentMessages: Boolean, + @get:JvmName("canDeleteAllMessages") val canDeleteAllMessages: Boolean, + @get:JvmName("canEditName") val canEditName: Boolean, + @get:JvmName("canEditBio") val canEditBio: Boolean, + @get:JvmName("canEditProfilePhoto") val canEditProfilePhoto: Boolean, + @get:JvmName("canEditUsername") val canEditUsername: Boolean, + @get:JvmName("canChangeGiftSettings") val canChangeGiftSettings: Boolean, + @get:JvmName("canViewGiftsAndStars") val canViewGiftsAndStars: Boolean, + @get:JvmName("canConvertGiftsToStars") val canConvertGiftsToStars: Boolean, + @get:JvmName("canTransferAndUpgradeGifts") val canTransferAndUpgradeGifts: Boolean, + @get:JvmName("canTransferStars") val canTransferStars: Boolean, + @get:JvmName("canManageStories") val canManageStories: Boolean, +) { + +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/business/BusinessConnection.java b/library/src/main/java/com/pengrad/telegrambot/model/business/BusinessConnection.java index 4c7a4009..d3fe0cbf 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/business/BusinessConnection.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/business/BusinessConnection.java @@ -10,6 +10,7 @@ public class BusinessConnection { private User user; private Long user_chat_id; private Integer date; + private BusinessBotRights rights; private Boolean can_reply; private Boolean is_enabled; @@ -29,10 +30,18 @@ public Integer date() { return date; } + /** + * @deprecated Use the 'rights' field instead. + */ + @Deprecated public Boolean canReply() { return can_reply; } + public BusinessBotRights rights() { + return rights; + } + public Boolean isEnabled() { return is_enabled; } @@ -42,12 +51,12 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; BusinessConnection that = (BusinessConnection) o; - return Objects.equals(id, that.id) && Objects.equals(user, that.user) && Objects.equals(user_chat_id, that.user_chat_id) && Objects.equals(date, that.date) && Objects.equals(can_reply, that.can_reply) && Objects.equals(is_enabled, that.is_enabled); + return Objects.equals(id, that.id) && Objects.equals(user, that.user) && Objects.equals(user_chat_id, that.user_chat_id) && Objects.equals(date, that.date) && Objects.equals(rights, that.rights) && Objects.equals(is_enabled, that.is_enabled); } @Override public int hashCode() { - return Objects.hash(id, user, user_chat_id, date, can_reply, is_enabled); + return Objects.hash(id, user, user_chat_id, date, rights, is_enabled); } @Override @@ -57,7 +66,7 @@ public String toString() { ", user=" + user + ", user_chat_id=" + user_chat_id + ", date=" + date + - ", can_reply=" + can_reply + + ", rights=" + rights + ", is_enabled=" + is_enabled + '}'; } From 579dab7d055ffa99cf1ab3dd593e645b35785deb Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:37:50 +0200 Subject: [PATCH 02/34] Added the method readBusinessMessage, allowing bots to mark incoming messages as read on behalf of a business account. --- .../request/business/ReadBusinessMessage.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/ReadBusinessMessage.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/ReadBusinessMessage.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/ReadBusinessMessage.kt new file mode 100644 index 00000000..1894d1e7 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/ReadBusinessMessage.kt @@ -0,0 +1,17 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +class ReadBusinessMessage( + businessConnectionId: String, + chatId: Long, + messageId: Int +) : KBaseRequest(BaseResponse::class) { + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val chatId: Long by requestParameter(chatId, customParameterName = "chat_id") + val messageId: Int by requestParameter(messageId, customParameterName = "message_id") + +} \ No newline at end of file From e9b87ffffcf81e1e9bcf83e81157d0eb99dd6e07 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:38:23 +0200 Subject: [PATCH 03/34] Added the method deleteBusinessMessages, allowing bots to delete messages on behalf of a business account. --- .../request/business/DeleteBusinessMessage.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/DeleteBusinessMessage.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/DeleteBusinessMessage.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/DeleteBusinessMessage.kt new file mode 100644 index 00000000..ded54912 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/DeleteBusinessMessage.kt @@ -0,0 +1,16 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class DeleteBusinessMessage( + businessConnectionId: String, + messageIds: Array +) : KBaseRequest(BaseResponse::class) { + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val messageIds: Array by requestParameter(messageIds, customParameterName = "message_ids") + +} \ No newline at end of file From d2c94b6b3d140e64f8e47422bb9fae09849892c9 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:38:44 +0200 Subject: [PATCH 04/34] Added the method setBusinessAccountName, allowing bots to change the first and last name of a managed business account. --- .../business/SetBusinessAccountName.kt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountName.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountName.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountName.kt new file mode 100644 index 00000000..8d2551bd --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountName.kt @@ -0,0 +1,27 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class SetBusinessAccountName private constructor( + businessConnectionId: String, + firstName: String, + lastName: String? +) : KBaseRequest(BaseResponse::class) { + + constructor(businessConnectionId: String, firstName: String) : this( + businessConnectionId = businessConnectionId, + firstName = firstName, + lastName = null + ) + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val firstName: String by requestParameter(firstName, customParameterName = "first_name") + + var lastName: String? by optionalRequestParameter(lastName, customParameterName = "last_name") + fun lastName(lastName: String) = applySelf { this.lastName = lastName } + +} \ No newline at end of file From 68edc0f6d12cb37c8df80f204e654a0e76421e34 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:39:06 +0200 Subject: [PATCH 05/34] Added the method setBusinessAccountUsername, allowing bots to change the username of a managed business account. --- .../business/SetBusinessAccountUsername.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountUsername.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountUsername.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountUsername.kt new file mode 100644 index 00000000..bc79b0bc --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountUsername.kt @@ -0,0 +1,24 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class SetBusinessAccountUsername private constructor( + businessConnectionId: String, + username: String? +): KBaseRequest(BaseResponse::class) { + + constructor(businessConnectionId: String) : this( + businessConnectionId = businessConnectionId, + username = null + ) + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + + var username: String? by optionalRequestParameter(username, customParameterName = "username") + fun username(username: String) = applySelf { this.username = username } + +} \ No newline at end of file From 4f816a00d81e0e2dd56cc202ea4a7493c6cbfeb1 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:39:31 +0200 Subject: [PATCH 06/34] Added the method setBusinessAccountBio, allowing bots to change the bio of a managed business account. --- .../request/business/SetBusinessAccountBio.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountBio.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountBio.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountBio.kt new file mode 100644 index 00000000..580e8d58 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountBio.kt @@ -0,0 +1,24 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class SetBusinessAccountBio private constructor( + businessConnectionId: String, + bio: String? +): KBaseRequest(BaseResponse::class) { + + constructor(businessConnectionId: String) : this( + businessConnectionId = businessConnectionId, + bio = null + ) + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + + var bio: String? by optionalRequestParameter(bio, customParameterName = "bio") + fun bio(bio: String) = applySelf { this.bio = bio } + +} \ No newline at end of file From 0f301c4514c9a5b43069c19af62d634b52fe2e1c Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:40:57 +0200 Subject: [PATCH 07/34] Added the class InputProfilePhoto, describing a profile photo to be set. --- .../inputprofilephoto/InputProfilePhoto.kt | 3 +++ .../InputProfilePhotoAnimated.kt | 17 +++++++++++++++++ .../InputProfilePhotoStatic.kt | 4 ++++ 3 files changed, 24 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhoto.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoAnimated.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoStatic.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhoto.kt b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhoto.kt new file mode 100644 index 00000000..0a4c7638 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhoto.kt @@ -0,0 +1,3 @@ +package com.pengrad.telegrambot.model.inputprofilephoto + +open class InputProfilePhoto(val type: String) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoAnimated.kt b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoAnimated.kt new file mode 100644 index 00000000..8f4d5091 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoAnimated.kt @@ -0,0 +1,17 @@ +package com.pengrad.telegrambot.model.inputprofilephoto + +@Suppress("unused") +class InputProfilePhotoAnimated private constructor( + val animation: String, + var mainFrameTimestamp: Double? +) : InputProfilePhoto(type = "animated") { + + constructor(animation: String) : this( + animation = animation, + mainFrameTimestamp = null + ) + + fun mainFrameTimestamp(mainFrameTimestamp: Double) = apply { + this.mainFrameTimestamp = mainFrameTimestamp + } +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoStatic.kt b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoStatic.kt new file mode 100644 index 00000000..e716386e --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoStatic.kt @@ -0,0 +1,4 @@ +package com.pengrad.telegrambot.model.inputprofilephoto + +@Suppress("unused") +class InputProfilePhotoStatic(val photo: String) : InputProfilePhoto(type = "static") \ No newline at end of file From 8ca20cf705258720cda546bc4ea5fb03d607ce5a Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:41:23 +0200 Subject: [PATCH 08/34] Added the methods setBusinessAccountProfilePhoto and removeBusinessAccountProfilePhoto, allowing bots to change the profile photo of a managed business account. --- .../RemoveBusinessAccountProfilePhoto.kt | 24 ++++++++++++++++ .../SetBusinessAccountProfilePhoto.kt | 28 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/RemoveBusinessAccountProfilePhoto.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountProfilePhoto.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/RemoveBusinessAccountProfilePhoto.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/RemoveBusinessAccountProfilePhoto.kt new file mode 100644 index 00000000..48d5d87a --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/RemoveBusinessAccountProfilePhoto.kt @@ -0,0 +1,24 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class RemoveBusinessAccountProfilePhoto private constructor( + businessConnectionId: String, + isPublic: Boolean? +) : KBaseRequest(BaseResponse::class) { + + constructor(businessConnectionId: String) : this( + businessConnectionId = businessConnectionId, + isPublic = null + ) + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + + var isPublic: Boolean? by optionalRequestParameter(isPublic, customParameterName = "is_public") + fun isPublic(isPublic: Boolean) = applySelf { this.isPublic = isPublic } + +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountProfilePhoto.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountProfilePhoto.kt new file mode 100644 index 00000000..ce09d449 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountProfilePhoto.kt @@ -0,0 +1,28 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.model.inputprofilephoto.InputProfilePhoto +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class SetBusinessAccountProfilePhoto private constructor( + businessConnectionId: String, + photo: InputProfilePhoto, + isPublic: Boolean? +) : KBaseRequest(BaseResponse::class) { + + constructor(businessConnectionId: String, photo: InputProfilePhoto) : this( + businessConnectionId = businessConnectionId, + photo = photo, + isPublic = null + ) + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val photo: InputProfilePhoto by requestParameter(photo, customParameterName = "photo") + + var isPublic: Boolean? by optionalRequestParameter(isPublic, customParameterName = "is_public") + fun isPublic(isPublic: Boolean) = applySelf { this.isPublic = isPublic } + +} \ No newline at end of file From 69378b071e384f28f970cee853418fae406c4bf1 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:42:08 +0200 Subject: [PATCH 09/34] Added the class AcceptedGiftTypes and the method setBusinessAccountGiftSettings, allowing bots to change the privacy settings pertaining to incoming gifts in a managed business account. --- .../model/gift/AcceptedGiftTypes.kt | 8 ++++++++ .../SetBusinessAccountGiftSettings.kt | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/AcceptedGiftTypes.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountGiftSettings.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/AcceptedGiftTypes.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/AcceptedGiftTypes.kt new file mode 100644 index 00000000..e1072190 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/AcceptedGiftTypes.kt @@ -0,0 +1,8 @@ +package com.pengrad.telegrambot.model.gift + +data class AcceptedGiftTypes( + @get:JvmName("unlimitedGifts") val unlimitedGifts: Boolean, + @get:JvmName("limitedGifts") val limitedGifts: Boolean, + @get:JvmName("uniqueGifts") val uniqueGifts: Boolean, + @get:JvmName("premiumSubscription") val premiumSubscription: Boolean +) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountGiftSettings.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountGiftSettings.kt new file mode 100644 index 00000000..183e93d9 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/SetBusinessAccountGiftSettings.kt @@ -0,0 +1,19 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.model.gift.AcceptedGiftTypes +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class SetBusinessAccountGiftSettings( + businessConnectionId: String, + showGiftButton: Boolean, + acceptedGiftTypes: AcceptedGiftTypes +): KBaseRequest(BaseResponse::class) { + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val showGiftButton: Boolean by requestParameter(showGiftButton, customParameterName = "show_gift_button") + val acceptedGiftTypes: AcceptedGiftTypes by requestParameter(acceptedGiftTypes, customParameterName = "accepted_gift_types") + +} \ No newline at end of file From 777986cd00dac817be8b8a73e270a6d3df5d821b Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:44:55 +0200 Subject: [PATCH 10/34] Added the class StarAmount and the method getBusinessAccountStarBalance, allowing bots to check the current Telegram Star balance of a managed business account. --- .../pengrad/telegrambot/model/stars/StarAmount.kt | 6 ++++++ .../business/GetBusinessAccountStarBalance.kt | 13 +++++++++++++ .../GetBusinessAccountStarBalanceResponse.kt | 5 +++++ 3 files changed, 24 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/stars/StarAmount.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/GetBusinessAccountStarBalance.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/response/GetBusinessAccountStarBalanceResponse.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/stars/StarAmount.kt b/library/src/main/java/com/pengrad/telegrambot/model/stars/StarAmount.kt new file mode 100644 index 00000000..6d0ab645 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/stars/StarAmount.kt @@ -0,0 +1,6 @@ +package com.pengrad.telegrambot.model.stars + +data class StarAmount( + @get:JvmName("amount") val amount: Int, + @get:JvmName("nanostarAmount") val nanostarAmount: Long +) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/GetBusinessAccountStarBalance.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/GetBusinessAccountStarBalance.kt new file mode 100644 index 00000000..d9ad399f --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/GetBusinessAccountStarBalance.kt @@ -0,0 +1,13 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.GetBusinessAccountStarBalanceResponse +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class GetBusinessAccountStarBalance( + businessConnectionId: String +): KBaseRequest(GetBusinessAccountStarBalanceResponse::class) { + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/response/GetBusinessAccountStarBalanceResponse.kt b/library/src/main/java/com/pengrad/telegrambot/response/GetBusinessAccountStarBalanceResponse.kt new file mode 100644 index 00000000..5ca9a358 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/response/GetBusinessAccountStarBalanceResponse.kt @@ -0,0 +1,5 @@ +package com.pengrad.telegrambot.response + +import com.pengrad.telegrambot.model.stars.StarAmount + +data class GetBusinessAccountStarBalanceResponse(val result: StarAmount) : BaseResponse() From f8f0eb6f3e6b6ff5880d968488dd1009493515ae Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:45:34 +0200 Subject: [PATCH 11/34] Added the method transferBusinessAccountStars, allowing bots to transfer Telegram Stars from the balance of a managed business account to their own balance for withdrawal. --- .../business/TransferBusinessAccountStars.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/TransferBusinessAccountStars.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/TransferBusinessAccountStars.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/TransferBusinessAccountStars.kt new file mode 100644 index 00000000..9d0d633c --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/TransferBusinessAccountStars.kt @@ -0,0 +1,16 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class TransferBusinessAccountStars( + businessConnectionId: String, + starCount: Int +): KBaseRequest(BaseResponse::class) { + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val starCount: Int by requestParameter(starCount, customParameterName = "star_count") + +} \ No newline at end of file From cb7a69c02ff33df3c5108ea8c905069f13177315 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:46:24 +0200 Subject: [PATCH 12/34] Added the classes OwnedGiftRegular, OwnedGiftUnique, OwnedGifts and the method getBusinessAccountGifts, allowing bots to fetch the list of gifts owned by a managed business account. --- .../telegrambot/model/gift/owned/OwnedGift.kt | 3 + .../model/gift/owned/OwnedGiftRegular.kt | 20 +++++++ .../model/gift/owned/OwnedGiftUnique.kt | 15 +++++ .../model/gift/owned/OwnedGifts.kt | 25 ++++++++ .../business/GetBusinessAccountGifts.kt | 59 +++++++++++++++++++ .../GetBusinessAccountGiftsResponse.kt | 5 ++ 6 files changed, 127 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGift.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftUnique.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGifts.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/GetBusinessAccountGifts.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/response/GetBusinessAccountGiftsResponse.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGift.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGift.kt new file mode 100644 index 00000000..cb11eada --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGift.kt @@ -0,0 +1,3 @@ +package com.pengrad.telegrambot.model.gift.owned + +open class OwnedGift(val type: String) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt new file mode 100644 index 00000000..58107c17 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt @@ -0,0 +1,20 @@ +package com.pengrad.telegrambot.model.gift.owned + +import com.pengrad.telegrambot.model.User +import com.pengrad.telegrambot.model.gift.Gift + +@Suppress("unused") +class OwnedGiftRegular( + @get:JvmName("gift") val gift: Gift, + @get:JvmName("ownedGiftId") var ownedGiftId: String?, + @get:JvmName("senderUser") var senderUser: User?, + @get:JvmName("sendDate") var sendDate: Long, + @get:JvmName("text") var text: String?, + @get:JvmName("entities") var entities: Array?, + @get:JvmName("isPrivate") var isPrivate: Boolean?, + @get:JvmName("isSaved") var isSaved: Boolean?, + @get:JvmName("canBeUpgraded") var canBeUpgraded: Boolean?, + @get:JvmName("wasRefunded") var wasRefunded: Boolean?, + @get:JvmName("convertStarCount") var convertStarCount: Int?, + @get:JvmName("prepaidUpgradeStarCount") var prepaidUpgradeStarCount: Int? +) : OwnedGift(type = "regular") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftUnique.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftUnique.kt new file mode 100644 index 00000000..5ca06f81 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftUnique.kt @@ -0,0 +1,15 @@ +package com.pengrad.telegrambot.model.gift.owned + +import com.pengrad.telegrambot.model.User +import com.pengrad.telegrambot.model.gift.Gift + +@Suppress("unused") +class OwnedGiftUnique( + @get:JvmName("gift") val gift: Gift, + @get:JvmName("ownedGiftId") var ownedGiftId: String?, + @get:JvmName("senderUser") var senderUser: User?, + @get:JvmName("sendDate") var sendDate: Long, + @get:JvmName("isSaved") var isSaved: Boolean?, + @get:JvmName("canBeTransferred") var canBeTransferred: Boolean?, + @get:JvmName("transferStarCount") var prepaidUpgradeStarCount: Int? +) : OwnedGift(type = "unique") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGifts.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGifts.kt new file mode 100644 index 00000000..7e187835 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGifts.kt @@ -0,0 +1,25 @@ +package com.pengrad.telegrambot.model.gift.owned + +data class OwnedGifts( + @get:JvmName("totalAmount") var totalAmount: Int, + @get:JvmName("gifts") var gifts: Array, + @get:JvmName("nextOffset") var nextOffset: String? +) { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is OwnedGifts) return false + + return totalAmount == other.totalAmount && + gifts.contentEquals(other.gifts) && + nextOffset == other.nextOffset + } + + override fun hashCode(): Int { + var result = totalAmount + result = 31 * result + gifts.contentHashCode() + result = 31 * result + (nextOffset?.hashCode() ?: 0) + return result + } + +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/GetBusinessAccountGifts.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/GetBusinessAccountGifts.kt new file mode 100644 index 00000000..30d62eef --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/GetBusinessAccountGifts.kt @@ -0,0 +1,59 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.GetBusinessAccountGiftsResponse +import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class GetBusinessAccountGifts private constructor( + businessConnectionId: String, + excludeUnsaved: Boolean?, + excludeSaved: Boolean?, + excludeUnlimited: Boolean?, + excludeLimited: Boolean?, + excludeUnique: Boolean?, + sortByPrice: Boolean?, + offset: String?, + limit: Int? +): KBaseRequest(GetBusinessAccountGiftsResponse::class) { + + constructor(businessConnectionId: String) : this( + businessConnectionId = businessConnectionId, + excludeUnsaved = null, + excludeSaved = null, + excludeUnlimited = null, + excludeLimited = null, + excludeUnique = null, + sortByPrice = null, + offset = null, + limit = null, + ) + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + + var excludeUnsaved: Boolean? by optionalRequestParameter(excludeUnsaved, customParameterName = "exclude_unsaved") + fun excludeUnsaved(excludeUnsaved: Boolean) = applySelf { this.excludeUnsaved = excludeUnsaved } + + var excludeSaved: Boolean? by optionalRequestParameter(excludeSaved, customParameterName = "exclude_saved") + fun excludeSaved(excludeSaved: Boolean) = applySelf { this.excludeSaved = excludeSaved } + + var excludeUnlimited: Boolean? by optionalRequestParameter(excludeUnlimited, customParameterName = "exclude_unlimited") + fun excludeUnlimited(excludeUnlimited: Boolean) = applySelf { this.excludeUnlimited = excludeUnlimited } + + var excludeLimited: Boolean? by optionalRequestParameter(excludeLimited, customParameterName = "exclude_limited") + fun excludeLimited(excludeLimited: Boolean) = applySelf { this.excludeLimited = excludeLimited } + + var excludeUnique: Boolean? by optionalRequestParameter(excludeUnique, customParameterName = "exclude_unique") + fun excludeUnique(excludeUnique: Boolean) = applySelf { this.excludeUnique = excludeUnique } + + var sortByPrice: Boolean? by optionalRequestParameter(sortByPrice, customParameterName = "sort_by_price") + fun sortByPrice(sortByPrice: Boolean) = applySelf { this.sortByPrice = sortByPrice } + + var offset: String? by optionalRequestParameter(offset, customParameterName = "offset") + fun offset(offset: String) = applySelf { this.offset = offset } + + var limit: Int? by optionalRequestParameter(limit, customParameterName = "limit") + fun limit(limit: Int) = applySelf { this.limit = limit } + +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/response/GetBusinessAccountGiftsResponse.kt b/library/src/main/java/com/pengrad/telegrambot/response/GetBusinessAccountGiftsResponse.kt new file mode 100644 index 00000000..e67ddee9 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/response/GetBusinessAccountGiftsResponse.kt @@ -0,0 +1,5 @@ +package com.pengrad.telegrambot.response + +import com.pengrad.telegrambot.model.gift.owned.OwnedGifts + +data class GetBusinessAccountGiftsResponse(val result: OwnedGifts) : BaseResponse() From 54c86f2c4938ac3465d84709b8047e506f025918 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:46:41 +0200 Subject: [PATCH 13/34] Added the method convertGiftToStars, allowing bots to convert gifts received by a managed business account to Telegram Stars. --- .../request/business/ConvertGiftToStars.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/ConvertGiftToStars.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/ConvertGiftToStars.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/ConvertGiftToStars.kt new file mode 100644 index 00000000..7d933f14 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/ConvertGiftToStars.kt @@ -0,0 +1,16 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class ConvertGiftToStars( + businessConnectionId: String, + ownedGiftId: String +) : KBaseRequest(BaseResponse::class) { + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val ownedGiftId: String by requestParameter(ownedGiftId, customParameterName = "owned_gift_id") + +} \ No newline at end of file From e5697dc407eff16f4d4a27b81abca291973fd644 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:46:59 +0200 Subject: [PATCH 14/34] Added the method upgradeGift, allowing bots to upgrade regular gifts received by a managed business account to unique gifts. --- .../request/business/UpgradeGift.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/UpgradeGift.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/UpgradeGift.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/UpgradeGift.kt new file mode 100644 index 00000000..bcf162f3 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/UpgradeGift.kt @@ -0,0 +1,32 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class UpgradeGift private constructor( + businessConnectionId: String, + ownedGiftId: String, + keepOriginalDetails: Boolean?, + starCount: Int? +): KBaseRequest(BaseResponse::class) { + + constructor(businessConnectionId: String, ownedGiftId: String) : this( + businessConnectionId = businessConnectionId, + ownedGiftId = ownedGiftId, + keepOriginalDetails = null, + starCount = null + ) + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val ownedGiftId: String by requestParameter(ownedGiftId, customParameterName = "owned_gift_id") + + var keepOriginalDetails: Boolean? by optionalRequestParameter(keepOriginalDetails, customParameterName = "keep_original_details") + fun keepOriginalDetails(keepOriginalDetails: Boolean) = applySelf { this.keepOriginalDetails = keepOriginalDetails } + + var starCount: Int? by optionalRequestParameter(starCount, customParameterName = "star_count") + fun starCount(starCount: Int) = applySelf { this.starCount = starCount } + +} \ No newline at end of file From af685a6ec5452e8d4117f2c24460f1f852bcd6d6 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:47:14 +0200 Subject: [PATCH 15/34] Added the method transferGift, allowing bots to transfer unique gifts owned by a managed business account. --- .../request/business/TransferGift.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/TransferGift.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/TransferGift.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/TransferGift.kt new file mode 100644 index 00000000..e9247f06 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/TransferGift.kt @@ -0,0 +1,30 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class TransferGift private constructor( + businessConnectionId: String, + ownedGiftId: String, + newOwnerChatId: Long, + starCount: Int? +): KBaseRequest(BaseResponse::class) { + + constructor(businessConnectionId: String, ownedGiftId: String, newOwnerChatId: Long) : this( + businessConnectionId = businessConnectionId, + ownedGiftId = ownedGiftId, + newOwnerChatId = newOwnerChatId, + starCount = null + ) + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val ownedGiftId: String by requestParameter(ownedGiftId, customParameterName = "owned_gift_id") + val newOwnerChatId: Long by requestParameter(newOwnerChatId, customParameterName = "new_owner_chat_id") + + var starCount: Int? by optionalRequestParameter(starCount, customParameterName = "star_count") + fun starCount(starCount: Int) = applySelf { this.starCount = starCount } + +} \ No newline at end of file From b9097b419092323c6e367a6f20eadf4b0cff44ab Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 17:58:31 +0200 Subject: [PATCH 16/34] Added the classes InputStoryContentPhoto and InputStoryContentVideo representing the content of a story to post. --- .../model/inputstory/InputStoryContent.kt | 3 ++ .../inputstory/InputStoryContentPhoto.kt | 4 +++ .../inputstory/InputStoryContentVideo.kt | 30 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContent.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentPhoto.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentVideo.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContent.kt b/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContent.kt new file mode 100644 index 00000000..bc7d8f20 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContent.kt @@ -0,0 +1,3 @@ +package com.pengrad.telegrambot.model.inputstory + +open class InputStoryContent(val type: String) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentPhoto.kt b/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentPhoto.kt new file mode 100644 index 00000000..5e50c59c --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentPhoto.kt @@ -0,0 +1,4 @@ +package com.pengrad.telegrambot.model.inputstory + +@Suppress("unused") +class InputStoryContentPhoto(val photo: String) : InputStoryContent(type = "photo") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentVideo.kt b/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentVideo.kt new file mode 100644 index 00000000..db69c702 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentVideo.kt @@ -0,0 +1,30 @@ +package com.pengrad.telegrambot.model.inputstory + +@Suppress("unused") +class InputStoryContentVideo private constructor( + val video: String, + var duration: Double?, + var coverFrameTimestamp: Double?, + var isAnimation: Boolean? +) : InputStoryContent(type = "video") { + + constructor(video: String) : this( + video = video, + duration = null, + coverFrameTimestamp = null, + isAnimation = null + ) + + fun duration(duration: Double) = apply { + this.duration = duration + } + + fun coverFrameTimestamp(coverFrameTimestamp: Double) = apply { + this.coverFrameTimestamp = coverFrameTimestamp + } + + fun isAnimation(isAnimation: Boolean) = apply { + this.isAnimation = isAnimation + } + +} \ No newline at end of file From aa1d3a48fc15f83eb85ee0131aed6cf7cbac8689 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 18:20:15 +0200 Subject: [PATCH 17/34] Added the classes StoryArea, StoryAreaPosition, LocationAddress, StoryAreaTypeLocation, StoryAreaTypeSuggestedReaction, StoryAreaTypeLink, StoryAreaTypeWeather and StoryAreaTypeUniqueGift, describing clickable active areas on stories. --- .../telegrambot/model/LocationAddress.kt | 30 +++++++++++++++++++ .../model/story/area/StoryAreaPosition.kt | 10 +++++++ .../model/story/area/type/StoryAreaType.kt | 5 ++++ .../story/area/type/StoryAreaTypeLink.kt | 6 ++++ .../story/area/type/StoryAreaTypeLocation.kt | 22 ++++++++++++++ .../type/StoryAreaTypeSuggestedReaction.kt | 27 +++++++++++++++++ .../area/type/StoryAreaTypeUniqueGift.kt | 6 ++++ .../story/area/type/StoryAreaTypeWeather.kt | 8 +++++ 8 files changed, 114 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/LocationAddress.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/story/area/StoryAreaPosition.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaType.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeLink.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeLocation.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeSuggestedReaction.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeUniqueGift.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeWeather.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/LocationAddress.kt b/library/src/main/java/com/pengrad/telegrambot/model/LocationAddress.kt new file mode 100644 index 00000000..511d3a79 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/LocationAddress.kt @@ -0,0 +1,30 @@ +package com.pengrad.telegrambot.model + +@Suppress("unused") +class LocationAddress private constructor( + @get:JvmName("countryCode") val countryCode: String, + @get:JvmName("state") var state: String?, + @get:JvmName("city") var city: String?, + @get:JvmName("street") var street: String? +) { + + constructor(countryCode: String) : this( + countryCode = countryCode, + state = null, + city = null, + street = null + ) + + fun state(state: String) = apply { + this.state = state + } + + fun city(city: String) = apply { + this.city = city + } + + fun street(street: String) = apply { + this.street = street + } + +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/story/area/StoryAreaPosition.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/area/StoryAreaPosition.kt new file mode 100644 index 00000000..25ac5a96 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/area/StoryAreaPosition.kt @@ -0,0 +1,10 @@ +package com.pengrad.telegrambot.model.story.area + +data class StoryAreaPosition( + @get:JvmName("xPercentage") val xPercentage: Double, + @get:JvmName("yPercentage") val yPercentage: Double, + @get:JvmName("widthPercentage") val widthPercentage: Double, + @get:JvmName("heightPercentage") val heightPercentage: Double, + @get:JvmName("rotationAngle") val rotationAngle: Double, + @get:JvmName("cornerRadiusPercentage") val cornerRadiusPercentage: Double +) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaType.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaType.kt new file mode 100644 index 00000000..94cb15ed --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaType.kt @@ -0,0 +1,5 @@ +package com.pengrad.telegrambot.model.story.area.type + +open class StoryAreaType( + @get:JvmName("type") val type: String +) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeLink.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeLink.kt new file mode 100644 index 00000000..b210fb6f --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeLink.kt @@ -0,0 +1,6 @@ +package com.pengrad.telegrambot.model.story.area.type + +@Suppress("unused") +class StoryAreaTypeLink( + @get:JvmName("url") val url: String +): StoryAreaType(type = "link") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeLocation.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeLocation.kt new file mode 100644 index 00000000..a6ac7493 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeLocation.kt @@ -0,0 +1,22 @@ +package com.pengrad.telegrambot.model.story.area.type + +import com.pengrad.telegrambot.model.LocationAddress + +@Suppress("unused") +class StoryAreaTypeLocation private constructor( + @get:JvmName("latitude") val latitude: Double, + @get:JvmName("longitude") val longitude: Double, + @get:JvmName("address") var address: LocationAddress? +): StoryAreaType(type = "location") { + + constructor(latitude: Double, longitude: Double) : this( + latitude = latitude, + longitude = longitude, + address = null + ) + + fun address(address: LocationAddress) = apply { + this.address = address + } + +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeSuggestedReaction.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeSuggestedReaction.kt new file mode 100644 index 00000000..f2de8f9d --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeSuggestedReaction.kt @@ -0,0 +1,27 @@ +package com.pengrad.telegrambot.model.story.area.type + +import com.pengrad.telegrambot.model.LocationAddress +import com.pengrad.telegrambot.model.reaction.ReactionType + +@Suppress("unused") +class StoryAreaTypeSuggestedReaction private constructor( + @get:JvmName("reactionType") val reactionType: ReactionType, + @get:JvmName("isDark") var isDark: Boolean?, + @get:JvmName("isFlipped") var isFlipped: Boolean? +): StoryAreaType(type = "suggested_reaction") { + + constructor(reactionType: ReactionType) : this( + reactionType = reactionType, + isDark = null, + isFlipped = null + ) + + fun isDark(isDark: Boolean) = apply { + this.isDark = isDark + } + + fun isFlipped(isFlipped: Boolean) = apply { + this.isFlipped = isFlipped + } + +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeUniqueGift.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeUniqueGift.kt new file mode 100644 index 00000000..8c9abb55 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeUniqueGift.kt @@ -0,0 +1,6 @@ +package com.pengrad.telegrambot.model.story.area.type + +@Suppress("unused") +class StoryAreaTypeUniqueGift( + @get:JvmName("name") val name: String +): StoryAreaType(type = "unique_gift") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeWeather.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeWeather.kt new file mode 100644 index 00000000..3ed6b7b5 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeWeather.kt @@ -0,0 +1,8 @@ +package com.pengrad.telegrambot.model.story.area.type + +@Suppress("unused") +class StoryAreaTypeWeather( + @get:JvmName("temperature") val temperature: Double, + @get:JvmName("emoji") val emoji: String, + @get:JvmName("backgroundColor") val backgroundColor: Int +): StoryAreaType(type = "weather") \ No newline at end of file From 0d5df573654725f13fc36604c61f8e6a2f32f649 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 18:28:50 +0200 Subject: [PATCH 18/34] Added missing @get:JvmName --- .../telegrambot/model/gift/owned/OwnedGift.kt | 4 +- .../model/gift/owned/OwnedGiftRegular.kt | 64 ++++++++++++++++++- .../inputprofilephoto/InputProfilePhoto.kt | 4 +- .../InputProfilePhotoAnimated.kt | 4 +- .../InputProfilePhotoStatic.kt | 4 +- .../model/inputstory/InputStoryContent.kt | 3 - .../inputstory/InputStoryContentPhoto.kt | 4 -- .../story/inputstory/InputStoryContent.kt | 5 ++ .../inputstory/InputStoryContentPhoto.kt | 6 ++ .../inputstory/InputStoryContentVideo.kt | 10 +-- 10 files changed, 88 insertions(+), 20 deletions(-) delete mode 100644 library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContent.kt delete mode 100644 library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentPhoto.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/story/inputstory/InputStoryContent.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/story/inputstory/InputStoryContentPhoto.kt rename library/src/main/java/com/pengrad/telegrambot/model/{ => story}/inputstory/InputStoryContentVideo.kt (67%) diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGift.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGift.kt index cb11eada..856c7591 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGift.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGift.kt @@ -1,3 +1,5 @@ package com.pengrad.telegrambot.model.gift.owned -open class OwnedGift(val type: String) \ No newline at end of file +open class OwnedGift( + @get:JvmName("type") val type: String +) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt index 58107c17..9facb02a 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt @@ -2,13 +2,14 @@ package com.pengrad.telegrambot.model.gift.owned import com.pengrad.telegrambot.model.User import com.pengrad.telegrambot.model.gift.Gift +import com.pengrad.telegrambot.model.inputprofilephoto.InputProfilePhotoAnimated @Suppress("unused") -class OwnedGiftRegular( +class OwnedGiftRegular private constructor( @get:JvmName("gift") val gift: Gift, @get:JvmName("ownedGiftId") var ownedGiftId: String?, @get:JvmName("senderUser") var senderUser: User?, - @get:JvmName("sendDate") var sendDate: Long, + @get:JvmName("sendDate") val sendDate: Long, @get:JvmName("text") var text: String?, @get:JvmName("entities") var entities: Array?, @get:JvmName("isPrivate") var isPrivate: Boolean?, @@ -17,4 +18,61 @@ class OwnedGiftRegular( @get:JvmName("wasRefunded") var wasRefunded: Boolean?, @get:JvmName("convertStarCount") var convertStarCount: Int?, @get:JvmName("prepaidUpgradeStarCount") var prepaidUpgradeStarCount: Int? -) : OwnedGift(type = "regular") \ No newline at end of file +) : OwnedGift(type = "regular") { + + constructor(gift: Gift, sendDate: Long) : this( + gift = gift, + ownedGiftId = null, + senderUser = null, + sendDate = sendDate, + text = null, + entities = null, + isPrivate = null, + isSaved = null, + canBeUpgraded = null, + wasRefunded = null, + convertStarCount = null, + prepaidUpgradeStarCount = null, + ) + + fun ownedGiftId(ownedGiftId: String) = apply { + this.ownedGiftId = ownedGiftId + } + + fun senderUser(senderUser: User) = apply { + this.senderUser = senderUser + } + + fun text(text: String) = apply { + this.text = text + } + + fun entities(entities: Array) = apply { + this.entities = entities + } + + fun isPrivate(isPrivate: Boolean) = apply { + this.isPrivate = isPrivate + } + + fun isSaved(isSaved: Boolean) = apply { + this.isSaved = isSaved + } + + fun canBeUpgraded(canBeUpgraded: Boolean) = apply { + this.canBeUpgraded = canBeUpgraded + } + + fun wasRefunded(wasRefunded: Boolean) = apply { + this.wasRefunded = wasRefunded + } + + fun convertStarCount(convertStarCount: Int) = apply { + this.convertStarCount = convertStarCount + } + + fun prepaidUpgradeStarCount(prepaidUpgradeStarCount: Int) = apply { + this.prepaidUpgradeStarCount = prepaidUpgradeStarCount + } + +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhoto.kt b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhoto.kt index 0a4c7638..ba9f31c7 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhoto.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhoto.kt @@ -1,3 +1,5 @@ package com.pengrad.telegrambot.model.inputprofilephoto -open class InputProfilePhoto(val type: String) \ No newline at end of file +open class InputProfilePhoto( + @get:JvmName("type") val type: String +) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoAnimated.kt b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoAnimated.kt index 8f4d5091..e2a917ea 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoAnimated.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoAnimated.kt @@ -2,8 +2,8 @@ package com.pengrad.telegrambot.model.inputprofilephoto @Suppress("unused") class InputProfilePhotoAnimated private constructor( - val animation: String, - var mainFrameTimestamp: Double? + @get:JvmName("animation") val animation: String, + @get:JvmName("mainFrameTimestamp") var mainFrameTimestamp: Double? ) : InputProfilePhoto(type = "animated") { constructor(animation: String) : this( diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoStatic.kt b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoStatic.kt index e716386e..cf2673cb 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoStatic.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/inputprofilephoto/InputProfilePhotoStatic.kt @@ -1,4 +1,6 @@ package com.pengrad.telegrambot.model.inputprofilephoto @Suppress("unused") -class InputProfilePhotoStatic(val photo: String) : InputProfilePhoto(type = "static") \ No newline at end of file +class InputProfilePhotoStatic( + @get:JvmName("photo") val photo: String +) : InputProfilePhoto(type = "static") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContent.kt b/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContent.kt deleted file mode 100644 index bc7d8f20..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContent.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.pengrad.telegrambot.model.inputstory - -open class InputStoryContent(val type: String) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentPhoto.kt b/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentPhoto.kt deleted file mode 100644 index 5e50c59c..00000000 --- a/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentPhoto.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.pengrad.telegrambot.model.inputstory - -@Suppress("unused") -class InputStoryContentPhoto(val photo: String) : InputStoryContent(type = "photo") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/story/inputstory/InputStoryContent.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/inputstory/InputStoryContent.kt new file mode 100644 index 00000000..87374698 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/inputstory/InputStoryContent.kt @@ -0,0 +1,5 @@ +package com.pengrad.telegrambot.model.story.inputstory + +open class InputStoryContent( + @get:JvmName("type") val type: String +) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/story/inputstory/InputStoryContentPhoto.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/inputstory/InputStoryContentPhoto.kt new file mode 100644 index 00000000..71137cd2 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/inputstory/InputStoryContentPhoto.kt @@ -0,0 +1,6 @@ +package com.pengrad.telegrambot.model.story.inputstory + +@Suppress("unused") +class InputStoryContentPhoto( + @get:JvmName("photo") val photo: String +) : InputStoryContent(type = "photo") \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentVideo.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/inputstory/InputStoryContentVideo.kt similarity index 67% rename from library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentVideo.kt rename to library/src/main/java/com/pengrad/telegrambot/model/story/inputstory/InputStoryContentVideo.kt index db69c702..56912b55 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/inputstory/InputStoryContentVideo.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/inputstory/InputStoryContentVideo.kt @@ -1,11 +1,11 @@ -package com.pengrad.telegrambot.model.inputstory +package com.pengrad.telegrambot.model.story.inputstory @Suppress("unused") class InputStoryContentVideo private constructor( - val video: String, - var duration: Double?, - var coverFrameTimestamp: Double?, - var isAnimation: Boolean? + @get:JvmName("video") val video: String, + @get:JvmName("duration") var duration: Double?, + @get:JvmName("coverFrameTimestamp") var coverFrameTimestamp: Double?, + @get:JvmName("isAnimation") var isAnimation: Boolean? ) : InputStoryContent(type = "video") { constructor(video: String) : this( From f79724a1ab0c9f755d515e109e8c4a891799601f Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 18:29:22 +0200 Subject: [PATCH 19/34] StoryArea.kt --- .../telegrambot/model/gift/owned/OwnedGiftRegular.kt | 1 - .../com/pengrad/telegrambot/model/story/StoryArea.kt | 10 ++++++++++ .../story/area/type/StoryAreaTypeSuggestedReaction.kt | 1 - 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/story/StoryArea.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt index 9facb02a..e5cad655 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt @@ -2,7 +2,6 @@ package com.pengrad.telegrambot.model.gift.owned import com.pengrad.telegrambot.model.User import com.pengrad.telegrambot.model.gift.Gift -import com.pengrad.telegrambot.model.inputprofilephoto.InputProfilePhotoAnimated @Suppress("unused") class OwnedGiftRegular private constructor( diff --git a/library/src/main/java/com/pengrad/telegrambot/model/story/StoryArea.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/StoryArea.kt new file mode 100644 index 00000000..fb2eb290 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/StoryArea.kt @@ -0,0 +1,10 @@ +package com.pengrad.telegrambot.model.story + +import com.pengrad.telegrambot.model.story.area.StoryAreaPosition +import com.pengrad.telegrambot.model.story.area.type.StoryAreaType + +@Suppress("unused") +class StoryArea( + @get:JvmName("position") val position: StoryAreaPosition, + @get:JvmName("type") val type: StoryAreaType +) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeSuggestedReaction.kt b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeSuggestedReaction.kt index f2de8f9d..71670f00 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeSuggestedReaction.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/story/area/type/StoryAreaTypeSuggestedReaction.kt @@ -1,6 +1,5 @@ package com.pengrad.telegrambot.model.story.area.type -import com.pengrad.telegrambot.model.LocationAddress import com.pengrad.telegrambot.model.reaction.ReactionType @Suppress("unused") From 86f1b505387d0e4622e552e0c5a3cbb0019f98e0 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 18:44:45 +0200 Subject: [PATCH 20/34] Added the method postStory, allowing bots to post a story on behalf of a managed business account. --- .../telegrambot/request/business/PostStory.kt | 59 +++++++++++++++++++ .../telegrambot/response/PostStoryResponse.kt | 5 ++ 2 files changed, 64 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/PostStory.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/response/PostStoryResponse.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/PostStory.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/PostStory.kt new file mode 100644 index 00000000..04653758 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/PostStory.kt @@ -0,0 +1,59 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.model.MessageEntity +import com.pengrad.telegrambot.model.story.StoryArea +import com.pengrad.telegrambot.model.story.inputstory.InputStoryContent +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.request.business.GetBusinessAccountGifts +import com.pengrad.telegrambot.response.PostStoryResponse +import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class PostStory private constructor( + businessConnectionId: String, + content: InputStoryContent, + activePeriod: Int, + caption: String?, + parseMode: String?, + captionEntities: Array?, + areas: Array?, + postToChatPage: Boolean?, + protectContent: Boolean? +): KBaseRequest(PostStoryResponse::class) { + + constructor(businessConnectionId: String, content: InputStoryContent, activePeriod: Int) : this( + businessConnectionId = businessConnectionId, + content = content, + activePeriod = activePeriod, + caption = null, + parseMode = null, + captionEntities = null, + areas = null, + postToChatPage = null, + protectContent = null + ) + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val content: InputStoryContent by requestParameter(content, customParameterName = "content") + val activePeriod: Int by requestParameter(activePeriod, customParameterName = "active_period") + + var caption: String? by optionalRequestParameter(caption, customParameterName = "caption") + fun caption(caption: String) = applySelf { this.caption = caption } + + var parseMode: String? by optionalRequestParameter(parseMode, customParameterName = "parse_mode") + fun parseMode(parseMode: String) = applySelf { this.parseMode = parseMode } + + var captionEntities: Array? by optionalRequestParameter(captionEntities, customParameterName = "caption_entities") + fun captionEntities(captionEntities: Array) = applySelf { this.captionEntities = captionEntities } + + var areas: Array? by optionalRequestParameter(areas, customParameterName = "areas") + fun areas(areas: Array) = applySelf { this.areas = areas } + + var postToChatPage: Boolean? by optionalRequestParameter(postToChatPage, customParameterName = "post_to_chat_page") + fun postToChatPage(postToChatPage: Boolean) = applySelf { this.postToChatPage = postToChatPage } + + var protectContent: Boolean? by optionalRequestParameter(protectContent, customParameterName = "protect_content") + fun protectContent(protectContent: Boolean) = applySelf { this.protectContent = protectContent } + +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/response/PostStoryResponse.kt b/library/src/main/java/com/pengrad/telegrambot/response/PostStoryResponse.kt new file mode 100644 index 00000000..7757c8c9 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/response/PostStoryResponse.kt @@ -0,0 +1,5 @@ +package com.pengrad.telegrambot.response + +import com.pengrad.telegrambot.model.Story + +data class PostStoryResponse(val result: Story) : BaseResponse() From aeb4fe521d53d068b54d985fa3ef1478d2421e67 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 18:47:55 +0200 Subject: [PATCH 21/34] Added the method editStory, allowing bots to edit stories they had previously posted on behalf of a managed business account. --- .../telegrambot/request/business/EditStory.kt | 48 +++++++++++++++++++ .../telegrambot/request/business/PostStory.kt | 1 - .../telegrambot/response/EditStoryResponse.kt | 5 ++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/EditStory.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/response/EditStoryResponse.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/EditStory.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/EditStory.kt new file mode 100644 index 00000000..ca7e6e87 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/EditStory.kt @@ -0,0 +1,48 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.model.MessageEntity +import com.pengrad.telegrambot.model.story.StoryArea +import com.pengrad.telegrambot.model.story.inputstory.InputStoryContent +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.EditStoryResponse +import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class EditStory private constructor( + businessConnectionId: String, + storyId: Int, + content: InputStoryContent, + caption: String?, + parseMode: String?, + captionEntities: Array?, + areas: Array? +): KBaseRequest(EditStoryResponse::class) { + + constructor(businessConnectionId: String, storyId: Int, content: InputStoryContent) : this( + businessConnectionId = businessConnectionId, + storyId = storyId, + content = content, + caption = null, + parseMode = null, + captionEntities = null, + areas = null + ) + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val storyId: Int by requestParameter(storyId, customParameterName = "story_id") + val content: InputStoryContent by requestParameter(content, customParameterName = "content") + + var caption: String? by optionalRequestParameter(caption, customParameterName = "caption") + fun caption(caption: String) = applySelf { this.caption = caption } + + var parseMode: String? by optionalRequestParameter(parseMode, customParameterName = "parse_mode") + fun parseMode(parseMode: String) = applySelf { this.parseMode = parseMode } + + var captionEntities: Array? by optionalRequestParameter(captionEntities, customParameterName = "caption_entities") + fun captionEntities(captionEntities: Array) = applySelf { this.captionEntities = captionEntities } + + var areas: Array? by optionalRequestParameter(areas, customParameterName = "areas") + fun areas(areas: Array) = applySelf { this.areas = areas } + +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/PostStory.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/PostStory.kt index 04653758..98cd06cd 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/business/PostStory.kt +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/PostStory.kt @@ -4,7 +4,6 @@ import com.pengrad.telegrambot.model.MessageEntity import com.pengrad.telegrambot.model.story.StoryArea import com.pengrad.telegrambot.model.story.inputstory.InputStoryContent import com.pengrad.telegrambot.request.KBaseRequest -import com.pengrad.telegrambot.request.business.GetBusinessAccountGifts import com.pengrad.telegrambot.response.PostStoryResponse import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter import com.pengrad.telegrambot.utility.kotlin.requestParameter diff --git a/library/src/main/java/com/pengrad/telegrambot/response/EditStoryResponse.kt b/library/src/main/java/com/pengrad/telegrambot/response/EditStoryResponse.kt new file mode 100644 index 00000000..7ec088d7 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/response/EditStoryResponse.kt @@ -0,0 +1,5 @@ +package com.pengrad.telegrambot.response + +import com.pengrad.telegrambot.model.Story + +data class EditStoryResponse(val result: Story) : BaseResponse() From 6efe3aa373b150ce5230dbb5c31fefe1f2717841 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 18:49:55 +0200 Subject: [PATCH 22/34] Added the method deleteStory, allowing bots to delete stories they had previously posted on behalf of a managed business account. --- .../telegrambot/request/business/DeleteStory.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/business/DeleteStory.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/business/DeleteStory.kt b/library/src/main/java/com/pengrad/telegrambot/request/business/DeleteStory.kt new file mode 100644 index 00000000..24fdc38d --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/business/DeleteStory.kt @@ -0,0 +1,16 @@ +package com.pengrad.telegrambot.request.business + +import com.pengrad.telegrambot.request.KBaseRequest +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class DeleteStory( + businessConnectionId: String, + storyId: Int +): KBaseRequest(BaseResponse::class) { + + val businessConnectionId: String by requestParameter(businessConnectionId, customParameterName = "business_connection_id") + val storyId: Int by requestParameter(storyId, customParameterName = "story_id") + +} \ No newline at end of file From 6d23edc9fe56997a113ccb27a4dc330eb93a3d67 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:01:02 +0200 Subject: [PATCH 23/34] Added the classes UniqueGiftModel, UniqueGiftSymbol, UniqueGiftBackdropColors, and UniqueGiftBackdrop to describe the properties of a unique gift. --- .../telegrambot/model/gift/unique/UniqueGiftBackdrop.kt | 7 +++++++ .../model/gift/unique/UniqueGiftBackdropColors.kt | 8 ++++++++ .../telegrambot/model/gift/unique/UniqueGiftModel.kt | 9 +++++++++ .../telegrambot/model/gift/unique/UniqueGiftSymbol.kt | 9 +++++++++ 4 files changed, 33 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftBackdrop.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftBackdropColors.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftModel.kt create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftSymbol.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftBackdrop.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftBackdrop.kt new file mode 100644 index 00000000..6e12b447 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftBackdrop.kt @@ -0,0 +1,7 @@ +package com.pengrad.telegrambot.model.gift.unique + +data class UniqueGiftBackdrop( + @get:JvmName("name") val name: String, + @get:JvmName("colors") val colors: UniqueGiftBackdropColors, + @get:JvmName("rarityPerMille") val rarityPerMille: Int +) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftBackdropColors.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftBackdropColors.kt new file mode 100644 index 00000000..f98ec13f --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftBackdropColors.kt @@ -0,0 +1,8 @@ +package com.pengrad.telegrambot.model.gift.unique + +data class UniqueGiftBackdropColors( + @get:JvmName("centerColor") val centerColor: Int, + @get:JvmName("edgeColor") val edgeColor: Int, + @get:JvmName("symbolColor") val symbolColor: Int, + @get:JvmName("textColor") val textColor: Int +) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftModel.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftModel.kt new file mode 100644 index 00000000..bd0721ed --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftModel.kt @@ -0,0 +1,9 @@ +package com.pengrad.telegrambot.model.gift.unique + +import com.pengrad.telegrambot.model.Sticker + +data class UniqueGiftModel( + @get:JvmName("name") val name: String, + @get:JvmName("sticker") val sticker: Sticker, + @get:JvmName("rarityPerMille") val rarityPerMille: Int +) \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftSymbol.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftSymbol.kt new file mode 100644 index 00000000..ed1f315a --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftSymbol.kt @@ -0,0 +1,9 @@ +package com.pengrad.telegrambot.model.gift.unique + +import com.pengrad.telegrambot.model.Sticker + +data class UniqueGiftSymbol( + @get:JvmName("name") val name: String, + @get:JvmName("sticker") val sticker: Sticker, + @get:JvmName("rarityPerMille") val rarityPerMille: Int +) \ No newline at end of file From 88669a98f8a9d0bb4b08c49725961600a6756cc4 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:01:14 +0200 Subject: [PATCH 24/34] Added the class UniqueGift describing a gift that was upgraded to a unique one. --- .../telegrambot/model/gift/unique/UniqueGift.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGift.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGift.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGift.kt new file mode 100644 index 00000000..0416a67d --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGift.kt @@ -0,0 +1,11 @@ +package com.pengrad.telegrambot.model.gift.unique + +@Suppress("unused") +data class UniqueGift( + @get:JvmName("baseName") val baseName: String, + @get:JvmName("name") val name: String, + @get:JvmName("number") val number: Int, + @get:JvmName("model") val model: UniqueGiftModel, + @get:JvmName("symbol") val symbol: UniqueGiftSymbol, + @get:JvmName("backdrop") val backdrop: UniqueGiftBackdrop +) \ No newline at end of file From c29e22d3059fa2dff3b731366371671ebf05a370 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:03:26 +0200 Subject: [PATCH 25/34] Replaced the field can_send_gift with the field accepted_gift_types of the type AcceptedGiftTypes in the class ChatFullInfo. --- .../pengrad/telegrambot/model/ChatFullInfo.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/pengrad/telegrambot/model/ChatFullInfo.java b/library/src/main/java/com/pengrad/telegrambot/model/ChatFullInfo.java index 25a06650..bbddf1b4 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/ChatFullInfo.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/ChatFullInfo.java @@ -4,6 +4,7 @@ import com.pengrad.telegrambot.model.business.BusinessIntro; import com.pengrad.telegrambot.model.business.BusinessLocation; import com.pengrad.telegrambot.model.business.BusinessOpeningHours; +import com.pengrad.telegrambot.model.gift.AcceptedGiftTypes; import com.pengrad.telegrambot.model.reaction.ReactionType; @@ -71,6 +72,7 @@ public enum Type { private Long linked_chat_id; private ChatLocation location; private Boolean can_send_gift; + private AcceptedGiftTypes accepted_gift_types; public Long id() { return id; @@ -247,10 +249,19 @@ public ChatLocation location() { return location; } + /** + * + * @deprecated Use 'acceptedGiftTypes' instead + */ + @Deprecated public Boolean canSendGift() { return can_send_gift; } + public AcceptedGiftTypes acceptedGiftTypes() { + return accepted_gift_types; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -300,7 +311,7 @@ public boolean equals(Object o) { Objects.equals(custom_emoji_sticker_set_name, chat.custom_emoji_sticker_set_name) && Objects.equals(linked_chat_id, chat.linked_chat_id) && Objects.equals(location, chat.location) && - Objects.equals(can_send_gift, chat.can_send_gift); + Objects.equals(accepted_gift_types, chat.accepted_gift_types); } @Override @@ -355,7 +366,7 @@ public String toString() { ", custom_emoji_sticker_set_name=" + custom_emoji_sticker_set_name + ", linked_chat_id=" + linked_chat_id + ", location=" + location + - ", can_send_gift=" + can_send_gift + + ", accepted_gift_types=" + accepted_gift_types + '}'; } } From b8742222fa29cfd1527f41a34c7dc4263def4acc Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:09:47 +0200 Subject: [PATCH 26/34] Added the class GiftInfo and the field gift to the class Message, describing a service message about a regular gift that was sent or received. --- .../pengrad/telegrambot/model/Message.java | 10 +++- .../telegrambot/model/gift/GiftInfo.kt | 48 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/GiftInfo.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Message.java b/library/src/main/java/com/pengrad/telegrambot/model/Message.java index 7a67234b..0dffdefb 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/Message.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/Message.java @@ -2,6 +2,7 @@ import com.pengrad.telegrambot.model.chatbackground.ChatBackground; import com.pengrad.telegrambot.model.chatboost.ChatBoostAdded; +import com.pengrad.telegrambot.model.gift.GiftInfo; import com.pengrad.telegrambot.model.giveaway.Giveaway; import com.pengrad.telegrambot.model.giveaway.GiveawayCompleted; import com.pengrad.telegrambot.model.giveaway.GiveawayCreated; @@ -105,6 +106,7 @@ public class Message extends MaybeInaccessibleMessage implements Serializable { private VideoChatScheduled video_chat_scheduled; private InlineKeyboardMarkup reply_markup; private WebAppData web_app_data; + private GiftInfo gift; public Integer messageThreadId() { return message_thread_id; @@ -435,6 +437,10 @@ public WebAppData webAppData() { return web_app_data; } + public GiftInfo gift() { + return gift; + } + /** * Only for backwards-compatibility with MaybeInaccessibleMessage */ @@ -545,7 +551,8 @@ public boolean equals(Object o) { Objects.equals(video_chat_participants_invited, message.video_chat_participants_invited) && Objects.equals(video_chat_scheduled, message.video_chat_scheduled) && Objects.equals(reply_markup, message.reply_markup) && - Objects.equals(web_app_data, message.web_app_data); + Objects.equals(web_app_data, message.web_app_data) && + Objects.equals(gift, message.gift); } @Override @@ -641,6 +648,7 @@ public String toString() { ", video_chat_scheduled=" + video_chat_scheduled + ", reply_markup=" + reply_markup + ", web_app_data=" + web_app_data + + ", gift=" + gift + '}'; } } diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/GiftInfo.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/GiftInfo.kt new file mode 100644 index 00000000..84d51b52 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/GiftInfo.kt @@ -0,0 +1,48 @@ +package com.pengrad.telegrambot.model.gift + +import com.pengrad.telegrambot.model.MessageEntity + +data class GiftInfo( + @get:JvmName("gift") val gift: Gift, + @get:JvmName("ownedGiftId") val ownedGiftId: String?, + @get:JvmName("convertStarCount") val convertStarCount: Int?, + @get:JvmName("prepaidUpgradeStarCount") val prepaidUpgradeStarCount: Int?, + @get:JvmName("canBeUpgraded") val canBeUpgraded: Boolean?, + @get:JvmName("text") val text: String?, + @get:JvmName("entities") val entities: Array?, + @get:JvmName("isPrivate") val isPrivate: Boolean?, +) { + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is GiftInfo) return false + + return gift == other.gift && + ownedGiftId == other.ownedGiftId && + convertStarCount == other.convertStarCount && + prepaidUpgradeStarCount == other.prepaidUpgradeStarCount && + canBeUpgraded == other.canBeUpgraded && + text == other.text && + entities contentEquals other.entities && + isPrivate == other.isPrivate + } + + override fun hashCode(): Int { + var result = gift.hashCode() + result = 31 * result + (ownedGiftId?.hashCode() ?: 0) + result = 31 * result + (convertStarCount ?: 0) + result = 31 * result + (prepaidUpgradeStarCount ?: 0) + result = 31 * result + (canBeUpgraded?.hashCode() ?: 0) + result = 31 * result + (text?.hashCode() ?: 0) + result = 31 * result + (entities?.contentHashCode() ?: 0) + result = 31 * result + (isPrivate?.hashCode() ?: 0) + return result + } + + override fun toString(): String { + return "GiftInfo(gift=$gift, ownedGiftId=$ownedGiftId, convertStarCount=$convertStarCount, " + + "prepaidUpgradeStarCount=$prepaidUpgradeStarCount, canBeUpgraded=$canBeUpgraded, " + + "text=$text, entities=${entities?.contentToString()}, isPrivate=$isPrivate)" + } + +} \ No newline at end of file From ded9f5f8513dda61b91599765dd96cb69dce4b84 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:16:13 +0200 Subject: [PATCH 27/34] Adding OwnedGift type adapter --- .../model/gift/owned/OwnedGiftRegular.kt | 6 +++- .../model/gift/owned/OwnedGiftUnique.kt | 8 ++++- .../pengrad/telegrambot/utility/BotUtils.java | 2 ++ .../utility/gson/OwnedGiftTypeAdapter.java | 30 +++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 library/src/main/java/com/pengrad/telegrambot/utility/gson/OwnedGiftTypeAdapter.java diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt index e5cad655..a611b02a 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt @@ -17,7 +17,11 @@ class OwnedGiftRegular private constructor( @get:JvmName("wasRefunded") var wasRefunded: Boolean?, @get:JvmName("convertStarCount") var convertStarCount: Int?, @get:JvmName("prepaidUpgradeStarCount") var prepaidUpgradeStarCount: Int? -) : OwnedGift(type = "regular") { +) : OwnedGift(type = TYPE) { + + companion object { + const val TYPE = "regular" + } constructor(gift: Gift, sendDate: Long) : this( gift = gift, diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftUnique.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftUnique.kt index 5ca06f81..6ed4a04c 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftUnique.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftUnique.kt @@ -12,4 +12,10 @@ class OwnedGiftUnique( @get:JvmName("isSaved") var isSaved: Boolean?, @get:JvmName("canBeTransferred") var canBeTransferred: Boolean?, @get:JvmName("transferStarCount") var prepaidUpgradeStarCount: Int? -) : OwnedGift(type = "unique") \ No newline at end of file +) : OwnedGift(type = TYPE) { + + companion object { + const val TYPE = "unique" + } + +} \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java b/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java index 4df59f51..323a79e0 100644 --- a/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java +++ b/library/src/main/java/com/pengrad/telegrambot/utility/BotUtils.java @@ -7,6 +7,7 @@ import com.pengrad.telegrambot.model.chatbackground.BackgroundFill; import com.pengrad.telegrambot.model.chatbackground.BackgroundType; import com.pengrad.telegrambot.model.chatboost.source.ChatBoostSource; +import com.pengrad.telegrambot.model.gift.owned.OwnedGift; import com.pengrad.telegrambot.model.message.MaybeInaccessibleMessage; import com.pengrad.telegrambot.model.message.origin.MessageOrigin; import com.pengrad.telegrambot.model.paidmedia.PaidMedia; @@ -38,6 +39,7 @@ private BotUtils() {} .registerTypeAdapter(RevenueWithdrawalState.class, new RevenueWithdrawalStateTypeAdapter()) .registerTypeAdapter(TransactionPartner.class, TransactionPartnerTypeAdapter.INSTANCE) .registerTypeAdapter(PaidMedia.class, new PaidMediaTypeAdapter()) + .registerTypeAdapter(OwnedGift.class, new OwnedGiftTypeAdapter()) .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .create(); diff --git a/library/src/main/java/com/pengrad/telegrambot/utility/gson/OwnedGiftTypeAdapter.java b/library/src/main/java/com/pengrad/telegrambot/utility/gson/OwnedGiftTypeAdapter.java new file mode 100644 index 00000000..0a82708d --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/utility/gson/OwnedGiftTypeAdapter.java @@ -0,0 +1,30 @@ +package com.pengrad.telegrambot.utility.gson; + +import com.google.gson.*; +import com.pengrad.telegrambot.model.gift.owned.OwnedGift; +import com.pengrad.telegrambot.model.gift.owned.OwnedGiftRegular; +import com.pengrad.telegrambot.model.gift.owned.OwnedGiftUnique; +import com.pengrad.telegrambot.model.paidmedia.PaidMedia; +import com.pengrad.telegrambot.model.paidmedia.PaidMediaPhoto; +import com.pengrad.telegrambot.model.paidmedia.PaidMediaPreview; +import com.pengrad.telegrambot.model.paidmedia.PaidMediaVideo; + +import java.lang.reflect.Type; + +public class OwnedGiftTypeAdapter implements JsonDeserializer { + + @Override + public OwnedGift deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException { + JsonObject object = element.getAsJsonObject(); + JsonPrimitive primitive = object.getAsJsonPrimitive("type"); + String discriminator = primitive != null ? primitive.getAsString() : "unknown"; + + if (OwnedGiftRegular.TYPE.equals(discriminator)) { + return context.deserialize(object, OwnedGiftRegular.class); + } else if (OwnedGiftUnique.TYPE.equals(discriminator)) { + return context.deserialize(object, OwnedGiftUnique.class); + } + + return new OwnedGift(discriminator); + } +} From 86c31a17afadea522635ef0fb136b015ae048743 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:20:32 +0200 Subject: [PATCH 28/34] Added the class UniqueGiftInfo and the field unique_gift to the class Message, describing a service message about a unique gift that was sent or received. --- .../java/com/pengrad/telegrambot/model/Message.java | 10 +++++++++- .../telegrambot/model/gift/unique/UniqueGiftInfo.kt | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftInfo.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Message.java b/library/src/main/java/com/pengrad/telegrambot/model/Message.java index 0dffdefb..52cfb960 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/Message.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/Message.java @@ -3,6 +3,7 @@ import com.pengrad.telegrambot.model.chatbackground.ChatBackground; import com.pengrad.telegrambot.model.chatboost.ChatBoostAdded; import com.pengrad.telegrambot.model.gift.GiftInfo; +import com.pengrad.telegrambot.model.gift.unique.UniqueGiftInfo; import com.pengrad.telegrambot.model.giveaway.Giveaway; import com.pengrad.telegrambot.model.giveaway.GiveawayCompleted; import com.pengrad.telegrambot.model.giveaway.GiveawayCreated; @@ -107,6 +108,7 @@ public class Message extends MaybeInaccessibleMessage implements Serializable { private InlineKeyboardMarkup reply_markup; private WebAppData web_app_data; private GiftInfo gift; + private UniqueGiftInfo unique_gift; public Integer messageThreadId() { return message_thread_id; @@ -441,6 +443,10 @@ public GiftInfo gift() { return gift; } + public UniqueGiftInfo uniqueGift() { + return unique_gift; + } + /** * Only for backwards-compatibility with MaybeInaccessibleMessage */ @@ -552,7 +558,8 @@ public boolean equals(Object o) { Objects.equals(video_chat_scheduled, message.video_chat_scheduled) && Objects.equals(reply_markup, message.reply_markup) && Objects.equals(web_app_data, message.web_app_data) && - Objects.equals(gift, message.gift); + Objects.equals(gift, message.gift) && + Objects.equals(unique_gift, message.unique_gift); } @Override @@ -649,6 +656,7 @@ public String toString() { ", reply_markup=" + reply_markup + ", web_app_data=" + web_app_data + ", gift=" + gift + + ", unique_gift=" + unique_gift + '}'; } } diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftInfo.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftInfo.kt new file mode 100644 index 00000000..f07f49c5 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/unique/UniqueGiftInfo.kt @@ -0,0 +1,9 @@ +package com.pengrad.telegrambot.model.gift.unique + +@Suppress("unused") +data class UniqueGiftInfo( + @get:JvmName("gift") val gift: UniqueGift, + @get:JvmName("origin") val origin: String, + @get:JvmName("ownedGiftId") val ownedGiftId: String?, + @get:JvmName("transferStarCount") val transferStarCount: Int? +) \ No newline at end of file From 2c4f0344eaa380a7eedf84d87142540bcabf4d8a Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:25:42 +0200 Subject: [PATCH 29/34] Added the method giftPremiumSubscription, allowing bots to gift a user a Telegram Premium subscription paid in Telegram Stars. --- .../request/GiftTelegramSubscription.kt | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 library/src/main/java/com/pengrad/telegrambot/request/GiftTelegramSubscription.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/request/GiftTelegramSubscription.kt b/library/src/main/java/com/pengrad/telegrambot/request/GiftTelegramSubscription.kt new file mode 100644 index 00000000..8bdb4652 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/GiftTelegramSubscription.kt @@ -0,0 +1,41 @@ +package com.pengrad.telegrambot.request + +import com.pengrad.telegrambot.model.MessageEntity +import com.pengrad.telegrambot.request.business.TransferGift +import com.pengrad.telegrambot.response.BaseResponse +import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter +import com.pengrad.telegrambot.utility.kotlin.requestParameter + +@Suppress("unused") +class GiftTelegramSubscription private constructor( + userId: Long, + monthCount: Int, + starCount: Int, + text: String?, + textParseMode: String?, + textEntities: Array? +): KBaseRequest(BaseResponse::class) { + + constructor(userId: Long, monthCount: Int, starCount: Int) : this( + userId = userId, + monthCount = monthCount, + starCount = starCount, + text = null, + textParseMode = null, + textEntities = null + ) + + val userId: Long by requestParameter(userId, customParameterName = "user_id") + val monthCount: Int by requestParameter(monthCount, customParameterName = "month_count") + val starCount: Int by requestParameter(starCount, customParameterName = "star_count") + + var text: String? by optionalRequestParameter(text, customParameterName = "text") + fun text(text: String) = applySelf { this.text = text } + + var textParseMode: String? by optionalRequestParameter(textParseMode, customParameterName = "text_parse_mode") + fun textParseMode(textParseMode: String) = applySelf { this.textParseMode = textParseMode } + + var textEntities: Array? by optionalRequestParameter(textEntities, customParameterName = "text_entities") + fun textEntities(textEntities: Array) = applySelf { this.textEntities = textEntities } + +} \ No newline at end of file From 56ec945ad2202e3269a7aca9e5b1a7d88fe07c52 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:28:33 +0200 Subject: [PATCH 30/34] Added the field premium_subscription_duration and transaction_type to the class TransactionPartnerUser --- .../model/stars/partner/TransactionPartnerUser.kt | 8 +++++++- .../telegrambot/request/GiftTelegramSubscription.kt | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/pengrad/telegrambot/model/stars/partner/TransactionPartnerUser.kt b/library/src/main/java/com/pengrad/telegrambot/model/stars/partner/TransactionPartnerUser.kt index 4d2c2b9a..429702c8 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/stars/partner/TransactionPartnerUser.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/stars/partner/TransactionPartnerUser.kt @@ -7,13 +7,15 @@ import com.pengrad.telegrambot.model.stars.affiliate.AffiliateInfo import com.pengrad.telegrambot.model.stars.partner.TransactionPartnerType.USER data class TransactionPartnerUser( + @get:JvmName("transactionType") val transactionType: String, @get:JvmName("user") val user: User, @get:JvmName("affiliate") val affiliate: AffiliateInfo, @get:JvmName("invoicePayload") val invoicePayload: String? = null, @get:JvmName("paidMedia") val paidMedia: Array? = null, @get:JvmName("paidMediaPayload") val paidMediaPayload: String? = null, @get:JvmName("subscriptionPeriod") val subscriptionPeriod: Int? = null, - @get:JvmName("gift") val gift: Gift? = null + @get:JvmName("gift") val gift: Gift? = null, + @get:JvmName("premiumSubscriptionDuration") val premiumSubscriptionDuration: Int? = null ) : TransactionPartner { override val type: String @@ -26,6 +28,7 @@ data class TransactionPartnerUser( other as TransactionPartnerUser if (subscriptionPeriod != other.subscriptionPeriod) return false + if (transactionType != other.transactionType) return false if (user != other.user) return false if (affiliate != other.affiliate) return false if (invoicePayload != other.invoicePayload) return false @@ -35,6 +38,7 @@ data class TransactionPartnerUser( } else if (other.paidMedia != null) return false if (paidMediaPayload != other.paidMediaPayload) return false if (gift != other.gift) return false + if (premiumSubscriptionDuration != other.premiumSubscriptionDuration) return false if (type != other.type) return false return true @@ -42,12 +46,14 @@ data class TransactionPartnerUser( override fun hashCode(): Int { var result = subscriptionPeriod ?: 0 + result = 31 * result + transactionType.hashCode() result = 31 * result + user.hashCode() result = 31 * result + affiliate.hashCode() result = 31 * result + (invoicePayload?.hashCode() ?: 0) result = 31 * result + (paidMedia?.contentHashCode() ?: 0) result = 31 * result + (paidMediaPayload?.hashCode() ?: 0) result = 31 * result + (gift?.hashCode() ?: 0) + result = 31 * result + (premiumSubscriptionDuration?.hashCode() ?: 0) result = 31 * result + type.hashCode() return result } diff --git a/library/src/main/java/com/pengrad/telegrambot/request/GiftTelegramSubscription.kt b/library/src/main/java/com/pengrad/telegrambot/request/GiftTelegramSubscription.kt index 8bdb4652..4ab17673 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/GiftTelegramSubscription.kt +++ b/library/src/main/java/com/pengrad/telegrambot/request/GiftTelegramSubscription.kt @@ -1,7 +1,6 @@ package com.pengrad.telegrambot.request import com.pengrad.telegrambot.model.MessageEntity -import com.pengrad.telegrambot.request.business.TransferGift import com.pengrad.telegrambot.response.BaseResponse import com.pengrad.telegrambot.utility.kotlin.optionalRequestParameter import com.pengrad.telegrambot.utility.kotlin.requestParameter From 147189511292fe9d57c3fea1ec6fd286754b799e Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:31:16 +0200 Subject: [PATCH 31/34] Added the class PaidMessagePriceChanged and the field paid_message_price_changed to the class Message, describing a service message about a price change for paid messages sent to the chat. --- .../main/java/com/pengrad/telegrambot/model/Message.java | 9 ++++++++- .../pengrad/telegrambot/model/PaidMessagePriceChanged.kt | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 library/src/main/java/com/pengrad/telegrambot/model/PaidMessagePriceChanged.kt diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Message.java b/library/src/main/java/com/pengrad/telegrambot/model/Message.java index 52cfb960..0771e74b 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/Message.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/Message.java @@ -109,6 +109,7 @@ public class Message extends MaybeInaccessibleMessage implements Serializable { private WebAppData web_app_data; private GiftInfo gift; private UniqueGiftInfo unique_gift; + private PaidMessagePriceChanged paid_message_price_changed; public Integer messageThreadId() { return message_thread_id; @@ -447,6 +448,10 @@ public UniqueGiftInfo uniqueGift() { return unique_gift; } + public PaidMessagePriceChanged paidMessagePriceChanged() { + return paid_message_price_changed; + } + /** * Only for backwards-compatibility with MaybeInaccessibleMessage */ @@ -559,7 +564,8 @@ public boolean equals(Object o) { Objects.equals(reply_markup, message.reply_markup) && Objects.equals(web_app_data, message.web_app_data) && Objects.equals(gift, message.gift) && - Objects.equals(unique_gift, message.unique_gift); + Objects.equals(unique_gift, message.unique_gift) && + Objects.equals(paid_message_price_changed, message.paid_message_price_changed); } @Override @@ -657,6 +663,7 @@ public String toString() { ", web_app_data=" + web_app_data + ", gift=" + gift + ", unique_gift=" + unique_gift + + ", paid_message_price_changed=" + paid_message_price_changed + '}'; } } diff --git a/library/src/main/java/com/pengrad/telegrambot/model/PaidMessagePriceChanged.kt b/library/src/main/java/com/pengrad/telegrambot/model/PaidMessagePriceChanged.kt new file mode 100644 index 00000000..6547d2a9 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/PaidMessagePriceChanged.kt @@ -0,0 +1,5 @@ +package com.pengrad.telegrambot.model + +data class PaidMessagePriceChanged( + @get:JvmName("prizeStarCount") val prizeStarCount: Int +) \ No newline at end of file From ed570975989cbaa8b8f8e3f9293ef0c948b321d7 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:32:32 +0200 Subject: [PATCH 32/34] Added the field paid_star_count to the class Message, containing the number of Telegram Stars that were paid to send the message. --- .../main/java/com/pengrad/telegrambot/model/Message.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Message.java b/library/src/main/java/com/pengrad/telegrambot/model/Message.java index 0771e74b..fad61402 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/Message.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/Message.java @@ -110,6 +110,7 @@ public class Message extends MaybeInaccessibleMessage implements Serializable { private GiftInfo gift; private UniqueGiftInfo unique_gift; private PaidMessagePriceChanged paid_message_price_changed; + private Integer paid_star_count; public Integer messageThreadId() { return message_thread_id; @@ -452,6 +453,10 @@ public PaidMessagePriceChanged paidMessagePriceChanged() { return paid_message_price_changed; } + public Integer paidStarCount() { + return paid_star_count; + } + /** * Only for backwards-compatibility with MaybeInaccessibleMessage */ @@ -565,7 +570,8 @@ public boolean equals(Object o) { Objects.equals(web_app_data, message.web_app_data) && Objects.equals(gift, message.gift) && Objects.equals(unique_gift, message.unique_gift) && - Objects.equals(paid_message_price_changed, message.paid_message_price_changed); + Objects.equals(paid_message_price_changed, message.paid_message_price_changed) && + Objects.equals(paid_star_count, message.paid_star_count); } @Override @@ -664,6 +670,7 @@ public String toString() { ", gift=" + gift + ", unique_gift=" + unique_gift + ", paid_message_price_changed=" + paid_message_price_changed + + ", paid_star_count=" + paid_star_count + '}'; } } From 5f85dc7b7ac712c609e563248c66ac54ed03f348 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:34:38 +0200 Subject: [PATCH 33/34] Bump to 9.0.0 --- README.md | 6 +++--- README_RU.md | 6 +++--- gradle.properties | 2 +- pom.xml | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1d5fa680..69d96222 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![codecov](https://codecov.io/gh/pengrad/java-telegram-bot-api/branch/master/graph/badge.svg)](https://codecov.io/gh/pengrad/java-telegram-bot-api) Java library for interacting with [Telegram Bot API](https://core.telegram.org/bots/api) -- Full support of all Bot API 8.3 methods +- Full support of all Bot API 9.0 methods - Telegram [Passport](https://core.telegram.org/passport) and Decryption API - Bot [Payments](https://core.telegram.org/bots/payments) - [Gaming Platform](https://telegram.org/blog/games) @@ -13,14 +13,14 @@ Java library for interacting with [Telegram Bot API](https://core.telegram.org/b Gradle: ```groovy -implementation 'com.github.pengrad:java-telegram-bot-api:8.3.0' +implementation 'com.github.pengrad:java-telegram-bot-api:9.0.0' ``` Maven: ```xml com.github.pengrad java-telegram-bot-api - 8.3.0 + 9.0.0 ``` [JAR with all dependencies on release page](https://github.com/pengrad/java-telegram-bot-api/releases) diff --git a/README_RU.md b/README_RU.md index 44e4b684..fc83a4f6 100644 --- a/README_RU.md +++ b/README_RU.md @@ -4,7 +4,7 @@ [![codecov](https://codecov.io/gh/pengrad/java-telegram-bot-api/branch/master/graph/badge.svg)](https://codecov.io/gh/pengrad/java-telegram-bot-api) Java библиотека, созданная для работы с [Telegram Bot API](https://core.telegram.org/bots/api) -- Полная поддержка всех методов BOT API 8.3 +- Полная поддержка всех методов BOT API 9.0 - Поддержка Telegram [паспорта](https://core.telegram.org/passport) и дешифровки (Decryption API); - Поддержка [платежей](https://core.telegram.org/bots/payments); - [Игровая платформа](https://telegram.org/blog/games). @@ -13,14 +13,14 @@ Java библиотека, созданная для работы с [Telegram B Gradle: ```groovy -implementation 'com.github.pengrad:java-telegram-bot-api:8.3.0' +implementation 'com.github.pengrad:java-telegram-bot-api:9.0.0' ``` Maven: ```xml com.github.pengrad java-telegram-bot-api - 8.3.0 + 9.0.0 ``` Также JAR со всеми зависимостями можно найти [в релизах](https://github.com/pengrad/java-telegram-bot-api/releases). diff --git a/gradle.properties b/gradle.properties index 671b7093..eabaeda8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.github.pengrad -VERSION_NAME=8.3.0 +VERSION_NAME=9.0.0 POM_DESCRIPTION=Java API for Telegram Bot API POM_URL=https://github.com/pengrad/java-telegram-bot-api/ diff --git a/pom.xml b/pom.xml index dbb3742b..70627d4d 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 4.0.0 com.github.pengrad java-telegram-bot-api - 8.3.0 + 9.0.0 JavaTelegramBotApi Java API for Telegram Bot API https://github.com/pengrad/java-telegram-bot-api/ From 7b9cfd15289bec9b7aff7898aef49dcfb7031e12 Mon Sep 17 00:00:00 2001 From: Mirco Ianese Date: Wed, 11 Jun 2025 19:41:13 +0200 Subject: [PATCH 34/34] Fix wrong type --- .../pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt index a611b02a..77fe1ca5 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt +++ b/library/src/main/java/com/pengrad/telegrambot/model/gift/owned/OwnedGiftRegular.kt @@ -1,5 +1,6 @@ package com.pengrad.telegrambot.model.gift.owned +import com.pengrad.telegrambot.model.MessageEntity import com.pengrad.telegrambot.model.User import com.pengrad.telegrambot.model.gift.Gift @@ -10,7 +11,7 @@ class OwnedGiftRegular private constructor( @get:JvmName("senderUser") var senderUser: User?, @get:JvmName("sendDate") val sendDate: Long, @get:JvmName("text") var text: String?, - @get:JvmName("entities") var entities: Array?, + @get:JvmName("entities") var entities: Array?, @get:JvmName("isPrivate") var isPrivate: Boolean?, @get:JvmName("isSaved") var isSaved: Boolean?, @get:JvmName("canBeUpgraded") var canBeUpgraded: Boolean?, @@ -50,7 +51,7 @@ class OwnedGiftRegular private constructor( this.text = text } - fun entities(entities: Array) = apply { + fun entities(entities: Array) = apply { this.entities = entities }