diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ca9c608de..e297c1d8be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ * Added webhooks functions and workaround for `Reverse Proxy` mode * Added new type of updates `MediaGroupUpdate`, which can be received only from filters * `UpdatesFilter` now use new type of updates for mediagroups +* Add `GetWebhookInfo` request and `WebhookInfo` type +* Replace updates types into separated place in types ## 0.11.0 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt index a4800f45c1..a491568b30 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt @@ -2,27 +2,30 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.ALL_UPDATES_LIST import com.github.insanusmokrassar.TelegramBotAPI.types.update.RawUpdate import kotlinx.serialization.* import kotlinx.serialization.internal.ArrayListSerializer -const val UPDATE_MESSAGE = "message" -const val UPDATE_EDITED_MESSAGE = "edited_message" -const val UPDATE_CHANNEL_POST = "channel_post" -const val UPDATE_EDITED_CHANNEL_POST = "edited_channel_post" -const val UPDATE_CHOSEN_INLINE_RESULT = "chosen_inline_result" -const val UPDATE_INLINE_QUERY = "inline_query" -const val UPDATE_CALLBACK_QUERY = "callback_query" -const val UPDATE_SHIPPING_QUERY = "shipping_query" -const val UPDATE_PRE_CHECKOUT_QUERY = "pre_checkout_query" -/* +@Deprecated("Replaced to other package", ReplaceWith("UPDATE_MESSAGE", "com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_MESSAGE")) +const val UPDATE_MESSAGE = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_MESSAGE +@Deprecated("Replaced to other package", ReplaceWith("UPDATE_EDITED_MESSAGE", "com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_EDITED_MESSAGE")) +const val UPDATE_EDITED_MESSAGE = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_EDITED_MESSAGE +@Deprecated("Replaced to other package", ReplaceWith("UPDATE_CHANNEL_POST", "com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_CHANNEL_POST")) +const val UPDATE_CHANNEL_POST = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_CHANNEL_POST +@Deprecated("Replaced to other package", ReplaceWith("UPDATE_EDITED_CHANNEL_POST", "com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_EDITED_CHANNEL_POST")) +const val UPDATE_EDITED_CHANNEL_POST = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_EDITED_CHANNEL_POST +@Deprecated("Replaced to other package", ReplaceWith("UPDATE_CHOSEN_INLINE_RESULT", "com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_CHOSEN_INLINE_RESULT")) +const val UPDATE_CHOSEN_INLINE_RESULT = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_CHOSEN_INLINE_RESULT +@Deprecated("Replaced to other package", ReplaceWith("UPDATE_INLINE_QUERY", "com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_INLINE_QUERY")) +const val UPDATE_INLINE_QUERY = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_INLINE_QUERY +@Deprecated("Replaced to other package", ReplaceWith("UPDATE_CALLBACK_QUERY", "com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_CALLBACK_QUERY")) +const val UPDATE_CALLBACK_QUERY = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_CALLBACK_QUERY +@Deprecated("Replaced to other package", ReplaceWith("UPDATE_SHIPPING_QUERY", "com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_SHIPPING_QUERY")) +const val UPDATE_SHIPPING_QUERY = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_SHIPPING_QUERY +@Deprecated("Replaced to other package", ReplaceWith("UPDATE_PRE_CHECKOUT_QUERY", "com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_PRE_CHECKOUT_QUERY")) +const val UPDATE_PRE_CHECKOUT_QUERY = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_PRE_CHECKOUT_QUERY - @Optional private val inline_query: RawInlineQuery? = null, - @Optional private val chosen_inline_result: Unit? = null, - @Optional private val callback_query: RawCallbackQuery? = null, - @Optional private val shipping_query: Unit? = null, - @Optional private val pre_checkout_query: Unit? = null - */ @Serializable data class GetUpdates( @Optional @@ -32,17 +35,7 @@ data class GetUpdates( @Optional val timeout: Int? = null, @Optional - val allowed_updates: List? = listOf( - UPDATE_MESSAGE, - UPDATE_EDITED_MESSAGE, - UPDATE_CHANNEL_POST, - UPDATE_EDITED_CHANNEL_POST, - UPDATE_CHOSEN_INLINE_RESULT, - UPDATE_INLINE_QUERY, - UPDATE_CALLBACK_QUERY, - UPDATE_SHIPPING_QUERY, - UPDATE_PRE_CHECKOUT_QUERY - ) + val allowed_updates: List? = ALL_UPDATES_LIST ): SimpleRequest> { override fun method(): String = "getUpdates" diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/GetWebhookInfo.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/GetWebhookInfo.kt new file mode 100644 index 0000000000..92d4c72462 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/GetWebhookInfo.kt @@ -0,0 +1,13 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.webhook + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.WebhookInfo +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable + +@Serializable +object GetWebhookInfo : SimpleRequest { + override fun method(): String = "getWebhookInfo" + + override fun resultSerializer(): KSerializer = WebhookInfo.serializer() +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/SetWebhook.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt similarity index 95% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/SetWebhook.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt index 11aed14b52..852018d5ca 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/SetWebhook.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt @@ -1,4 +1,4 @@ -package com.github.insanusmokrassar.TelegramBotAPI.requests +package com.github.insanusmokrassar.TelegramBotAPI.requests.webhook import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.* diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index 8f82575c3c..8aa06288d6 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -71,6 +71,10 @@ const val switchPmTextField = "switch_pm_text" const val switchPmParameterField = "switch_pm_parameter" const val maxAllowedConnectionsField = "max_connections" const val allowedUpdatesField = "allowed_updates" +const val hasCustomCertificateField = "has_custom_certificate" +const val pendingUpdateCountField = "pending_update_count" +const val lastErrorDateField = "last_error_date" +const val lastErrorMessageField = "last_error_message" const val photoUrlField = "photo_url" diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/UpdateTypes.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/UpdateTypes.kt new file mode 100644 index 0000000000..e5d477db3f --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/UpdateTypes.kt @@ -0,0 +1,23 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types + +const val UPDATE_MESSAGE = "message" +const val UPDATE_EDITED_MESSAGE = "edited_message" +const val UPDATE_CHANNEL_POST = "channel_post" +const val UPDATE_EDITED_CHANNEL_POST = "edited_channel_post" +const val UPDATE_CHOSEN_INLINE_RESULT = "chosen_inline_result" +const val UPDATE_INLINE_QUERY = "inline_query" +const val UPDATE_CALLBACK_QUERY = "callback_query" +const val UPDATE_SHIPPING_QUERY = "shipping_query" +const val UPDATE_PRE_CHECKOUT_QUERY = "pre_checkout_query" + +val ALL_UPDATES_LIST = listOf( + UPDATE_MESSAGE, + UPDATE_EDITED_MESSAGE, + UPDATE_CHANNEL_POST, + UPDATE_EDITED_CHANNEL_POST, + UPDATE_CHOSEN_INLINE_RESULT, + UPDATE_INLINE_QUERY, + UPDATE_CALLBACK_QUERY, + UPDATE_SHIPPING_QUERY, + UPDATE_PRE_CHECKOUT_QUERY +) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/WebhookInfo.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/WebhookInfo.kt new file mode 100644 index 0000000000..84fa832908 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/WebhookInfo.kt @@ -0,0 +1,32 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types + +import kotlinx.serialization.* + +@Serializable +data class WebhookInfo( + @SerialName(urlField) + val url: String, + @SerialName(pendingUpdateCountField) + val awaitDeliery: Int, + @SerialName(maxAllowedConnectionsField) + @Optional + val maxConnections: Int = 40, // default count according to documentation + @SerialName(hasCustomCertificateField) + @Optional + val customCertificate: Boolean = false, + @SerialName(allowedUpdatesField) + @Optional + val allowedUpdates: List = ALL_UPDATES_LIST, + @SerialName(lastErrorDateField) + @Optional + val lastErrorDate: TelegramDate? = null, + @SerialName(lastErrorMessageField) + @Optional + val lastErrorMessage: String? = null +) { + @Transient + val isNotUseWebhook: Boolean = url.isEmpty() + + @Transient + val hasError: Boolean = lastErrorMessage != null +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesFilter.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesFilter.kt index 17acee1bff..d008a3b971 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesFilter.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesFilter.kt @@ -1,6 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions -import com.github.insanusmokrassar.TelegramBotAPI.requests.* +import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate import com.github.insanusmokrassar.TelegramBotAPI.utils.toMediaGroupUpdate diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt index d32e13a163..7e54d4f084 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt @@ -1,8 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor -import com.github.insanusmokrassar.TelegramBotAPI.requests.* import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.InputFile +import com.github.insanusmokrassar.TelegramBotAPI.requests.webhook.SetWebhook import com.github.insanusmokrassar.TelegramBotAPI.types.MediaGroupIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage import com.github.insanusmokrassar.TelegramBotAPI.types.update.*