1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-10-27 02:02:40 +00:00

telegramBot improvements

This commit is contained in:
2020-11-06 12:07:46 +06:00
parent cf47cee36a
commit c89aa7b9ba
3 changed files with 26 additions and 8 deletions

View File

@@ -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)