From 44e6d7adbc4c70b8717a7ad0b3ae8ee257636d3a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 21 Apr 2023 21:42:40 +0600 Subject: [PATCH] add support of SwitchInlineQueryChosenChatInlineKeyboardButton --- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 5 +++ .../InlineKeyboardButton.kt | 17 +++++++++ .../InlineKeyboardButtonSerializer.kt | 2 ++ .../SwitchInlineQueryChosenChat.kt | 19 ++++++++++ .../inline/InlineKeyboardButtonsShortcuts.kt | 35 +++++++++++++++++++ .../types/buttons/InlineKeyboardBuilder.kt | 35 +++++++++++++++++++ 6 files changed, 113 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/SwitchInlineQueryChosenChat.kt 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 f65b22b650..b64318597c 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 @@ -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" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt index 6c31cdccee..f5ff00faf2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt @@ -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 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt index 70005d12c7..99b3e06ea5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/InlineKeyboardButtonSerializer.kt @@ -27,6 +27,7 @@ object InlineKeyboardButtonSerializer : KSerializer { 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 { 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) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/SwitchInlineQueryChosenChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/SwitchInlineQueryChosenChat.kt new file mode 100644 index 0000000000..d5eec4dfca --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/InlineKeyboardButtons/SwitchInlineQueryChosenChat.kt @@ -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, +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt index 9f148a98fe..886dd9e650 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/inline/InlineKeyboardButtonsShortcuts.kt @@ -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] * diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt index 06e844e9e1..57625f1d0f 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/InlineKeyboardBuilder.kt @@ -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] *