mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-14 21:00:15 +00:00
fix of #577
This commit is contained in:
@@ -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)
|
||||
|
@@ -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"
|
||||
|
Reference in New Issue
Block a user