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:
@@ -342,11 +342,14 @@ const val requestPollField = "request_poll"
|
|||||||
const val requestUserField = "request_user"
|
const val requestUserField = "request_user"
|
||||||
const val requestUsersField = "request_users"
|
const val requestUsersField = "request_users"
|
||||||
const val requestChatField = "request_chat"
|
const val requestChatField = "request_chat"
|
||||||
|
const val requestManagedBotField = "request_managed_bot"
|
||||||
const val requestIdField = "request_id"
|
const val requestIdField = "request_id"
|
||||||
const val requestTitleField = "request_title"
|
const val requestTitleField = "request_title"
|
||||||
const val requestUsernameField = "request_username"
|
const val requestUsernameField = "request_username"
|
||||||
const val requestPhotoField = "request_photo"
|
const val requestPhotoField = "request_photo"
|
||||||
const val requestNameField = "request_name"
|
const val requestNameField = "request_name"
|
||||||
|
const val suggestedNameField = "suggested_name"
|
||||||
|
const val suggestedUsernameField = "suggested_username"
|
||||||
const val maxQuantityField = "max_quantity"
|
const val maxQuantityField = "max_quantity"
|
||||||
const val prizeStarCountField = "prize_star_count"
|
const val prizeStarCountField = "prize_star_count"
|
||||||
|
|
||||||
|
|||||||
@@ -171,6 +171,18 @@ data class RequestChatKeyboardButton(
|
|||||||
override val style: KeyboardButtonStyle? = null
|
override val style: KeyboardButtonStyle? = null
|
||||||
) : KeyboardButton
|
) : 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
|
@RiskFeature
|
||||||
object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
|
object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
|
||||||
private val internalSerializer = JsonElement.serializer()
|
private val internalSerializer = JsonElement.serializer()
|
||||||
@@ -241,6 +253,15 @@ object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
|
|||||||
iconCustomEmojiIdData,
|
iconCustomEmojiIdData,
|
||||||
styleData
|
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 is JsonObject && asJson[textField] != null -> SimpleKeyboardButton(
|
||||||
asJson[textField]!!.jsonPrimitive.content,
|
asJson[textField]!!.jsonPrimitive.content,
|
||||||
iconCustomEmojiIdData,
|
iconCustomEmojiIdData,
|
||||||
@@ -270,6 +291,7 @@ object KeyboardButtonSerializer : KSerializer<KeyboardButton> {
|
|||||||
}
|
}
|
||||||
is RequestUserKeyboardButton -> RequestUserKeyboardButton.serializer().serialize(encoder, value)
|
is RequestUserKeyboardButton -> RequestUserKeyboardButton.serializer().serialize(encoder, value)
|
||||||
is RequestChatKeyboardButton -> RequestChatKeyboardButton.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))
|
is UnknownKeyboardButton -> JsonElement.serializer().serialize(encoder, nonstrictJsonFormat.parseToJsonElement(value.raw))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
)
|
||||||
|
|
||||||
@@ -300,7 +300,7 @@ fun requestChannelReplyButton(
|
|||||||
/**
|
/**
|
||||||
* Creates [RequestChatKeyboardButton] with [KeyboardButtonRequestChat.Group]
|
* Creates [RequestChatKeyboardButton] with [KeyboardButtonRequestChat.Group]
|
||||||
*/
|
*/
|
||||||
fun requestChannelReplyButton(
|
fun requestGroupReplyButton(
|
||||||
text: String,
|
text: String,
|
||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
isForum: Boolean? = null,
|
isForum: Boolean? = null,
|
||||||
@@ -331,3 +331,39 @@ fun requestChannelReplyButton(
|
|||||||
iconCustomEmojiId,
|
iconCustomEmojiId,
|
||||||
style
|
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
|
||||||
|
)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.utils.types.buttons
|
|||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.buttons.*
|
import dev.inmo.tgbotapi.types.buttons.*
|
||||||
import dev.inmo.tgbotapi.types.buttons.reply.requestChatReplyButton
|
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.requestUserReplyButton
|
||||||
import dev.inmo.tgbotapi.types.buttons.reply.requestUsersReplyButton
|
import dev.inmo.tgbotapi.types.buttons.reply.requestUsersReplyButton
|
||||||
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
import dev.inmo.tgbotapi.types.chat.member.ChatCommonAdministratorRights
|
||||||
@@ -467,3 +468,47 @@ fun ReplyKeyboardRowBuilder.requestGroupButton(
|
|||||||
iconCustomEmojiId,
|
iconCustomEmojiId,
|
||||||
style
|
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
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user