1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2026-04-06 18:12:35 +00:00

add support of KeyboardButtonRequestManagedBot

This commit is contained in:
2026-04-05 21:28:10 +06:00
parent 661b846a74
commit e604b7a3bf
5 changed files with 129 additions and 1 deletions

View File

@@ -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"

View File

@@ -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<KeyboardButton> {
private val internalSerializer = JsonElement.serializer()
@@ -241,6 +253,15 @@ object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
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<KeyboardButton> {
}
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))
}
}

View File

@@ -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
)

View File

@@ -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
)

View File

@@ -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
)