From 179bb66183a2996890c850f6711bf9512883eb4f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 23:21:25 +0600 Subject: [PATCH] return SetWebhook without certificate --- CHANGELOG.md | 4 +-- .../tgbotapi/requests/webhook/SetWebhook.kt | 26 +++++++++++++++++-- .../inmo/tgbotapi/types/files/AudioFile.kt | 11 +++++--- .../inmo/tgbotapi/types/files/VideoFile.kt | 11 +++++--- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf21e246f2..e80f2f6b00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,6 @@ * 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) @@ -18,6 +15,7 @@ * New field `UnbanChatMember#onlyIfBanned` * New fields `ExtendedChannelChat#linkedGroupChatId` and `ExtendedSupergroupChat#linkedChannelChatId` * New fields `ExtendedSupergroupChat#location` + * New fields `AudioFile#fileName` and `VideoFile#fileName` ## 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 cc088fe8ca..9a2c5a3a0f 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 @@ -58,7 +58,7 @@ fun SetWebhook( @Suppress("USELESS_CAST") fun SetWebhook( url: String, - certificate: InputFile? = null, + certificate: InputFile, ipAddress: String? = null, maxAllowedConnections: Int? = null, allowedUpdates: List? = null, @@ -66,9 +66,31 @@ fun SetWebhook( ): Request = 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) - null -> SetWebhook(correctWebhookUrl(url), null as String?, ipAddress, maxAllowedConnections, 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, + ipAddress: String? = null, + maxAllowedConnections: Int? = null, + allowedUpdates: List? = null, + dropPendingUpdates: Boolean? = null +): Request = SetWebhook( + correctWebhookUrl(url), + null, + ipAddress, + maxAllowedConnections, + 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. diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt index af686eda9b..554b878069 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/AudioFile.kt @@ -2,8 +2,7 @@ package dev.inmo.tgbotapi.types.files import dev.inmo.tgbotapi.CommonAbstracts.Performerable import dev.inmo.tgbotapi.requests.abstracts.FileId -import dev.inmo.tgbotapi.types.FileUniqueId -import dev.inmo.tgbotapi.types.fileUniqueIdField +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.files.abstracts.* import dev.inmo.tgbotapi.utils.MimeType import kotlinx.serialization.SerialName @@ -15,14 +14,20 @@ data class AudioFile( override val fileId: FileId, @SerialName(fileUniqueIdField) override val fileUniqueId: FileUniqueId, + @SerialName(durationField) override val duration: Long? = null, + @SerialName(performerField) override val performer: String? = null, + @SerialName(titleField) override val title: String? = null, + @SerialName(fileNameField) + override val fileName: String? = null, @SerialName(mimeTypeField) override val mimeType: MimeType? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, + @SerialName(thumbField) override val thumb: PhotoSize? = null -) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, TitledMediaFile, Performerable +) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, TitledMediaFile, Performerable fun AudioFile.asVoiceFile() = VoiceFile(fileId, fileUniqueId, duration, mimeType, fileSize) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt index 5780caa07c..da28496110 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/VideoFile.kt @@ -1,11 +1,10 @@ package dev.inmo.tgbotapi.types.files import dev.inmo.tgbotapi.requests.abstracts.FileId -import dev.inmo.tgbotapi.types.FileUniqueId +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode -import dev.inmo.tgbotapi.types.fileUniqueIdField import dev.inmo.tgbotapi.types.files.abstracts.* import dev.inmo.tgbotapi.utils.MimeType import dev.inmo.tgbotapi.utils.toHtmlCaptions @@ -18,15 +17,21 @@ data class VideoFile( override val fileId: FileId, @SerialName(fileUniqueIdField) override val fileUniqueId: FileUniqueId, + @SerialName(widthField) override val width: Int, + @SerialName(heightField) override val height: Int, + @SerialName(durationField) override val duration: Long? = null, + @SerialName(thumbField) override val thumb: PhotoSize? = null, + @SerialName(fileNameField) + override val fileName: String? = null, @SerialName(mimeTypeField) override val mimeType: MimeType? = null, @SerialName(fileSizeField) override val fileSize: Long? = null -) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile +) : TelegramMediaFile, CustomNamedMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile @Suppress("NOTHING_TO_INLINE") inline fun VideoFile.toInputMediaVideo(