1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-01 23:45:25 +00:00
tgbotapi/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt

90 lines
2.9 KiB
Kotlin
Raw Normal View History

package dev.inmo.tgbotapi.extensions.api
2020-05-12 12:52:37 +00:00
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutor
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
2020-11-06 06:07:46 +00:00
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
2020-05-12 12:52:37 +00:00
import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.HttpClientEngine
/**
* Allows to create bot using bot [urlsKeeper] and already prepared [client]
*/
fun telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper,
2020-08-10 07:38:19 +00:00
client: HttpClient = HttpClient()
): TelegramBot = KtorRequestsExecutor(
2020-05-12 12:52:37 +00:00
urlsKeeper,
client
)
/**
* Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by passing [clientEngine] param and optionally
* configure [HttpClient] using [clientConfig]
*/
2020-05-15 13:14:09 +00:00
fun telegramBotWithCustomClientConfig(
2020-05-12 12:52:37 +00:00
urlsKeeper: TelegramAPIUrlsKeeper,
clientEngine: HttpClientEngine,
clientConfig: HttpClientConfig<*>.() -> Unit = {}
): TelegramBot = telegramBot(
2020-05-12 12:52:37 +00:00
urlsKeeper,
HttpClient(clientEngine, clientConfig)
)
/**
* Allows to create bot using bot [urlsKeeper] and optionally configure [HttpClient] using [clientConfig]
*/
2020-05-15 13:14:09 +00:00
fun telegramBotWithCustomClientConfig(
2020-05-12 12:52:37 +00:00
urlsKeeper: TelegramAPIUrlsKeeper,
clientConfig: HttpClientConfig<*>.() -> Unit = {}
): TelegramBot = telegramBot(
2020-05-12 12:52:37 +00:00
urlsKeeper,
HttpClient(clientConfig)
)
/**
* Allows to create bot using bot [token]
*/
fun telegramBot(
2020-11-06 06:07:46 +00:00
token: String,
apiUrl: String = telegramBotAPIDefaultUrl
): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token, apiUrl))
2020-05-12 12:52:37 +00:00
/**
* Allows to create bot using bot [token] and already prepared [client]
*/
fun telegramBot(
token: String,
2020-11-06 06:07:46 +00:00
client: HttpClient,
apiUrl: String = telegramBotAPIDefaultUrl
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), client)
2020-05-12 12:52:37 +00:00
/**
* Allows to create bot using bot [token] and configure [HttpClient] using [clientConfig]
*/
2020-11-06 06:07:46 +00:00
fun telegramBot(
2020-05-12 12:52:37 +00:00
token: String,
2020-11-06 06:07:46 +00:00
apiUrl: String = telegramBotAPIDefaultUrl,
2020-05-12 12:52:37 +00:00
clientConfig: HttpClientConfig<*>.() -> Unit
2020-11-06 06:07:46 +00:00
): 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)
2020-05-12 12:52:37 +00:00
/**
* Allows to create bot using bot [token] and specify [HttpClientEngine] by passing [clientEngine] param and optionally
* configure [HttpClient] using [clientConfig]
*/
fun telegramBot(
token: String,
clientEngine: HttpClientEngine,
2020-11-06 06:07:46 +00:00
apiUrl: String = telegramBotAPIDefaultUrl,
2020-05-12 12:52:37 +00:00
clientConfig: HttpClientConfig<*>.() -> Unit = {}
2020-11-06 06:07:46 +00:00
): TelegramBot = telegramBotWithCustomClientConfig(TelegramAPIUrlsKeeper(token, apiUrl), clientEngine, clientConfig)