diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c8621af44..bc1f8e980d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,9 @@ * Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat` * New extensions `TelegramBot#unpinAllChatMessages` * Extensions `TelegramBot#promoteChatMember` got `isAnonymous` parameter + * All old api methods has been actualized to their analogs in `Core` + * All `telegramBot` with `token: String` got `apiUrl` parameter + * Factory `telegramBotWithCustomClientConfig` has been renamed to `telegramBot` ## 0.29.4 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt index f6876dbe8e..1e8770804d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/TelegramAPIUrlsKeeper.kt @@ -1,8 +1,10 @@ package dev.inmo.tgbotapi.utils +const val telegramBotAPIDefaultUrl = "https://api.telegram.org" + class TelegramAPIUrlsKeeper( token: String, - hostUrl: String = "https://api.telegram.org" + hostUrl: String = telegramBotAPIDefaultUrl ) { val commonAPIUrl = "$hostUrl/bot$token" val fileBaseUrl = "$hostUrl/file/bot$token" diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt index 18f9d0e72e..2300eeaba3 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.api import dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutor import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper +import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig import io.ktor.client.engine.HttpClientEngine @@ -46,24 +47,35 @@ fun telegramBotWithCustomClientConfig( * Allows to create bot using bot [token] */ fun telegramBot( - token: String -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token)) + token: String, + apiUrl: String = telegramBotAPIDefaultUrl +): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token, apiUrl)) /** * Allows to create bot using bot [token] and already prepared [client] */ fun telegramBot( token: String, - client: HttpClient -): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token), client) + client: HttpClient, + apiUrl: String = telegramBotAPIDefaultUrl +): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), client) /** * Allows to create bot using bot [token] and configure [HttpClient] using [clientConfig] */ -fun telegramBotWithCustomClientConfig( +fun telegramBot( token: String, + apiUrl: String = telegramBotAPIDefaultUrl, clientConfig: HttpClientConfig<*>.() -> Unit -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token), clientConfig) +): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token, apiUrl), clientConfig) + +@Suppress("NOTHING_TO_INLINE") +@Deprecated("Renamed", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot")) +inline fun telegramBotWithCustomClientConfig( + token: String, + apiUrl: String = telegramBotAPIDefaultUrl, + noinline clientConfig: HttpClientConfig<*>.() -> Unit +) = telegramBot(token, apiUrl, clientConfig) /** * Allows to create bot using bot [token] and specify [HttpClientEngine] by passing [clientEngine] param and optionally @@ -72,5 +84,6 @@ fun telegramBotWithCustomClientConfig( fun telegramBot( token: String, clientEngine: HttpClientEngine, + apiUrl: String = telegramBotAPIDefaultUrl, clientConfig: HttpClientConfig<*>.() -> Unit = {} -): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token), clientEngine, clientConfig) +): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token, apiUrl), clientEngine, clientConfig)