From 6d6c544aaf0704e3cb38668a61a46a48fa4757f6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 Nov 2020 22:17:17 +0600 Subject: [PATCH] logout and close --- CHANGELOG.md | 4 +++ .../dev/inmo/tgbotapi/requests/local/Close.kt | 25 +++++++++++++++++++ .../inmo/tgbotapi/requests/local/LogOut.kt | 21 ++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/LogOut.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 17580ecc8a..021369df88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.30.0 Bot API 5.0 +* `Core`: + * Support of `logOut` method (`LogOut` object as a `Request`) + * Support of `close` method (`Close` object as a `Request`) + ## 0.29.4 * `Core`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt new file mode 100644 index 0000000000..9e950998f0 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/Close.kt @@ -0,0 +1,25 @@ +package dev.inmo.tgbotapi.requests.local + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.Serializable +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.builtins.serializer + +/** + * Use this method to close the bot instance before moving it from one local server to another. You need to delete the + * webhook before calling this method to ensure that the bot isn't launched again after server restart. The method will + * return error 429 in the first 10 minutes after the bot is launched. + * + * @see io.ktor.client.features.ClientRequestException + */ +@Serializable +object Close : SimpleRequest { + override val requestSerializer: SerializationStrategy<*> + get() = LogOut.serializer() + + override fun method(): String = "close" + + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/LogOut.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/LogOut.kt new file mode 100644 index 0000000000..63eb15993b --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/local/LogOut.kt @@ -0,0 +1,21 @@ +package dev.inmo.tgbotapi.requests.local + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +/** + * Use this method to log out from the cloud Bot API server before launching the bot locally. You **must** log out the bot + * before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful + * call, you will not be able to log in again using the same token for 10 minutes + */ +@Serializable +object LogOut : SimpleRequest { + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "logOut" + + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() +}