mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-15 21:03:48 +00:00
add opportunity to manually set up delay for media groups webhooks
This commit is contained in:
parent
d67c80bc99
commit
9e73d0c461
@ -34,9 +34,10 @@ import java.util.concurrent.Executors
|
|||||||
fun Route.includeWebhookHandlingInRoute(
|
fun Route.includeWebhookHandlingInRoute(
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||||
|
mediaGroupsDebounceTimeMillis: Long = 1000L,
|
||||||
block: UpdateReceiver<Update>
|
block: UpdateReceiver<Update>
|
||||||
) {
|
) {
|
||||||
val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block)
|
val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block, mediaGroupsDebounceTimeMillis)
|
||||||
post {
|
post {
|
||||||
safely(
|
safely(
|
||||||
exceptionsHandler ?: {}
|
exceptionsHandler ?: {}
|
||||||
@ -56,10 +57,12 @@ fun Route.includeWebhookHandlingInRoute(
|
|||||||
fun Route.includeWebhookHandlingInRouteWithFlows(
|
fun Route.includeWebhookHandlingInRouteWithFlows(
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
||||||
|
mediaGroupsDebounceTimeMillis: Long = 1000L,
|
||||||
block: FlowsUpdatesFilter.() -> Unit
|
block: FlowsUpdatesFilter.() -> Unit
|
||||||
) = includeWebhookHandlingInRoute(
|
) = includeWebhookHandlingInRoute(
|
||||||
scope,
|
scope,
|
||||||
exceptionsHandler,
|
exceptionsHandler,
|
||||||
|
mediaGroupsDebounceTimeMillis,
|
||||||
flowsUpdatesFilter(block = block).asUpdateReceiver
|
flowsUpdatesFilter(block = block).asUpdateReceiver
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -83,6 +86,7 @@ fun startListenWebhooks(
|
|||||||
listenRoute: String? = null,
|
listenRoute: String? = null,
|
||||||
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||||
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||||
|
mediaGroupsDebounceTimeMillis: Long = 1000L,
|
||||||
block: UpdateReceiver<Update>
|
block: UpdateReceiver<Update>
|
||||||
): ApplicationEngine {
|
): ApplicationEngine {
|
||||||
val env = applicationEngineEnvironment {
|
val env = applicationEngineEnvironment {
|
||||||
@ -90,8 +94,8 @@ fun startListenWebhooks(
|
|||||||
module {
|
module {
|
||||||
routing {
|
routing {
|
||||||
listenRoute ?.also {
|
listenRoute ?.also {
|
||||||
createRouteFromPath(it).includeWebhookHandlingInRoute(scope, exceptionsHandler, block)
|
createRouteFromPath(it).includeWebhookHandlingInRoute(scope, exceptionsHandler, mediaGroupsDebounceTimeMillis, block)
|
||||||
} ?: includeWebhookHandlingInRoute(scope, exceptionsHandler, block)
|
} ?: includeWebhookHandlingInRoute(scope, exceptionsHandler, mediaGroupsDebounceTimeMillis, block)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
privateKeyConfig ?.let {
|
privateKeyConfig ?.let {
|
||||||
@ -137,10 +141,11 @@ suspend fun RequestsExecutor.setWebhookInfoAndStartListenWebhooks(
|
|||||||
listenRoute: String = "/",
|
listenRoute: String = "/",
|
||||||
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
privateKeyConfig: WebhookPrivateKeyConfig? = null,
|
||||||
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
|
||||||
|
mediaGroupsDebounceTimeMillis: Long = 1000L,
|
||||||
block: UpdateReceiver<Update>
|
block: UpdateReceiver<Update>
|
||||||
): ApplicationEngine = try {
|
): ApplicationEngine = try {
|
||||||
execute(setWebhookRequest)
|
execute(setWebhookRequest)
|
||||||
startListenWebhooks(listenPort, engineFactory, exceptionsHandler, listenHost, listenRoute, privateKeyConfig, scope, block)
|
startListenWebhooks(listenPort, engineFactory, exceptionsHandler, listenHost, listenRoute, privateKeyConfig, scope, mediaGroupsDebounceTimeMillis, block)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user