mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-18 21:45:06 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eb1fb16117 | |||
| ee4cf7c626 | |||
| 74d8b31437 | |||
| f22d571484 | |||
| 9be5ebb036 | |||
| da4cd527ec | |||
| 4117288b21 | |||
| 458bdd3ee4 | |||
| d469a88791 | |||
| 514bc699dd | |||
| bec72b8cf8 | |||
| fb0014dffa | |||
| 2bbd2e0679 |
20
CHANGELOG.md
20
CHANGELOG.md
@@ -1,5 +1,25 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 28.0.3
|
||||||
|
|
||||||
|
* `Core`:
|
||||||
|
* Add passing of default engines in `HttpClient` constructors
|
||||||
|
|
||||||
|
## 28.0.2
|
||||||
|
|
||||||
|
* `Core`:
|
||||||
|
* [#1001](https://github.com/InsanusMokrassar/ktgbotapi/issues/1001) - `[Bug] Invalid detection of isCausedByCancellation()`
|
||||||
|
* [#1002](https://github.com/InsanusMokrassar/ktgbotapi/issues/1002) - `Unable to handle UnauthorizedException with buildBehaviourWithLongPolling`
|
||||||
|
|
||||||
|
## 28.0.1
|
||||||
|
|
||||||
|
* `Version`:
|
||||||
|
* `Kotlin`: `2.2.0` -> `2.2.10`
|
||||||
|
* `MicroUtils`: `0.26.2` -> `0.26.3`
|
||||||
|
* `Ktor`: `3.2.2` -> `3.2.3`
|
||||||
|
* `Core`:
|
||||||
|
* Let all `OptionallyMessageThreadRequest` inheritors to use `@EncodeDefault` annotation to fix default value passing
|
||||||
|
|
||||||
## 28.0.0
|
## 28.0.0
|
||||||
|
|
||||||
**THIS UPDATE CONTAINS BREAKING CHANGES**
|
**THIS UPDATE CONTAINS BREAKING CHANGES**
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != n
|
|||||||
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
||||||
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
||||||
validationTimeout = Duration.ofSeconds(0)
|
validationTimeout = Duration.ofSeconds(0)
|
||||||
publishingType = "USER_MANAGED"
|
publishingType = System.getenv('PUBLISHING_TYPE') != "" ? System.getenv('PUBLISHING_TYPE') : "USER_MANAGED"
|
||||||
}
|
}
|
||||||
|
|
||||||
publishAllProjectsProbablyBreakingProjectIsolation()
|
publishAllProjectsProbablyBreakingProjectIsolation()
|
||||||
|
|||||||
@@ -9,4 +9,4 @@ kotlin.incremental.js=true
|
|||||||
ksp.useKSP2=false
|
ksp.useKSP2=false
|
||||||
|
|
||||||
library_group=dev.inmo
|
library_group=dev.inmo
|
||||||
library_version=28.0.0
|
library_version=28.0.3
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
kotlin = "2.2.0"
|
kotlin = "2.2.10"
|
||||||
kotlin-serialization = "1.9.0"
|
kotlin-serialization = "1.9.0"
|
||||||
kotlin-coroutines = "1.10.2"
|
kotlin-coroutines = "1.10.2"
|
||||||
|
|
||||||
@@ -8,12 +8,12 @@ javax-activation = "1.1.1"
|
|||||||
|
|
||||||
korlibs = "5.4.0"
|
korlibs = "5.4.0"
|
||||||
uuid = "0.8.4"
|
uuid = "0.8.4"
|
||||||
ktor = "3.2.2"
|
ktor = "3.2.3"
|
||||||
|
|
||||||
ksp = "2.2.0-2.0.2"
|
ksp = "2.2.10-2.0.2"
|
||||||
kotlin-poet = "2.2.0"
|
kotlin-poet = "2.2.0"
|
||||||
|
|
||||||
microutils = "0.26.2"
|
microutils = "0.26.3"
|
||||||
kslog = "1.5.0"
|
kslog = "1.5.0"
|
||||||
|
|
||||||
versions = "0.52.0"
|
versions = "0.52.0"
|
||||||
@@ -22,7 +22,7 @@ github-release-plugin = "2.5.2"
|
|||||||
dokka = "2.0.0"
|
dokka = "2.0.0"
|
||||||
|
|
||||||
validator = "0.18.1"
|
validator = "0.18.1"
|
||||||
nmcp = "1.0.2"
|
nmcp = "1.1.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
|
|
||||||
@@ -37,6 +37,8 @@ kotlin-test-js = { module = "org.jetbrains.kotlin:kotlin-test-js", version.ref =
|
|||||||
|
|
||||||
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
|
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
|
||||||
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
|
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
|
||||||
|
ktor-client-java = { module = "io.ktor:ktor-client-java", version.ref = "ktor" }
|
||||||
|
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
|
||||||
ktor-client-curl = { module = "io.ktor:ktor-client-curl", version.ref = "ktor" }
|
ktor-client-curl = { module = "io.ktor:ktor-client-curl", version.ref = "ktor" }
|
||||||
ktor-client-winhttp = { module = "io.ktor:ktor-client-winhttp", version.ref = "ktor" }
|
ktor-client-winhttp = { module = "io.ktor:ktor-client-winhttp", version.ref = "ktor" }
|
||||||
ktor-server = { module = "io.ktor:ktor-server", version.ref = "ktor" }
|
ktor-server = { module = "io.ktor:ktor-server", version.ref = "ktor" }
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.api
|
|||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||||
|
import dev.inmo.tgbotapi.utils.defaultKtorEngine
|
||||||
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
|
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.HttpClientConfig
|
import io.ktor.client.HttpClientConfig
|
||||||
@@ -13,7 +14,7 @@ import io.ktor.client.engine.*
|
|||||||
*/
|
*/
|
||||||
public fun telegramBot(
|
public fun telegramBot(
|
||||||
urlsKeeper: TelegramAPIUrlsKeeper,
|
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
client: HttpClient = HttpClient()
|
client: HttpClient = HttpClient(defaultKtorEngine)
|
||||||
): TelegramBot = telegramBot(urlsKeeper) {
|
): TelegramBot = telegramBot(urlsKeeper) {
|
||||||
this.client = client
|
this.client = client
|
||||||
}
|
}
|
||||||
@@ -68,7 +69,7 @@ public fun telegramBot(
|
|||||||
apiUrl: String = telegramBotAPIDefaultUrl,
|
apiUrl: String = telegramBotAPIDefaultUrl,
|
||||||
testServer: Boolean = false,
|
testServer: Boolean = false,
|
||||||
fileLinkUrlMapper: TelegramAPIUrlsKeeper.(String) -> String = { "${fileBaseUrl}/$it" },
|
fileLinkUrlMapper: TelegramAPIUrlsKeeper.(String) -> String = { "${fileBaseUrl}/$it" },
|
||||||
client: HttpClient = HttpClient()
|
client: HttpClient = HttpClient(defaultKtorEngine)
|
||||||
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, testServer, apiUrl, fileLinkUrlMapper), client)
|
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, testServer, apiUrl, fileLinkUrlMapper), client)
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ suspend fun TelegramBot.buildBehaviourWithLongPolling(
|
|||||||
timeoutSeconds = timeoutSeconds,
|
timeoutSeconds = timeoutSeconds,
|
||||||
autoDisableWebhooks = autoDisableWebhooks,
|
autoDisableWebhooks = autoDisableWebhooks,
|
||||||
autoSkipTimeoutExceptions = autoSkipTimeoutExceptions,
|
autoSkipTimeoutExceptions = autoSkipTimeoutExceptions,
|
||||||
mediaGroupsDebounceTimeMillis = mediaGroupsDebounceTimeMillis
|
mediaGroupsDebounceTimeMillis = mediaGroupsDebounceTimeMillis,
|
||||||
|
exceptionsHandler = defaultExceptionsHandler
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30506,6 +30506,10 @@ public final class dev/inmo/tgbotapi/utils/DefaultKSLogKt {
|
|||||||
public static final fun setDefaultKTgBotAPIKSLogSystemTag (Ljava/lang/String;)V
|
public static final fun setDefaultKTgBotAPIKSLogSystemTag (Ljava/lang/String;)V
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final class dev/inmo/tgbotapi/utils/DefaultKtorEngine_jvmKt {
|
||||||
|
public static final fun getDefaultKtorEngine ()Lio/ktor/client/engine/HttpClientEngineFactory;
|
||||||
|
}
|
||||||
|
|
||||||
public final class dev/inmo/tgbotapi/utils/DeserializeWithUnknownKt {
|
public final class dev/inmo/tgbotapi/utils/DeserializeWithUnknownKt {
|
||||||
public static final fun deserializeEitherWithRaw (Lkotlinx/serialization/encoding/Decoder;Lkotlinx/serialization/KSerializer;)Ldev/inmo/micro_utils/common/Either;
|
public static final fun deserializeEitherWithRaw (Lkotlinx/serialization/encoding/Decoder;Lkotlinx/serialization/KSerializer;)Ldev/inmo/micro_utils/common/Either;
|
||||||
public static final fun deserializeWithRaw (Lkotlinx/serialization/encoding/Decoder;Lkotlinx/serialization/KSerializer;)Lkotlin/Pair;
|
public static final fun deserializeWithRaw (Lkotlinx/serialization/encoding/Decoder;Lkotlinx/serialization/KSerializer;)Lkotlin/Pair;
|
||||||
|
|||||||
@@ -47,12 +47,19 @@ kotlin {
|
|||||||
api libs.ktor.server.host.common
|
api libs.ktor.server.host.common
|
||||||
|
|
||||||
api libs.ktor.client.cio
|
api libs.ktor.client.cio
|
||||||
|
api libs.ktor.client.java
|
||||||
|
|
||||||
api libs.javax.activation
|
api libs.javax.activation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
linuxX64Main {
|
jsMain {
|
||||||
|
dependencies {
|
||||||
|
api libs.ktor.client.js
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
linuxMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
api libs.ktor.client.curl
|
api libs.ktor.client.curl
|
||||||
}
|
}
|
||||||
@@ -64,7 +71,7 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mingwX64Main {
|
mingwMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
api libs.ktor.client.winhttp
|
api libs.ktor.client.winhttp
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import dev.inmo.tgbotapi.bot.settings.limiters.RequestLimiter
|
|||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
||||||
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||||
|
import dev.inmo.tgbotapi.utils.defaultKtorEngine
|
||||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
@@ -37,7 +38,7 @@ expect class KtorRequestsExecutor internal constructor(
|
|||||||
|
|
||||||
fun KtorRequestsExecutor(
|
fun KtorRequestsExecutor(
|
||||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
client: HttpClient = HttpClient(),
|
client: HttpClient = HttpClient(defaultKtorEngine),
|
||||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
callsFactories: List<KtorCallFactory> = emptyList(),
|
||||||
excludeDefaultFactories: Boolean = false,
|
excludeDefaultFactories: Boolean = false,
|
||||||
requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter,
|
requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter,
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ fun createTelegramBotDefaultKtorCallRequestsFactories(logger: KSLog? = null) = l
|
|||||||
class KtorRequestsExecutorBuilder(
|
class KtorRequestsExecutorBuilder(
|
||||||
var telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
var telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
||||||
) {
|
) {
|
||||||
var client: HttpClient = HttpClient()
|
var client: HttpClient = HttpClient(defaultKtorEngine)
|
||||||
var callsFactories: List<KtorCallFactory> = emptyList()
|
var callsFactories: List<KtorCallFactory> = emptyList()
|
||||||
var excludeDefaultFactories: Boolean = false
|
var excludeDefaultFactories: Boolean = false
|
||||||
var requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter
|
var requestsLimiter: RequestLimiter = ExceptionsOnlyLimiter
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class DefaultKtorRequestsExecutor internal constructor(
|
|||||||
|
|
||||||
when (e) {
|
when (e) {
|
||||||
is ClientRequestException -> {
|
is ClientRequestException -> {
|
||||||
val exceptionResult = runCatching {
|
val exceptionResult = runCatchingLogging(logger = Log) {
|
||||||
val content = e.response.bodyAsText()
|
val content = e.response.bodyAsText()
|
||||||
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
|
val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content)
|
||||||
newRequestException(
|
newRequestException(
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ data class ForwardMessage(
|
|||||||
val toChatId: ChatIdentifier,
|
val toChatId: ChatIdentifier,
|
||||||
@SerialName(messageIdField)
|
@SerialName(messageIdField)
|
||||||
override val messageId: MessageId,
|
override val messageId: MessageId,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = toChatId.threadId,
|
override val threadId: MessageThreadId? = toChatId.threadId,
|
||||||
@SerialName(videoStartTimestampField)
|
@SerialName(videoStartTimestampField)
|
||||||
override val startTimestamp: Seconds? = null,
|
override val startTimestamp: Seconds? = null,
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ data class ForwardMessages (
|
|||||||
val fromChatId: ChatIdentifier,
|
val fromChatId: ChatIdentifier,
|
||||||
@SerialName(messageIdsField)
|
@SerialName(messageIdsField)
|
||||||
override val messageIds: List<MessageId>,
|
override val messageIds: List<MessageId>,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = toChatId.threadId,
|
override val threadId: MessageThreadId? = toChatId.threadId,
|
||||||
@SerialName(disableNotificationField)
|
@SerialName(disableNotificationField)
|
||||||
override val disableNotification: Boolean = false,
|
override val disableNotification: Boolean = false,
|
||||||
|
|||||||
@@ -160,7 +160,9 @@ data class CopyMessage internal constructor(
|
|||||||
private val rawEntities: List<RawMessageEntity>? = null,
|
private val rawEntities: List<RawMessageEntity>? = null,
|
||||||
@SerialName(showCaptionAboveMediaField)
|
@SerialName(showCaptionAboveMediaField)
|
||||||
override val showCaptionAboveMedia: Boolean = false,
|
override val showCaptionAboveMedia: Boolean = false,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = toChatId.threadId,
|
override val threadId: MessageThreadId? = toChatId.threadId,
|
||||||
@SerialName(videoStartTimestampField)
|
@SerialName(videoStartTimestampField)
|
||||||
override val startTimestamp: Seconds? = null,
|
override val startTimestamp: Seconds? = null,
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ data class CopyMessages (
|
|||||||
val fromChatId: ChatIdentifier,
|
val fromChatId: ChatIdentifier,
|
||||||
@SerialName(messageIdsField)
|
@SerialName(messageIdsField)
|
||||||
override val messageIds: List<MessageId>,
|
override val messageIds: List<MessageId>,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = toChatId.threadId,
|
override val threadId: MessageThreadId? = toChatId.threadId,
|
||||||
@SerialName(disableNotificationField)
|
@SerialName(disableNotificationField)
|
||||||
override val disableNotification: Boolean = false,
|
override val disableNotification: Boolean = false,
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ data class SendAction(
|
|||||||
override val chatId: ChatIdentifier,
|
override val chatId: ChatIdentifier,
|
||||||
@SerialName(actionField)
|
@SerialName(actionField)
|
||||||
val action: BotAction,
|
val action: BotAction,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ data class SendContact(
|
|||||||
val firstName: String,
|
val firstName: String,
|
||||||
@SerialName(lastNameField)
|
@SerialName(lastNameField)
|
||||||
val lastName: String? = null,
|
val lastName: String? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ data class SendDice(
|
|||||||
override val chatId: ChatIdentifier,
|
override val chatId: ChatIdentifier,
|
||||||
@SerialName(emojiField)
|
@SerialName(emojiField)
|
||||||
val animationType: DiceAnimationType? = null,
|
val animationType: DiceAnimationType? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -139,8 +139,8 @@ sealed interface SendLocation<T : LocationContent> : SendContentMessageRequest<C
|
|||||||
override val heading: Degrees? = null,
|
override val heading: Degrees? = null,
|
||||||
@SerialName(proximityAlertRadiusField)
|
@SerialName(proximityAlertRadiusField)
|
||||||
override val proximityAlertRadius: Meters? = null,
|
override val proximityAlertRadius: Meters? = null,
|
||||||
@SerialName(messageThreadIdField)
|
|
||||||
@OptIn(ExperimentalSerializationApi::class)
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
|
@SerialName(messageThreadIdField)
|
||||||
@EncodeDefault
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
|
|||||||
@@ -89,7 +89,9 @@ data class SendTextMessage internal constructor(
|
|||||||
override val parseMode: ParseMode? = null,
|
override val parseMode: ParseMode? = null,
|
||||||
@SerialName(entitiesField)
|
@SerialName(entitiesField)
|
||||||
private val rawEntities: List<RawMessageEntity>? = null,
|
private val rawEntities: List<RawMessageEntity>? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ data class SendVenue(
|
|||||||
val googlePlaceId: GooglePlaceId? = null,
|
val googlePlaceId: GooglePlaceId? = null,
|
||||||
@SerialName(googlePlaceTypeField)
|
@SerialName(googlePlaceTypeField)
|
||||||
val googlePlaceType: GooglePlaceType? = null,
|
val googlePlaceType: GooglePlaceType? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ data class SendGame (
|
|||||||
override val chatId: ChatIdentifier,
|
override val chatId: ChatIdentifier,
|
||||||
@SerialName(gameShortNameField)
|
@SerialName(gameShortNameField)
|
||||||
val gameShortName: String,
|
val gameShortName: String,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -160,7 +160,9 @@ data class SendAnimationData internal constructor(
|
|||||||
override val width: Int? = null,
|
override val width: Int? = null,
|
||||||
@SerialName(heightField)
|
@SerialName(heightField)
|
||||||
override val height: Int? = null,
|
override val height: Int? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -149,7 +149,9 @@ data class SendAudioData internal constructor(
|
|||||||
override val performer: String? = null,
|
override val performer: String? = null,
|
||||||
@SerialName(titleField)
|
@SerialName(titleField)
|
||||||
override val title: String? = null,
|
override val title: String? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -161,7 +161,9 @@ data class SendDocumentData internal constructor(
|
|||||||
override val parseMode: ParseMode? = null,
|
override val parseMode: ParseMode? = null,
|
||||||
@SerialName(captionEntitiesField)
|
@SerialName(captionEntitiesField)
|
||||||
private val rawEntities: List<RawMessageEntity>? = null,
|
private val rawEntities: List<RawMessageEntity>? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -191,7 +191,9 @@ data class SendMediaGroupData internal constructor(
|
|||||||
@SerialName(chatIdField)
|
@SerialName(chatIdField)
|
||||||
override val chatId: ChatIdentifier,
|
override val chatId: ChatIdentifier,
|
||||||
val media: List<MediaGroupMemberTelegramMedia> = emptyList(),
|
val media: List<MediaGroupMemberTelegramMedia> = emptyList(),
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -167,7 +167,9 @@ data class SendPaidMediaData internal constructor(
|
|||||||
val payload: PaidMediaPayload? = null,
|
val payload: PaidMediaPayload? = null,
|
||||||
@SerialName(showCaptionAboveMediaField)
|
@SerialName(showCaptionAboveMediaField)
|
||||||
override val showCaptionAboveMedia: Boolean = false,
|
override val showCaptionAboveMedia: Boolean = false,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -128,7 +128,9 @@ data class SendPhotoData internal constructor(
|
|||||||
override val showCaptionAboveMedia: Boolean = false,
|
override val showCaptionAboveMedia: Boolean = false,
|
||||||
@SerialName(hasSpoilerField)
|
@SerialName(hasSpoilerField)
|
||||||
override val spoilered: Boolean = false,
|
override val spoilered: Boolean = false,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ data class SendStickerByFileId internal constructor(
|
|||||||
override val chatId: ChatIdentifier,
|
override val chatId: ChatIdentifier,
|
||||||
@SerialName(stickerField)
|
@SerialName(stickerField)
|
||||||
val sticker: InputFile,
|
val sticker: InputFile,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -181,7 +181,9 @@ data class SendVideoData internal constructor(
|
|||||||
override val height: Int? = null,
|
override val height: Int? = null,
|
||||||
@SerialName(supportStreamingField)
|
@SerialName(supportStreamingField)
|
||||||
val supportStreaming: Boolean? = null,
|
val supportStreaming: Boolean? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -74,7 +74,9 @@ data class SendVideoNoteData internal constructor(
|
|||||||
override val duration: Long? = null,
|
override val duration: Long? = null,
|
||||||
@SerialName(lengthField)
|
@SerialName(lengthField)
|
||||||
override val width: Int? = null,
|
override val width: Int? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -126,7 +126,9 @@ data class SendVoiceData internal constructor(
|
|||||||
private val rawEntities: List<RawMessageEntity>? = null,
|
private val rawEntities: List<RawMessageEntity>? = null,
|
||||||
@SerialName(durationField)
|
@SerialName(durationField)
|
||||||
override val duration: Long? = null,
|
override val duration: Long? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
|||||||
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
||||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||||
import dev.inmo.tgbotapi.types.payments.abstracts.XTR
|
import dev.inmo.tgbotapi.types.payments.abstracts.XTR
|
||||||
|
import dev.inmo.tgbotapi.types.threadId
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
private val invoiceMessageSerializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
|
private val invoiceMessageSerializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
|
||||||
@@ -61,7 +62,9 @@ data class SendInvoice(
|
|||||||
override val shouldSendEmailToProvider: Boolean = false,
|
override val shouldSendEmailToProvider: Boolean = false,
|
||||||
@SerialName(priceDependOnShipAddressField)
|
@SerialName(priceDependOnShipAddressField)
|
||||||
override val priceDependOnShipAddress: Boolean = false,
|
override val priceDependOnShipAddress: Boolean = false,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(disableNotificationField)
|
@SerialName(disableNotificationField)
|
||||||
override val disableNotification: Boolean = false,
|
override val disableNotification: Boolean = false,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import dev.inmo.tgbotapi.types.polls.ExactScheduledCloseInfo
|
|||||||
import dev.inmo.tgbotapi.types.polls.InputPollOption
|
import dev.inmo.tgbotapi.types.polls.InputPollOption
|
||||||
import dev.inmo.tgbotapi.types.polls.ScheduledCloseInfo
|
import dev.inmo.tgbotapi.types.polls.ScheduledCloseInfo
|
||||||
import dev.inmo.tgbotapi.utils.extensions.makeSourceString
|
import dev.inmo.tgbotapi.utils.extensions.makeSourceString
|
||||||
|
import kotlinx.serialization.EncodeDefault
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.SerializationStrategy
|
import kotlinx.serialization.SerializationStrategy
|
||||||
@@ -46,7 +48,9 @@ class SendQuizPoll internal constructor(
|
|||||||
override val openPeriod: LongSeconds? = null,
|
override val openPeriod: LongSeconds? = null,
|
||||||
@SerialName(closeDateField)
|
@SerialName(closeDateField)
|
||||||
override val closeDate: LongSeconds? = null,
|
override val closeDate: LongSeconds? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import dev.inmo.tgbotapi.types.polls.ScheduledCloseInfo
|
|||||||
import dev.inmo.tgbotapi.utils.EntitiesBuilder
|
import dev.inmo.tgbotapi.utils.EntitiesBuilder
|
||||||
import dev.inmo.tgbotapi.utils.EntitiesBuilderBody
|
import dev.inmo.tgbotapi.utils.EntitiesBuilderBody
|
||||||
import dev.inmo.tgbotapi.utils.extensions.makeSourceString
|
import dev.inmo.tgbotapi.utils.extensions.makeSourceString
|
||||||
|
import kotlinx.serialization.EncodeDefault
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.SerializationStrategy
|
import kotlinx.serialization.SerializationStrategy
|
||||||
@@ -41,7 +43,9 @@ class SendRegularPoll private constructor(
|
|||||||
override val openPeriod: LongSeconds?= null,
|
override val openPeriod: LongSeconds?= null,
|
||||||
@SerialName(closeDateField)
|
@SerialName(closeDateField)
|
||||||
override val closeDate: LongSeconds? = null,
|
override val closeDate: LongSeconds? = null,
|
||||||
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@SerialName(messageThreadIdField)
|
@SerialName(messageThreadIdField)
|
||||||
|
@EncodeDefault
|
||||||
override val threadId: MessageThreadId? = chatId.threadId,
|
override val threadId: MessageThreadId? = chatId.threadId,
|
||||||
@SerialName(businessConnectionIdField)
|
@SerialName(businessConnectionIdField)
|
||||||
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
override val businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||||
|
|||||||
@@ -2,6 +2,17 @@ package dev.inmo.tgbotapi.utils
|
|||||||
|
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Traverses this throwable's cause chain to find a [CancellationException].
|
||||||
|
*
|
||||||
|
* It walks through `this` and its `cause`s until the first [CancellationException] is encountered,
|
||||||
|
* and returns that exception. If no [CancellationException] is found in the chain, returns `null`.
|
||||||
|
*
|
||||||
|
* This is useful when you need to distinguish cancellations from other failures while handling errors.
|
||||||
|
*
|
||||||
|
* @receiver the root [Throwable] to inspect
|
||||||
|
* @return the first [CancellationException] found in the cause chain, or `null` if none present
|
||||||
|
*/
|
||||||
fun Throwable.causedCancellationException(): CancellationException? {
|
fun Throwable.causedCancellationException(): CancellationException? {
|
||||||
var current = this
|
var current = this
|
||||||
while (current !is CancellationException) {
|
while (current !is CancellationException) {
|
||||||
@@ -15,4 +26,10 @@ fun Throwable.causedCancellationException(): CancellationException? {
|
|||||||
return current
|
return current
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Throwable.isCausedByCancellation(): Boolean = causedCancellationException() == null
|
/**
|
||||||
|
* Checks whether this throwable (or any of its causes) is a [CancellationException].
|
||||||
|
*
|
||||||
|
* @receiver the [Throwable] to inspect
|
||||||
|
* @return `true` if a [CancellationException] is found in the cause chain, `false` otherwise
|
||||||
|
*/
|
||||||
|
fun Throwable.isCausedByCancellation(): Boolean = causedCancellationException() != null
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
|
import io.ktor.client.engine.HttpClientEngineFactory
|
||||||
|
|
||||||
|
expect val defaultKtorEngine: HttpClientEngineFactory<*>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
|
import io.ktor.client.engine.HttpClientEngineFactory
|
||||||
|
import io.ktor.client.engine.js.Js
|
||||||
|
|
||||||
|
actual val defaultKtorEngine: HttpClientEngineFactory<*> by lazy {
|
||||||
|
Js
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
|
import io.ktor.client.engine.HttpClientEngineFactory
|
||||||
|
import io.ktor.client.engine.java.Java
|
||||||
|
|
||||||
|
actual val defaultKtorEngine: HttpClientEngineFactory<*> by lazy {
|
||||||
|
Java
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.bot.ktor.base
|
package dev.inmo.tgbotapi.bot.ktor.base
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.utils.defaultKtorEngine
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.engine.cio.*
|
import io.ktor.client.engine.cio.*
|
||||||
|
|
||||||
@@ -21,4 +22,8 @@ internal actual inline fun platformClientCopy(client: HttpClient): HttpClient =
|
|||||||
HttpClient(CIO) {
|
HttpClient(CIO) {
|
||||||
this.plusAssign(config)
|
this.plusAssign(config)
|
||||||
}
|
}
|
||||||
} ?: throw IllegalArgumentException("On LinuxX64 TelegramBotAPI currently support only Curl Ktor HttpClient engine")
|
} ?: HttpClient(
|
||||||
|
defaultKtorEngine
|
||||||
|
) {
|
||||||
|
install(client)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
|
import io.ktor.client.engine.HttpClientEngineFactory
|
||||||
|
import io.ktor.client.engine.curl.Curl
|
||||||
|
|
||||||
|
actual val defaultKtorEngine: HttpClientEngineFactory<*> by lazy {
|
||||||
|
Curl
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package dev.inmo.tgbotapi.bot.ktor.base
|
package dev.inmo.tgbotapi.bot.ktor.base
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.utils.defaultKtorEngine
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.engine.curl.*
|
import io.ktor.client.engine.curl.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,4 +23,8 @@ internal actual inline fun platformClientCopy(client: HttpClient): HttpClient =
|
|||||||
HttpClient(Curl) {
|
HttpClient(Curl) {
|
||||||
this.plusAssign(config)
|
this.plusAssign(config)
|
||||||
}
|
}
|
||||||
} ?: throw IllegalArgumentException("On LinuxX64 TelegramBotAPI currently support only Curl Ktor HttpClient engine")
|
} ?: HttpClient(
|
||||||
|
defaultKtorEngine
|
||||||
|
) {
|
||||||
|
install(client)
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
|
import io.ktor.client.engine.HttpClientEngineFactory
|
||||||
|
import io.ktor.client.engine.winhttp.WinHttp
|
||||||
|
|
||||||
|
actual val defaultKtorEngine: HttpClientEngineFactory<*> by lazy {
|
||||||
|
WinHttp
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.extensions.utils.extensions
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.types.files.PathedFile
|
import dev.inmo.tgbotapi.types.files.PathedFile
|
||||||
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||||
|
import dev.inmo.tgbotapi.utils.defaultKtorEngine
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.request.get
|
import io.ktor.client.request.get
|
||||||
import io.ktor.client.statement.readBytes
|
import io.ktor.client.statement.readBytes
|
||||||
@@ -19,5 +20,5 @@ suspend fun HttpClient.loadFile(
|
|||||||
|
|
||||||
suspend fun PathedFile.download(
|
suspend fun PathedFile.download(
|
||||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
client: HttpClient = HttpClient()
|
client: HttpClient = HttpClient(defaultKtorEngine)
|
||||||
) = client.loadFile(telegramAPIUrlsKeeper, this)
|
) = client.loadFile(telegramAPIUrlsKeeper, this)
|
||||||
|
|||||||
Reference in New Issue
Block a user