From 1df653f42890890e22b92736bc31f758e70c1d01 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 21 Jun 2022 17:55:21 +0600 Subject: [PATCH] SetWebhook#secretToken --- CHANGELOG.md | 1 + .../extensions/api/webhook/SetWebhookInfo.kt | 15 ++++---- .../tgbotapi/requests/webhook/SetWebhook.kt | 35 ++++++++++++------- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 1 + 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b07993269b..0daed1b25d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Add support of functionality for `WebApp`s from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022) * Add support of functionality for premium feature from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022) * Add support of `addedToAttachmentMenu` in `CommonUser` from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022) +* Add support of `secret_token` in `SetWebhook` request from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022) ## 2.0.3 diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt index bf2730daae..a0e9dcb195 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/webhook/SetWebhookInfo.kt @@ -13,10 +13,11 @@ suspend fun TelegramBot.setWebhookInfo( ipAddress: String? = null, maxAllowedConnections: Int? = null, allowedUpdates: List? = null, - dropPendingUpdates: Boolean? = null + dropPendingUpdates: Boolean? = null, + secretToken: String? = null ) = execute( SetWebhook( - url, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates + url, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates, secretToken ) ) @@ -29,10 +30,11 @@ suspend fun TelegramBot.setWebhookInfo( ipAddress: String? = null, maxAllowedConnections: Int? = null, allowedUpdates: List? = null, - dropPendingUpdates: Boolean? = null + dropPendingUpdates: Boolean? = null, + secretToken: String? = null ) = execute( SetWebhook( - url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates + url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates, secretToken ) ) @@ -45,9 +47,10 @@ suspend fun TelegramBot.setWebhookInfo( ipAddress: String? = null, maxAllowedConnections: Int? = null, allowedUpdates: List? = null, - dropPendingUpdates: Boolean? = null + dropPendingUpdates: Boolean? = null, + secretToken: String? = null ) = execute( SetWebhook( - url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates + url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates, secretToken ) ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt index 087ec7723b..39482247c5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/webhook/SetWebhook.kt @@ -20,7 +20,8 @@ class MultipartSetWebhookRequest( ipAddress: String? = null, maxAllowedConnections: Int? = null, allowedUpdates: List? = null, - dropPendingUpdates: Boolean? = null + dropPendingUpdates: Boolean? = null, + secretToken: String? = null ) : SetWebhookRequest(), MultipartRequest by MultipartRequestImpl( SetWebhook( correctWebhookUrl(url), @@ -28,7 +29,8 @@ class MultipartSetWebhookRequest( ipAddress, maxAllowedConnections, allowedUpdates, - dropPendingUpdates + dropPendingUpdates, + secretToken ), mapOf(certificateField to certificate) ) @@ -39,14 +41,16 @@ fun SetWebhook( ipAddress: String? = null, maxAllowedConnections: Int? = null, allowedUpdates: List? = null, - dropPendingUpdates: Boolean? = null + dropPendingUpdates: Boolean? = null, + secretToken: String? = null ): MultipartSetWebhookRequest = MultipartSetWebhookRequest( correctWebhookUrl(url), certificate, ipAddress, maxAllowedConnections, allowedUpdates, - dropPendingUpdates + dropPendingUpdates, + secretToken ) fun SetWebhook( @@ -55,14 +59,16 @@ fun SetWebhook( ipAddress: String? = null, maxAllowedConnections: Int? = null, allowedUpdates: List? = null, - dropPendingUpdates: Boolean? = null + dropPendingUpdates: Boolean? = null, + secretToken: String? = null ): SetWebhook = SetWebhook( correctWebhookUrl(url), certificate.fileId, ipAddress, maxAllowedConnections, allowedUpdates, - dropPendingUpdates + dropPendingUpdates, + secretToken ) /** @@ -79,10 +85,11 @@ fun SetWebhook( ipAddress: String? = null, maxAllowedConnections: Int? = null, allowedUpdates: List? = null, - dropPendingUpdates: Boolean? = null + dropPendingUpdates: Boolean? = null, + secretToken: String? = null ) = when (certificate) { - is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) - is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) + is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates, secretToken) + is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates, secretToken) } /** @@ -98,14 +105,16 @@ fun SetWebhook( ipAddress: String? = null, maxAllowedConnections: Int? = null, allowedUpdates: List? = null, - dropPendingUpdates: Boolean? = null + dropPendingUpdates: Boolean? = null, + secretToken: String? = null ) = SetWebhook( correctWebhookUrl(url), null, ipAddress, maxAllowedConnections, allowedUpdates, - dropPendingUpdates + dropPendingUpdates, + secretToken ) /** @@ -128,7 +137,9 @@ data class SetWebhook internal constructor( @SerialName(allowedUpdatesField) val allowedUpdates: List? = null, @SerialName(dropPendingUpdatesField) - val dropPendingUpdates: Boolean? = null + val dropPendingUpdates: Boolean? = null, + @SerialName(secretTokenField) + val secretToken: String? = null ) : SetWebhookRequest(), DataRequest { override fun method(): String = "setWebhook" override val resultDeserializer: DeserializationStrategy 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 4d2b181554..33fa728067 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 @@ -158,6 +158,7 @@ const val switchPmParameterField = "switch_pm_parameter" const val maxAllowedConnectionsField = "max_connections" const val allowedUpdatesField = "allowed_updates" const val dropPendingUpdatesField = "drop_pending_updates" +const val secretTokenField = "secret_token" const val hasCustomCertificateField = "has_custom_certificate" const val pendingUpdateCountField = "pending_update_count" const val lastErrorDateField = "last_error_date"