1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-14 21:00:15 +00:00
This commit is contained in:
2022-05-02 13:21:43 +06:00
parent 8e7f7a03c8
commit 8c9cd9df67
7 changed files with 32 additions and 9 deletions

View File

@@ -125,5 +125,6 @@ inline fun telegramBot(
inline fun telegramBot(
token: String,
apiUrl: String = telegramBotAPIDefaultUrl,
testServer: Boolean = false,
builder: KtorRequestsExecutorBuilder.() -> Unit = {}
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), builder)
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, testServer, apiUrl), builder)

View File

@@ -16,7 +16,8 @@ private inline val String.withoutLastSlash: String
class TelegramAPIUrlsKeeper(
token: String,
hostUrl: String = telegramBotAPIDefaultUrl
hostUrl: String = telegramBotAPIDefaultUrl,
urlsSuffixes: String = ""
) {
val webAppDataSecretKey by lazy {
token.hmacSha256("WebAppData")
@@ -25,10 +26,16 @@ class TelegramAPIUrlsKeeper(
val commonAPIUrl: String
val fileBaseUrl: String
constructor(token: String, testServer: Boolean, hostUrl: String = telegramBotAPIDefaultUrl) : this(
token,
hostUrl,
"/test".takeIf { testServer } ?: ""
)
init {
val correctedHost = hostUrl.withoutLastSlash
commonAPIUrl = "$correctedHost/bot$token"
fileBaseUrl = "$correctedHost/file/bot$token"
commonAPIUrl = "$correctedHost/bot$token$urlsSuffixes"
fileBaseUrl = "$correctedHost/file/bot$token$urlsSuffixes"
}
fun createFileLinkUrl(filePath: String) = "${fileBaseUrl}/$filePath"