1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 03:58:44 +00:00

Now setWebhook supports custom listen address even if certificate was not provided

This commit is contained in:
InsanusMokrassar 2020-01-01 14:43:32 +06:00
parent 62d474b7cc
commit 43b08e9319
2 changed files with 12 additions and 7 deletions

View File

@ -35,6 +35,7 @@
### 0.20.4 ### 0.20.4
* Now `setWebhook` supports setting up of path for listening * 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 ## 0.19.0 ImplicitReflection removing

View File

@ -28,7 +28,7 @@ import java.util.concurrent.TimeUnit
* *
* @param url URL of webhook WITHOUT including of [port] * @param url URL of webhook WITHOUT including of [port]
* @param port port which will be listen by bot * @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] * @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 * which will be used by telegram to send encrypted messages
* @param scope Scope which will be used for * @param scope Scope which will be used for
@ -37,7 +37,8 @@ suspend fun RequestsExecutor.setWebhook(
url: String, url: String,
port: Int, port: Int,
engineFactory: ApplicationEngineFactory<*, *>, engineFactory: ApplicationEngineFactory<*, *>,
listenAddress: String = "/", listenHost: String = "0.0.0.0",
listenRoute: String = "/",
certificate: InputFile? = null, certificate: InputFile? = null,
privateKeyConfig: WebhookPrivateKeyConfig? = null, privateKeyConfig: WebhookPrivateKeyConfig? = null,
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
@ -71,7 +72,7 @@ suspend fun RequestsExecutor.setWebhook(
module { module {
routing { routing {
post(listenAddress) { post(listenRoute) {
val deserialized = call.receiveText() val deserialized = call.receiveText()
val update = Json.nonstrict.parse( val update = Json.nonstrict.parse(
RawUpdate.serializer(), RawUpdate.serializer(),
@ -89,11 +90,11 @@ suspend fun RequestsExecutor.setWebhook(
privateKeyConfig::keyStorePassword, privateKeyConfig::keyStorePassword,
privateKeyConfig::aliasPassword privateKeyConfig::aliasPassword
) { ) {
host = "0.0.0.0" host = listenHost
this.port = port this.port = port
} }
} ?: connector { } ?: connector {
host = "localhost" host = listenHost
this.port = port this.port = port
} }
@ -151,6 +152,7 @@ suspend fun RequestsExecutor.setWebhook(
url, url,
port, port,
engineFactory, engineFactory,
certificate ?.let { "0.0.0.0" } ?: "localhost",
"/", "/",
certificate, certificate,
privateKeyConfig, privateKeyConfig,
@ -169,12 +171,14 @@ suspend fun RequestsExecutor.setWebhook(
privateKeyConfig: WebhookPrivateKeyConfig? = null, privateKeyConfig: WebhookPrivateKeyConfig? = null,
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
maxAllowedConnections: Int? = null, maxAllowedConnections: Int? = null,
listenAddress: String = "/" listenHost: String = certificate ?.let { "0.0.0.0" } ?: "localhost",
listenRoute: String = "/"
): Job = setWebhook( ): Job = setWebhook(
url, url,
port, port,
engineFactory, engineFactory,
listenAddress, listenHost,
listenRoute,
certificate, certificate,
privateKeyConfig, privateKeyConfig,
scope, scope,