1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

now setWebhook supports setting up of path for listening

This commit is contained in:
InsanusMokrassar 2020-01-01 14:07:17 +06:00
parent 27aba72a5a
commit ef7e94ba68
2 changed files with 30 additions and 3 deletions

View File

@ -34,6 +34,8 @@
### 0.20.4 ### 0.20.4
* Now `setWebhook` supports setting up of path for listening
## 0.19.0 ImplicitReflection removing ## 0.19.0 ImplicitReflection removing
* Total rework of serialization for requests. Now all `SimpleRequest` children have: * Total rework of serialization for requests. Now all `SimpleRequest` children have:

View File

@ -23,7 +23,6 @@ import kotlinx.serialization.json.Json
import java.util.concurrent.Executors import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
/** /**
* Reverse proxy webhook. * Reverse proxy webhook.
* *
@ -36,6 +35,7 @@ import java.util.concurrent.TimeUnit
suspend fun RequestsExecutor.setWebhook( suspend fun RequestsExecutor.setWebhook(
url: String, url: String,
port: Int, port: Int,
listenAddress: String,
engineFactory: ApplicationEngineFactory<*, *>, engineFactory: ApplicationEngineFactory<*, *>,
certificate: InputFile? = null, certificate: InputFile? = null,
privateKeyConfig: WebhookPrivateKeyConfig? = null, privateKeyConfig: WebhookPrivateKeyConfig? = null,
@ -70,7 +70,7 @@ suspend fun RequestsExecutor.setWebhook(
module { module {
routing { routing {
post { post(listenAddress) {
val deserialized = call.receiveText() val deserialized = call.receiveText()
val update = Json.nonstrict.parse( val update = Json.nonstrict.parse(
RawUpdate.serializer(), RawUpdate.serializer(),
@ -136,6 +136,29 @@ suspend fun RequestsExecutor.setWebhook(
} }
} }
suspend fun RequestsExecutor.setWebhook(
url: String,
port: Int,
engineFactory: ApplicationEngineFactory<*, *>,
certificate: InputFile? = null,
privateKeyConfig: WebhookPrivateKeyConfig? = null,
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
allowedUpdates: List<String>? = null,
maxAllowedConnections: Int? = null,
block: UpdateReceiver<Update>
) = setWebhook(
url,
port,
"/",
engineFactory,
certificate,
privateKeyConfig,
scope,
allowedUpdates,
maxAllowedConnections,
block
)
suspend fun RequestsExecutor.setWebhook( suspend fun RequestsExecutor.setWebhook(
url: String, url: String,
port: Int, port: Int,
@ -144,10 +167,12 @@ suspend fun RequestsExecutor.setWebhook(
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()),
maxAllowedConnections: Int? = null maxAllowedConnections: Int? = null,
listenAddress: String = ""
): Job = setWebhook( ): Job = setWebhook(
url, url,
port, port,
listenAddress,
engineFactory, engineFactory,
certificate, certificate,
privateKeyConfig, privateKeyConfig,