mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
telegramBot improvements
This commit is contained in:
parent
cf47cee36a
commit
c89aa7b9ba
@ -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
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user