1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-12-15 10:45:45 +00:00

fix of #1019 and improve longPollingFlow

This commit is contained in:
2025-11-23 17:35:59 +06:00
parent 97dae295d6
commit 28b5fae760
6 changed files with 92 additions and 21 deletions

View File

@@ -10654,6 +10654,7 @@ public final class dev/inmo/tgbotapi/types/CommonKt {
public static final field yShiftField Ljava/lang/String;
public static final field yearField Ljava/lang/String;
public static final fun getAllowedConnectionsLength ()Lkotlin/ranges/IntRange;
public static final fun getAllowedConnectionsWithLocalServerLength ()Lkotlin/ranges/IntRange;
public static final fun getBasketballAndFootballDiceResultLimit ()Lkotlin/ranges/IntRange;
public static final fun getBotCommandDescriptionLimit ()Lkotlin/ranges/IntRange;
public static final fun getBotCommandLengthLimit ()Lkotlin/ranges/IntRange;

View File

@@ -1,9 +1,11 @@
package dev.inmo.tgbotapi.requests.webhook
import dev.inmo.kslog.common.w
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.send.media.base.DataRequest
import dev.inmo.tgbotapi.requests.send.media.base.MultipartRequestImpl
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
@@ -118,11 +120,22 @@ fun SetWebhook(
)
/**
* 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.
* Represents a request for setting a webhook in Telegram's Bot API. A webhook allows Telegram to send updates directly
* to the bot via an HTTPS POST request to the provided URL, enabling real-time interaction.
*
* 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/<token>. Since nobody else knows your bot's token, you can be pretty sure it's us.
* @constructor Creates a data class holding configuration options for the webhook.
*
* @property url The HTTPS URL to which updates will be posted. Must be valid and accessible.
* @property certificateFile An optional path to a public certificate file for webhook verification. Use only if a self-signed certificate is applied.
* @property ipAddress The fixed IP address for incoming webhook connections.
* @property maxAllowedConnections The maximum number of simultaneous HTTPS connections allowed to the webhook for
* delivering updates. You may use value outside of [allowedConnectionsLength], but be sure that it is in
* [allowedConnectionsWithLocalServerLength] and you are using local bot api url
* @property allowedUpdates A list of update types the bot will receive. Defaults to all update types.
* @property dropPendingUpdates If true, all pending updates will be dropped when the webhook is changed.
* @property secretToken An optional arbitrary secret key to ensure the webhook updates are coming from Telegram.
*
* @throws IllegalArgumentException if the provided maxAllowedConnections value is outside the permitted range (both [allowedConnectionsLength] and [allowedConnectionsWithLocalServerLength])
*/
@ConsistentCopyVisibility
@Serializable
@@ -150,8 +163,19 @@ data class SetWebhook internal constructor(
init {
maxAllowedConnections ?.let {
if (it !in allowedConnectionsLength) {
throw IllegalArgumentException("Allowed connection for webhook must be in $allowedConnectionsLength range (but passed $it)")
when {
it !in allowedConnectionsLength && it in allowedConnectionsWithLocalServerLength -> {
DefaultKTgBotAPIKSLog.w {
"""
Passed amount of allowed connections to server is $it and it exceeds default amount of
connections $allowedConnectionsLength, but can be used with local bot api server. Make sure
you are using local bot api url in your bot.
""".trimIndent()
}
}
it !in allowedConnectionsLength -> {
throw IllegalArgumentException("Allowed connection for webhook must be in $allowedConnectionsLength range (but passed $it)")
}
}
}
}

View File

@@ -64,6 +64,7 @@ val threadNameLength = 1 until 128
val chatDescriptionLength = 0 until 256
val inlineResultQueryIdLingth = 1 until 64
val allowedConnectionsLength = 1 .. 100
val allowedConnectionsWithLocalServerLength = 1 .. 100000
val invoiceTitleLimit = 1 until 32
val invoiceDescriptionLimit = 1 until 256