diff --git a/CHANGELOG.md b/CHANGELOG.md index 021369df88..e29dd5a7be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ * `Core`: * Support of `logOut` method (`LogOut` object as a `Request`) * Support of `close` method (`Close` object as a `Request`) + * `SetWebhook` updates: + * Function `SetWebhook` with `inputFile` has changed this param nullability - `inputFile` now is nullable + * Function `SetWebhook` without `certificate` param now is unavailable. You can use `SetWebhook` with nullable + `inputFile` + * New field `ipAddress`. It works the same as `ip_address` in [setWebhook](https://core.telegram.org/bots/api#setwebhook) + section + * New field `dropPendingUpdates`. It works the same as `drop_pending_updates` in [setWebhook](https://core.telegram.org/bots/api#setwebhook) + section ## 0.29.4 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 5dc0f0841a..cc088fe8ca 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 @@ -16,14 +16,18 @@ private fun correctWebhookUrl(sourceUrl: String) = if (sourceUrl.contains("://") fun SetWebhook( url: String, certificate: MultipartFile, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ): MultipartRequestImpl, Boolean> = MultipartRequestImpl( SetWebhook( correctWebhookUrl(url), - null, + null as String?, + ipAddress, maxAllowedConnections, - allowedUpdates + allowedUpdates, + dropPendingUpdates ), mapOf(certificateField to certificate) ) @@ -31,47 +35,61 @@ fun SetWebhook( fun SetWebhook( url: String, certificate: FileId, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ): SetWebhook = SetWebhook( correctWebhookUrl(url), certificate.fileId, + ipAddress, maxAllowedConnections, - allowedUpdates + allowedUpdates, + dropPendingUpdates ) +/** + * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update + * for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. + * + * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url], + * e.g. https://www.example.com/. Since nobody else knows your bot's token, you can be pretty sure it's us. + */ @Suppress("USELESS_CAST") fun SetWebhook( url: String, - certificate: InputFile, + certificate: InputFile? = null, + ipAddress: String? = null, maxAllowedConnections: Int? = null, - allowedUpdates: List? = null + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null ): Request = when (certificate) { - is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, maxAllowedConnections, allowedUpdates) - is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, maxAllowedConnections, allowedUpdates) + is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) + is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) + null -> SetWebhook(correctWebhookUrl(url), null as String?, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates) } -fun SetWebhook( - url: String, - maxAllowedConnections: Int? = null, - allowedUpdates: List? = null -) = SetWebhook( - correctWebhookUrl(url), - null, - maxAllowedConnections, - allowedUpdates -) - +/** + * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update + * for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. + * + * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url], + * e.g. https://www.example.com/. Since nobody else knows your bot's token, you can be pretty sure it's us. + */ @Serializable data class SetWebhook internal constructor( @SerialName(urlField) val url: String, @SerialName(certificateField) val certificateFile: String? = null, + @SerialName(ipAddressField) + val ipAddress: String? = null, @SerialName(maxAllowedConnectionsField) val maxAllowedConnections: Int? = null, @SerialName(allowedUpdatesField) - val allowedUpdates: List? = null + val allowedUpdates: List? = null, + @SerialName(dropPendingUpdatesField) + val dropPendingUpdates: Boolean? = null ) : 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 0d3a71a24e..97e8e46d07 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 @@ -123,6 +123,7 @@ const val switchPmTextField = "switch_pm_text" const val switchPmParameterField = "switch_pm_parameter" const val maxAllowedConnectionsField = "max_connections" const val allowedUpdatesField = "allowed_updates" +const val dropPendingUpdatesField = "drop_pending_updates" const val hasCustomCertificateField = "has_custom_certificate" const val pendingUpdateCountField = "pending_update_count" const val lastErrorDateField = "last_error_date" @@ -143,6 +144,7 @@ const val inviteLinkField = "invite_link" const val pinnedMessageField = "pinned_message" const val customTitleField = "custom_title" const val optionIdsField = "option_ids" +const val ipAddressField = "ip_address" const val requestContactField = "request_contact" const val requestLocationField = "request_location"