1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +00:00

add support of SwitchInlineQueryChosenChatInlineKeyboardButton

This commit is contained in:
InsanusMokrassar 2023-04-21 21:42:40 +06:00
parent 61a6d4a880
commit 44e6d7adbc
6 changed files with 113 additions and 0 deletions

View File

@ -254,6 +254,10 @@ const val switchPmTextField = "switch_pm_text"
const val switchPmParameterField = "switch_pm_parameter"
const val maxAllowedConnectionsField = "max_connections"
const val allowedUpdatesField = "allowed_updates"
const val allowUserChatsField = "allow_user_chats"
const val allowBotChatsField = "allow_bot_chats"
const val allowGroupChatsField = "allow_group_chats"
const val allowChannelChatsField = "allow_channel_chats"
const val dropPendingUpdatesField = "drop_pending_updates"
const val secretTokenField = "secret_token"
const val hasCustomCertificateField = "has_custom_certificate"
@ -274,6 +278,7 @@ const val loginUrlField = "login_url"
const val forwardTextField = "forward_text"
const val botUsernameField = "bot_username"
const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat"
const val switchInlineQueryChosenChatField = "switch_inline_query_chosen_chat"
const val switchInlineQueryField = "switch_inline_query"
const val isAnimatedField = "is_animated"
const val isVideoField = "is_video"

View File

@ -98,6 +98,23 @@ data class SwitchInlineQueryCurrentChatInlineKeyboardButton(
val switchInlineQueryCurrentChat: String
) : InlineKeyboardButton
/**
* Complex button with [switchInlineQueryCurrentChat] which will be sent to you in an [dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery]
* which you may catch in [dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onBaseInlineQuery] and get
* from [dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery.query] (or changed by user query in case he will be
* the fastest hand in the wild west). Can be forwarded in any chat with message in case if it is the only one button in
* message, but will be converted to a [SwitchInlineQueryInlineKeyboardButton].
* Remember that clicking on this button will automatically insert username of this bot in current chat, paste
* [switchInlineQueryCurrentChat] as a query and create and inline request to your bot
* Visit https://core.telegram.org/bots/api#inlinekeyboardbutton for more info
*/
@Serializable
data class SwitchInlineQueryChosenChatInlineKeyboardButton(
override val text: String,
@SerialName(switchInlineQueryChosenChatField)
val parameters: SwitchInlineQueryChosenChat
) : InlineKeyboardButton
/**
* Complex button with [switchInlineQuery] which will be sent to you in an [dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery]
* which you may catch in [dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onBaseInlineQuery] and get

View File

@ -27,6 +27,7 @@ object InlineKeyboardButtonSerializer : KSerializer<InlineKeyboardButton> {
json[payField] != null -> PayInlineKeyboardButton.serializer()
json[switchInlineQueryField] != null -> SwitchInlineQueryInlineKeyboardButton.serializer()
json[switchInlineQueryCurrentChatField] != null -> SwitchInlineQueryCurrentChatInlineKeyboardButton.serializer()
json[switchInlineQueryChosenChatField] != null -> SwitchInlineQueryChosenChatInlineKeyboardButton.serializer()
json[urlField] != null -> URLInlineKeyboardButton.serializer()
else -> null
}
@ -47,6 +48,7 @@ object InlineKeyboardButtonSerializer : KSerializer<InlineKeyboardButton> {
is PayInlineKeyboardButton -> PayInlineKeyboardButton.serializer().serialize(encoder, value)
is SwitchInlineQueryInlineKeyboardButton -> SwitchInlineQueryInlineKeyboardButton.serializer().serialize(encoder, value)
is SwitchInlineQueryCurrentChatInlineKeyboardButton -> SwitchInlineQueryCurrentChatInlineKeyboardButton.serializer().serialize(encoder, value)
is SwitchInlineQueryChosenChatInlineKeyboardButton -> SwitchInlineQueryChosenChatInlineKeyboardButton.serializer().serialize(encoder, value)
is URLInlineKeyboardButton -> URLInlineKeyboardButton.serializer().serialize(encoder, value)
is WebAppInlineKeyboardButton -> WebAppInlineKeyboardButton.serializer().serialize(encoder, value)
is CallbackGameInlineKeyboardButton -> CallbackGameInlineKeyboardButton.serializer().serialize(encoder, value)

View File

@ -0,0 +1,19 @@
package dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons
import dev.inmo.tgbotapi.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class SwitchInlineQueryChosenChat(
@SerialName(queryField)
val query: String? = null,
@SerialName(allowUserChatsField)
val allowUsers: Boolean? = null,
@SerialName(allowBotChatsField)
val allowBots: Boolean? = null,
@SerialName(allowGroupChatsField)
val allowGroups: Boolean? = null,
@SerialName(allowChannelChatsField)
val allowChannels: Boolean? = null,
)

View File

@ -57,6 +57,41 @@ inline fun inlineQueryInCurrentChatInlineButton(
data: String
) = SwitchInlineQueryCurrentChatInlineKeyboardButton(text, data)
/**
* Creates and put [SwitchInlineQueryChosenChatInlineKeyboardButton]
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun inlineQueryInCurrentChatInlineButton(
text: String,
parameters: SwitchInlineQueryChosenChat
) = SwitchInlineQueryChosenChatInlineKeyboardButton(text, parameters)
/**
* Creates and put [SwitchInlineQueryChosenChatInlineKeyboardButton]
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun inlineQueryInCurrentChatInlineButton(
text: String,
query: String? = null,
allowUsers: Boolean? = null,
allowBots: Boolean? = null,
allowGroups: Boolean? = null,
allowChannels: Boolean? = null,
) = inlineQueryInCurrentChatInlineButton(
text,
SwitchInlineQueryChosenChat(
query = query,
allowUsers = allowUsers,
allowBots = allowBots,
allowGroups = allowGroups,
allowChannels = allowChannels
)
)
/**
* Creates and put [SwitchInlineQueryInlineKeyboardButton]
*

View File

@ -103,6 +103,41 @@ inline fun InlineKeyboardRowBuilder.inlineQueryInCurrentChatButton(
data: String
) = add(SwitchInlineQueryCurrentChatInlineKeyboardButton(text, data))
/**
* Creates and put [SwitchInlineQueryChosenChatInlineKeyboardButton]
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton(
text: String,
parameters: SwitchInlineQueryChosenChat
) = add(SwitchInlineQueryChosenChatInlineKeyboardButton(text, parameters))
/**
* Creates and put [SwitchInlineQueryChosenChatInlineKeyboardButton]
*
* @see inlineKeyboard
* @see InlineKeyboardBuilder.row
*/
inline fun InlineKeyboardRowBuilder.inlineQueryInChosenChatButton(
text: String,
query: String? = null,
allowUsers: Boolean? = null,
allowBots: Boolean? = null,
allowGroups: Boolean? = null,
allowChannels: Boolean? = null,
) = inlineQueryInChosenChatButton(
text,
SwitchInlineQueryChosenChat(
query = query,
allowUsers = allowUsers,
allowBots = allowBots,
allowGroups = allowGroups,
allowChannels = allowChannels
)
)
/**
* Creates and put [SwitchInlineQueryInlineKeyboardButton]
*