From 7008f312dc12c9068500e2979afebd0760c787e9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 16 May 2020 20:43:09 +0600 Subject: [PATCH] fixes --- .../utils/updates/retrieving/Webhook.kt | 12 +++++------- .../requests/webhook/SetWebhook.kt | 16 +++++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/TelegramBotAPI-extensions-utils/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/Webhook.kt b/TelegramBotAPI-extensions-utils/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/Webhook.kt index 7fa6001286..08c4bffaa8 100644 --- a/TelegramBotAPI-extensions-utils/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/Webhook.kt +++ b/TelegramBotAPI-extensions-utils/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/updates/retrieving/Webhook.kt @@ -83,9 +83,7 @@ fun startListenWebhooks( module { routing { listenRoute ?.also { - route(it) { - includeWebhookHandlingInRoute(scope, exceptionsHandler, block) - } + createRouteFromPath(it).includeWebhookHandlingInRoute(scope, exceptionsHandler, block) } ?: includeWebhookHandlingInRoute(scope, exceptionsHandler, block) } } @@ -97,11 +95,11 @@ fun startListenWebhooks( privateKeyConfig::aliasPassword ) { host = listenHost - this.port = listenPort + port = listenPort } } ?: connector { host = listenHost - this.port = listenPort + port = listenPort } } @@ -117,7 +115,7 @@ internal suspend fun RequestsExecutor.internalSetWebhookInfoAndStartListenWebhoo setWebhookRequest: Request, exceptionsHandler: ExceptionHandler = {}, listenHost: String = "0.0.0.0", - listenRoute: String = "/", + listenRoute: String? = null, privateKeyConfig: WebhookPrivateKeyConfig? = null, scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), block: UpdateReceiver @@ -186,7 +184,7 @@ suspend fun RequestsExecutor.setWebhookInfoAndStartListenWebhooks( setWebhookRequest: MultipartRequestImpl, Boolean>, exceptionsHandler: ExceptionHandler = {}, listenHost: String = "0.0.0.0", - listenRoute: String = "/", + listenRoute: String? = null, privateKeyConfig: WebhookPrivateKeyConfig? = null, scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), block: UpdateReceiver diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt index 84fd651e22..703c6ac043 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/webhook/SetWebhook.kt @@ -7,6 +7,12 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer +private fun correctWebhookUrl(sourceUrl: String) = if (sourceUrl.contains("://")) { + sourceUrl +} else { + "https://$sourceUrl" +} + fun SetWebhook( url: String, certificate: MultipartFile, @@ -14,7 +20,7 @@ fun SetWebhook( allowedUpdates: List? = null ): MultipartRequestImpl, Boolean> = MultipartRequestImpl( SetWebhook( - url, + correctWebhookUrl(url), null, maxAllowedConnections, allowedUpdates @@ -28,7 +34,7 @@ fun SetWebhook( maxAllowedConnections: Int? = null, allowedUpdates: List? = null ): SetWebhook = SetWebhook( - url, + correctWebhookUrl(url), certificate.fileId, maxAllowedConnections, allowedUpdates @@ -40,8 +46,8 @@ fun SetWebhook( maxAllowedConnections: Int? = null, allowedUpdates: List? = null ): Request = when (certificate) { - is MultipartFile -> SetWebhook(url, certificate as MultipartFile, maxAllowedConnections, allowedUpdates) - is FileId -> SetWebhook(url, certificate as FileId, maxAllowedConnections, allowedUpdates) + is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, maxAllowedConnections, allowedUpdates) + is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, maxAllowedConnections, allowedUpdates) } fun SetWebhook( @@ -49,7 +55,7 @@ fun SetWebhook( maxAllowedConnections: Int? = null, allowedUpdates: List? = null ) = SetWebhook( - url, + correctWebhookUrl(url), null, maxAllowedConnections, allowedUpdates