From 656bb687392596f950d5e3a823bb40d4dc601f99 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 26 Jun 2021 01:48:41 +0600 Subject: [PATCH] add support of input_field_placeholder --- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 4 ++++ .../dev/inmo/tgbotapi/types/buttons/ReplyForce.kt | 12 +++++++++++- .../tgbotapi/types/buttons/ReplyKeyboardMarkup.kt | 12 +++++++++++- .../utils/types/buttons/ReplyKeyboardMarkup.kt | 2 ++ 4 files changed, 28 insertions(+), 2 deletions(-) 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 8d9f796715..8a9ba6d089 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 @@ -82,6 +82,8 @@ val membersLimit = 1 .. 99999 val suggestedTipAmountsLimit = 1 .. 4 +val inputFieldPlaceholderLimit = 1 .. 64 + const val botActionActualityTime: Seconds = 5 // Made as lazy for correct work in K/JS @@ -366,6 +368,8 @@ const val requireShippingAddressField = "need_shipping_address" const val shouldSendPhoneNumberToProviderField = "send_phone_number_to_provider" const val shouldSendEmailToProviderField = "send_email_to_provider" +const val inputFieldPlaceholderField = "input_field_placeholder" + const val priceDependOnShipAddressField = "is_flexible" const val documentField = "document" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyForce.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyForce.kt index ad6c101b45..bfa3ad377e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyForce.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyForce.kt @@ -1,10 +1,14 @@ package dev.inmo.tgbotapi.types.buttons +import dev.inmo.tgbotapi.types.inputFieldPlaceholderField +import dev.inmo.tgbotapi.types.inputFieldPlaceholderLimit import kotlinx.serialization.* @Serializable data class ReplyForce( - val selective: Boolean? = null + val selective: Boolean? = null, + @SerialName(inputFieldPlaceholderField) + val inputFieldPlaceholder: String? = null ) : KeyboardMarkup { @SerialName("force_reply") @Required @@ -15,6 +19,12 @@ data class ReplyForce( val ReplyForceNonSelective = ReplyForce(false) val ReplyForceDefault = ReplyForce() } + + init { + if (inputFieldPlaceholder != null && inputFieldPlaceholder.length !in inputFieldPlaceholderLimit) { + error("Field $inputFieldPlaceholderField length must be in $inputFieldPlaceholderLimit, but was ${inputFieldPlaceholder.length}") + } + } } @Deprecated("Renamed", ReplaceWith("ReplyForce", "dev.inmo.tgbotapi.types.buttons.ReplyForce")) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt index 70ff25aaf1..a88703b9ff 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/buttons/ReplyKeyboardMarkup.kt @@ -1,5 +1,7 @@ package dev.inmo.tgbotapi.types.buttons +import dev.inmo.tgbotapi.types.inputFieldPlaceholderField +import dev.inmo.tgbotapi.types.inputFieldPlaceholderLimit import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -10,5 +12,13 @@ data class ReplyKeyboardMarkup( val resizeKeyboard: Boolean? = null, @SerialName("one_time_keyboard") val oneTimeKeyboard: Boolean? = null, + @SerialName(inputFieldPlaceholderField) + val inputFieldPlaceholder: String? = null, val selective: Boolean? = null -) : KeyboardMarkup +) : KeyboardMarkup { + init { + if (inputFieldPlaceholder != null && inputFieldPlaceholder.length !in inputFieldPlaceholderLimit) { + error("Field $inputFieldPlaceholderField length must be in $inputFieldPlaceholderLimit, but was ${inputFieldPlaceholder.length}") + } + } +} diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt index 8029ee9a8d..2b8bc76fc6 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/types/buttons/ReplyKeyboardMarkup.kt @@ -8,10 +8,12 @@ fun ReplyKeyboardMarkup( vararg buttons: KeyboardButton, resizeKeyboard: Boolean? = null, oneTimeKeyboard: Boolean? = null, + inputFieldPlaceholder: String? = null, selective: Boolean? = null ): ReplyKeyboardMarkup = ReplyKeyboardMarkup( flatMatrix { buttons.forEach { +it } }, resizeKeyboard, oneTimeKeyboard, + inputFieldPlaceholder, selective )