diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 249eeed906..17afa8ccf8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -342,11 +342,14 @@ const val requestPollField = "request_poll" const val requestUserField = "request_user" const val requestUsersField = "request_users" const val requestChatField = "request_chat" +const val requestManagedBotField = "request_managed_bot" const val requestIdField = "request_id" const val requestTitleField = "request_title" const val requestUsernameField = "request_username" const val requestPhotoField = "request_photo" const val requestNameField = "request_name" +const val suggestedNameField = "suggested_name" +const val suggestedUsernameField = "suggested_username" const val maxQuantityField = "max_quantity" const val prizeStarCountField = "prize_star_count" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButton.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButton.kt index 7278f66c4a..9c21441abb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButton.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButton.kt @@ -171,6 +171,18 @@ data class RequestChatKeyboardButton( override val style: KeyboardButtonStyle? = null ) : KeyboardButton +@Serializable +data class RequestManagedBotKeyboardButton( + override val text: String, + @SerialName(requestManagedBotField) + val requestManagedBot: KeyboardButtonRequestManagedBot, + @SerialName(iconCustomEmojiIdField) + override val iconCustomEmojiId: CustomEmojiId? = null, + @SerialName(styleField) + override val style: KeyboardButtonStyle? = null + +) : KeyboardButton + @RiskFeature object KeyboardButtonSerializer : KSerializer { private val internalSerializer = JsonElement.serializer() @@ -241,6 +253,15 @@ object KeyboardButtonSerializer : KSerializer { iconCustomEmojiIdData, styleData ) + asJson is JsonObject && asJson[requestManagedBotField] != null -> RequestManagedBotKeyboardButton( + asJson[textField]!!.jsonPrimitive.content, + nonstrictJsonFormat.decodeFromJsonElement( + KeyboardButtonRequestManagedBot.serializer(), + asJson[requestManagedBotField] ?.jsonObject ?: buildJsonObject { } + ), + iconCustomEmojiIdData, + styleData + ) asJson is JsonObject && asJson[textField] != null -> SimpleKeyboardButton( asJson[textField]!!.jsonPrimitive.content, iconCustomEmojiIdData, @@ -270,6 +291,7 @@ object KeyboardButtonSerializer : KSerializer { } is RequestUserKeyboardButton -> RequestUserKeyboardButton.serializer().serialize(encoder, value) is RequestChatKeyboardButton -> RequestChatKeyboardButton.serializer().serialize(encoder, value) + is RequestManagedBotKeyboardButton -> RequestManagedBotKeyboardButton.serializer().serialize(encoder, value) is UnknownKeyboardButton -> JsonElement.serializer().serialize(encoder, nonstrictJsonFormat.parseToJsonElement(value.raw)) } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButtonRequestManagedBot.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButtonRequestManagedBot.kt new file mode 100644 index 0000000000..6a617c482f --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/KeyboardButtonRequestManagedBot.kt @@ -0,0 +1,22 @@ +package dev.inmo.tgbotapi.types.buttons + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.request.RequestId +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * @param requestId Signed 32-bit identifier of the request. Must be unique within the message + * @param suggestedName Suggested name for the bot + * @param suggestedUsername Suggested username for the bot + */ +@Serializable +data class KeyboardButtonRequestManagedBot( + @SerialName(requestIdField) + val requestId: RequestId, + @SerialName(suggestedNameField) + val suggestedName: String? = null, + @SerialName(suggestedUsernameField) + val suggestedUsername: Username? = null +) + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt index d4851c6a40..44b6b94b47 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/reply/ReplyKeyboardButtonsShortcuts.kt @@ -300,7 +300,7 @@ fun requestChannelReplyButton( /** * Creates [RequestChatKeyboardButton] with [KeyboardButtonRequestChat.Group] */ -fun requestChannelReplyButton( +fun requestGroupReplyButton( text: String, requestId: RequestId, isForum: Boolean? = null, @@ -331,3 +331,39 @@ fun requestChannelReplyButton( iconCustomEmojiId, style ) + +/** + * Creates [RequestManagedBotKeyboardButton] + */ +fun requestManagedBotReplyButton( + text: String, + requestManagedBot: KeyboardButtonRequestManagedBot, + iconCustomEmojiId: CustomEmojiId? = null, + style: KeyboardButtonStyle? = null +) = RequestManagedBotKeyboardButton( + text, + requestManagedBot, + iconCustomEmojiId, + style +) + +/** + * Creates [RequestManagedBotKeyboardButton] with [KeyboardButtonRequestManagedBot] + */ +fun requestManagedBotReplyButton( + text: String, + requestId: RequestId, + suggestedName: String? = null, + suggestedUsername: Username? = null, + iconCustomEmojiId: CustomEmojiId? = null, + style: KeyboardButtonStyle? = null +) = requestManagedBotReplyButton( + text, + KeyboardButtonRequestManagedBot( + requestId = requestId, + suggestedName = suggestedName, + suggestedUsername = suggestedUsername, + ), + iconCustomEmojiId, + style +) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt index a9a39d4cb8..4917dd64bb 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardBuilder.kt @@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.utils.types.buttons import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.* import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton +import dev.inmo.tgbotapi.types.buttons.reply.requestManagedBotReplyButton import dev.inmo.tgbotapi.types.buttons.reply.requestUserReplyButton import dev.inmo.tgbotapi.types.buttons.reply.requestUsersReplyButton import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights @@ -467,3 +468,47 @@ fun ReplyKeyboardRowBuilder.requestGroupButton( iconCustomEmojiId, style ) + +/** + * Creates and put [RequestManagedBotKeyboardButton] + * + * @see replyKeyboard + * @see ReplyKeyboardBuilder.row + */ +fun ReplyKeyboardRowBuilder.requestManagedBotButton( + text: String, + requestManagedBot: KeyboardButtonRequestManagedBot, + iconCustomEmojiId: CustomEmojiId? = null, + style: KeyboardButtonStyle? = null +) = add( + requestManagedBotReplyButton( + text, + requestManagedBot, + iconCustomEmojiId, + style + ) +) + +/** + * Creates and put [RequestManagedBotKeyboardButton] with [KeyboardButtonRequestManagedBot] + * + * @see replyKeyboard + * @see ReplyKeyboardBuilder.row + */ +fun ReplyKeyboardRowBuilder.requestManagedBotButton( + text: String, + requestId: RequestId, + suggestedName: String? = null, + suggestedUsername: Username? = null, + iconCustomEmojiId: CustomEmojiId? = null, + style: KeyboardButtonStyle? = null +) = requestManagedBotButton( + text, + KeyboardButtonRequestManagedBot( + requestId = requestId, + suggestedName = suggestedName, + suggestedUsername = suggestedUsername, + ), + iconCustomEmojiId, + style +)