From 43b08e93196e29445ffc1327ad1ca8642d3c75f3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 1 Jan 2020 14:43:32 +0600 Subject: [PATCH] Now setWebhook supports custom listen address even if certificate was not provided --- CHANGELOG.md | 1 + .../utils/extensions/Webhooks.kt | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ec8782ae0..350c2f1f7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ ### 0.20.4 * Now `setWebhook` supports setting up of path for listening +* Now `setWebhook` supports custom listen address even if certificate was not provided ## 0.19.0 ImplicitReflection removing diff --git a/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt b/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt index 6d985c0558..856cbaf3cc 100644 --- a/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt +++ b/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/Webhooks.kt @@ -28,7 +28,7 @@ import java.util.concurrent.TimeUnit * * @param url URL of webhook WITHOUT including of [port] * @param port port which will be listen by bot - * @param listenAddress address to listen by bot + * @param listenRoute address to listen by bot * @param certificate [com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile] or [com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId] * which will be used by telegram to send encrypted messages * @param scope Scope which will be used for @@ -37,7 +37,8 @@ suspend fun RequestsExecutor.setWebhook( url: String, port: Int, engineFactory: ApplicationEngineFactory<*, *>, - listenAddress: String = "/", + listenHost: String = "0.0.0.0", + listenRoute: String = "/", certificate: InputFile? = null, privateKeyConfig: WebhookPrivateKeyConfig? = null, scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), @@ -71,7 +72,7 @@ suspend fun RequestsExecutor.setWebhook( module { routing { - post(listenAddress) { + post(listenRoute) { val deserialized = call.receiveText() val update = Json.nonstrict.parse( RawUpdate.serializer(), @@ -89,11 +90,11 @@ suspend fun RequestsExecutor.setWebhook( privateKeyConfig::keyStorePassword, privateKeyConfig::aliasPassword ) { - host = "0.0.0.0" + host = listenHost this.port = port } } ?: connector { - host = "localhost" + host = listenHost this.port = port } @@ -151,6 +152,7 @@ suspend fun RequestsExecutor.setWebhook( url, port, engineFactory, + certificate ?.let { "0.0.0.0" } ?: "localhost", "/", certificate, privateKeyConfig, @@ -169,12 +171,14 @@ suspend fun RequestsExecutor.setWebhook( privateKeyConfig: WebhookPrivateKeyConfig? = null, scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), maxAllowedConnections: Int? = null, - listenAddress: String = "/" + listenHost: String = certificate ?.let { "0.0.0.0" } ?: "localhost", + listenRoute: String = "/" ): Job = setWebhook( url, port, engineFactory, - listenAddress, + listenHost, + listenRoute, certificate, privateKeyConfig, scope,