2020-10-04 10:57:39 +00:00
|
|
|
package dev.inmo.tgbotapi.extensions.utils.updates.retrieving
|
2020-05-13 17:22:35 +00:00
|
|
|
|
2021-02-08 13:35:32 +00:00
|
|
|
import dev.inmo.micro_utils.coroutines.*
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.bot.RequestsExecutor
|
2021-01-09 16:10:38 +00:00
|
|
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
2022-09-18 19:39:23 +00:00
|
|
|
import dev.inmo.tgbotapi.bot.exceptions.*
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates
|
|
|
|
import dev.inmo.tgbotapi.requests.GetUpdates
|
2023-06-30 10:35:14 +00:00
|
|
|
import dev.inmo.tgbotapi.requests.GetUpdatesRaw
|
2022-12-31 09:13:50 +00:00
|
|
|
import dev.inmo.tgbotapi.requests.webhook.DeleteWebhook
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.types.*
|
2022-11-07 20:27:38 +00:00
|
|
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
|
|
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.types.update.*
|
2022-11-07 20:27:38 +00:00
|
|
|
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
2020-10-04 11:06:30 +00:00
|
|
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
|
|
|
import dev.inmo.tgbotapi.updateshandlers.*
|
2022-05-01 05:21:01 +00:00
|
|
|
import io.ktor.client.plugins.HttpRequestTimeoutException
|
2022-04-04 07:16:18 +00:00
|
|
|
import io.ktor.utils.io.CancellationException
|
2020-05-13 17:22:35 +00:00
|
|
|
import kotlinx.coroutines.*
|
2021-02-08 13:35:32 +00:00
|
|
|
import kotlinx.coroutines.flow.*
|
2020-05-13 17:22:35 +00:00
|
|
|
|
2023-03-01 05:55:17 +00:00
|
|
|
/**
|
|
|
|
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
|
2023-03-01 07:14:18 +00:00
|
|
|
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
|
|
|
|
* retrieved in different updates
|
2023-03-01 05:55:17 +00:00
|
|
|
*/
|
2021-06-27 19:00:20 +00:00
|
|
|
fun TelegramBot.longPollingFlow(
|
2020-05-13 17:22:35 +00:00
|
|
|
timeoutSeconds: Seconds = 30,
|
2020-05-14 07:11:46 +00:00
|
|
|
exceptionsHandler: (ExceptionHandler<Unit>)? = null,
|
2022-08-23 05:55:28 +00:00
|
|
|
allowedUpdates: List<String>? = ALL_UPDATES_LIST,
|
2023-02-06 07:28:38 +00:00
|
|
|
autoDisableWebhooks: Boolean = true,
|
2023-03-01 05:55:17 +00:00
|
|
|
autoSkipTimeoutExceptions: Boolean = true,
|
|
|
|
mediaGroupsDebounceTimeMillis: Long? = 1000L,
|
2021-06-27 19:00:20 +00:00
|
|
|
): Flow<Update> = channelFlow {
|
2022-12-31 09:13:50 +00:00
|
|
|
if (autoDisableWebhooks) {
|
|
|
|
runCatchingSafely {
|
|
|
|
execute(DeleteWebhook())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-06 07:28:38 +00:00
|
|
|
val contextSafelyExceptionHandler = coroutineContext[ContextSafelyExceptionHandlerKey]
|
|
|
|
val contextToWork = if (contextSafelyExceptionHandler == null || !autoSkipTimeoutExceptions) {
|
|
|
|
coroutineContext
|
|
|
|
} else {
|
|
|
|
coroutineContext + ContextSafelyExceptionHandler { e ->
|
|
|
|
if (e is HttpRequestTimeoutException || (e is CommonBotException && e.cause is HttpRequestTimeoutException)) {
|
|
|
|
return@ContextSafelyExceptionHandler
|
|
|
|
} else {
|
|
|
|
contextSafelyExceptionHandler.handler(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 17:22:35 +00:00
|
|
|
var lastUpdateIdentifier: UpdateIdentifier? = null
|
|
|
|
|
2023-03-01 05:55:17 +00:00
|
|
|
val updatesHandler: (suspend (List<Update>) -> Unit) = if (mediaGroupsDebounceTimeMillis != null) {
|
|
|
|
val scope = CoroutineScope(contextToWork)
|
|
|
|
val updatesReceiver = scope.updateHandlerWithMediaGroupsAdaptation(
|
2023-03-01 06:38:50 +00:00
|
|
|
{
|
|
|
|
withContext(contextToWork) {
|
|
|
|
send(it)
|
|
|
|
}
|
|
|
|
},
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis
|
|
|
|
);
|
|
|
|
{ originalUpdates: List<Update> ->
|
|
|
|
originalUpdates.forEach {
|
|
|
|
updatesReceiver(it)
|
2023-03-01 06:38:50 +00:00
|
|
|
lastUpdateIdentifier = maxOf(lastUpdateIdentifier ?: it.updateId, it.updateId)
|
2023-03-01 05:55:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
{ originalUpdates: List<Update> ->
|
|
|
|
val converted = originalUpdates.convertWithMediaGroupUpdates()
|
|
|
|
/**
|
|
|
|
* Dirty hack for cases when the media group was retrieved not fully:
|
|
|
|
*
|
|
|
|
* We are throw out the last media group and will reretrieve it again in the next get updates
|
|
|
|
* and it will guarantee that it is full
|
|
|
|
*/
|
|
|
|
val updates = if (
|
|
|
|
originalUpdates.size == getUpdatesLimit.last
|
|
|
|
&& ((converted.last() as? BaseSentMessageUpdate) ?.data as? CommonMessage<*>) ?.content is MediaGroupContent<*>
|
|
|
|
) {
|
|
|
|
converted - converted.last()
|
|
|
|
} else {
|
|
|
|
converted
|
|
|
|
}
|
|
|
|
|
|
|
|
safelyWithResult {
|
|
|
|
for (update in updates) {
|
|
|
|
send(update)
|
|
|
|
|
2023-06-30 10:35:14 +00:00
|
|
|
if (update.updateId > -1) {
|
|
|
|
lastUpdateIdentifier = update.updateId
|
|
|
|
}
|
2023-03-01 05:55:17 +00:00
|
|
|
}
|
|
|
|
}.onFailure {
|
|
|
|
cancel(it as? CancellationException ?: return@onFailure)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-06 07:28:38 +00:00
|
|
|
withContext(contextToWork) {
|
|
|
|
while (isActive) {
|
|
|
|
safely(
|
|
|
|
{ e ->
|
|
|
|
val isHttpRequestTimeoutException = e is HttpRequestTimeoutException || (e is CommonBotException && e.cause is HttpRequestTimeoutException)
|
|
|
|
if (isHttpRequestTimeoutException && autoSkipTimeoutExceptions) {
|
|
|
|
return@safely
|
|
|
|
}
|
|
|
|
exceptionsHandler ?.invoke(e)
|
|
|
|
if (e is RequestException) {
|
|
|
|
delay(1000L)
|
|
|
|
}
|
2020-05-13 17:22:35 +00:00
|
|
|
}
|
2023-02-06 07:28:38 +00:00
|
|
|
) {
|
2023-03-01 05:55:17 +00:00
|
|
|
execute(
|
2023-02-06 07:28:38 +00:00
|
|
|
GetUpdates(
|
|
|
|
offset = lastUpdateIdentifier?.plus(1),
|
|
|
|
timeout = timeoutSeconds,
|
|
|
|
allowed_updates = allowedUpdates
|
|
|
|
)
|
|
|
|
).let { originalUpdates ->
|
2023-03-01 05:55:17 +00:00
|
|
|
updatesHandler(originalUpdates)
|
2020-05-13 17:22:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-01 07:14:18 +00:00
|
|
|
/**
|
|
|
|
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
|
|
|
|
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
|
|
|
|
* retrieved in different updates
|
|
|
|
*/
|
2021-06-27 19:00:20 +00:00
|
|
|
fun TelegramBot.startGettingOfUpdatesByLongPolling(
|
|
|
|
timeoutSeconds: Seconds = 30,
|
|
|
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
|
|
|
exceptionsHandler: (ExceptionHandler<Unit>)? = null,
|
2022-08-23 05:55:28 +00:00
|
|
|
allowedUpdates: List<String>? = ALL_UPDATES_LIST,
|
2022-12-31 09:13:50 +00:00
|
|
|
autoDisableWebhooks: Boolean = true,
|
2023-02-06 07:28:38 +00:00
|
|
|
autoSkipTimeoutExceptions: Boolean = true,
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis: Long? = 1000L,
|
2021-06-27 19:00:20 +00:00
|
|
|
updatesReceiver: UpdateReceiver<Update>
|
2023-02-06 07:28:38 +00:00
|
|
|
): Job = longPollingFlow(
|
|
|
|
timeoutSeconds = timeoutSeconds,
|
|
|
|
exceptionsHandler = exceptionsHandler,
|
|
|
|
allowedUpdates = allowedUpdates,
|
|
|
|
autoDisableWebhooks = autoDisableWebhooks,
|
2023-03-01 05:55:17 +00:00
|
|
|
autoSkipTimeoutExceptions = autoSkipTimeoutExceptions,
|
|
|
|
mediaGroupsDebounceTimeMillis = mediaGroupsDebounceTimeMillis
|
2023-02-06 07:28:38 +00:00
|
|
|
).subscribeSafely(
|
2021-06-27 19:00:20 +00:00
|
|
|
scope,
|
|
|
|
exceptionsHandler ?: defaultSafelyExceptionHandler,
|
|
|
|
updatesReceiver
|
|
|
|
)
|
|
|
|
|
2021-02-08 13:35:32 +00:00
|
|
|
/**
|
2023-03-01 07:14:18 +00:00
|
|
|
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
|
|
|
|
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
|
|
|
|
* retrieved in different updates
|
|
|
|
*
|
2021-02-08 13:35:32 +00:00
|
|
|
* @return [kotlinx.coroutines.flow.Flow] which will emit updates to the collector while they will be accumulated. Works
|
2022-04-04 07:16:18 +00:00
|
|
|
* the same as [longPollingFlow], but it will cancel the flow after the first one [HttpRequestTimeoutException]
|
2021-02-08 13:35:32 +00:00
|
|
|
*/
|
|
|
|
fun TelegramBot.createAccumulatedUpdatesRetrieverFlow(
|
|
|
|
avoidInlineQueries: Boolean = false,
|
|
|
|
avoidCallbackQueries: Boolean = false,
|
|
|
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
2022-12-31 09:13:50 +00:00
|
|
|
allowedUpdates: List<String>? = ALL_UPDATES_LIST,
|
2023-03-01 05:55:17 +00:00
|
|
|
autoDisableWebhooks: Boolean = true,
|
|
|
|
mediaGroupsDebounceTimeMillis: Long? = 1000L,
|
2022-04-04 07:16:18 +00:00
|
|
|
): Flow<Update> = longPollingFlow(
|
|
|
|
timeoutSeconds = 0,
|
|
|
|
exceptionsHandler = {
|
2022-09-18 19:39:23 +00:00
|
|
|
when {
|
|
|
|
it is HttpRequestTimeoutException ||
|
|
|
|
(it is CommonBotException && it.cause is HttpRequestTimeoutException) -> throw CancellationException("Cancel due to absence of new updates")
|
|
|
|
else -> exceptionsHandler ?.invoke(it)
|
2022-04-04 07:16:18 +00:00
|
|
|
}
|
|
|
|
},
|
2022-12-31 09:13:50 +00:00
|
|
|
allowedUpdates = allowedUpdates,
|
2023-02-06 07:28:38 +00:00
|
|
|
autoDisableWebhooks = autoDisableWebhooks,
|
2023-03-01 05:55:17 +00:00
|
|
|
autoSkipTimeoutExceptions = false,
|
|
|
|
mediaGroupsDebounceTimeMillis = mediaGroupsDebounceTimeMillis
|
2022-04-04 07:16:18 +00:00
|
|
|
).filter {
|
|
|
|
!(it is InlineQueryUpdate && avoidInlineQueries || it is CallbackQueryUpdate && avoidCallbackQueries)
|
|
|
|
}
|
|
|
|
|
2023-03-01 07:14:18 +00:00
|
|
|
/**
|
|
|
|
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
|
|
|
|
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
|
|
|
|
* retrieved in different updates
|
|
|
|
*/
|
2022-04-04 07:16:18 +00:00
|
|
|
fun TelegramBot.retrieveAccumulatedUpdates(
|
|
|
|
avoidInlineQueries: Boolean = false,
|
|
|
|
avoidCallbackQueries: Boolean = false,
|
|
|
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
|
|
|
exceptionsHandler: (ExceptionHandler<Unit>)? = null,
|
2022-08-23 05:55:28 +00:00
|
|
|
allowedUpdates: List<String>? = ALL_UPDATES_LIST,
|
2022-12-31 09:13:50 +00:00
|
|
|
autoDisableWebhooks: Boolean = true,
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis: Long? = 1000L,
|
2022-04-04 07:16:18 +00:00
|
|
|
updatesReceiver: UpdateReceiver<Update>
|
|
|
|
): Job = createAccumulatedUpdatesRetrieverFlow(
|
|
|
|
avoidInlineQueries,
|
|
|
|
avoidCallbackQueries,
|
|
|
|
exceptionsHandler,
|
2022-12-31 09:13:50 +00:00
|
|
|
allowedUpdates,
|
2023-03-01 05:55:17 +00:00
|
|
|
autoDisableWebhooks,
|
|
|
|
mediaGroupsDebounceTimeMillis
|
2022-04-04 07:16:18 +00:00
|
|
|
).subscribeSafelyWithoutExceptions(
|
|
|
|
scope.LinkedSupervisorScope()
|
|
|
|
) {
|
|
|
|
updatesReceiver(it)
|
2021-02-08 13:35:32 +00:00
|
|
|
}
|
|
|
|
|
2023-03-01 07:14:18 +00:00
|
|
|
/**
|
|
|
|
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
|
|
|
|
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
|
|
|
|
* retrieved in different updates
|
|
|
|
*/
|
2021-02-08 13:35:32 +00:00
|
|
|
fun TelegramBot.retrieveAccumulatedUpdates(
|
|
|
|
flowsUpdatesFilter: FlowsUpdatesFilter,
|
|
|
|
avoidInlineQueries: Boolean = false,
|
|
|
|
avoidCallbackQueries: Boolean = false,
|
|
|
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
2022-12-31 09:13:50 +00:00
|
|
|
autoDisableWebhooks: Boolean = true,
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis: Long? = 1000L,
|
2021-02-08 13:35:32 +00:00
|
|
|
exceptionsHandler: ExceptionHandler<Unit>? = null
|
2022-04-04 07:16:18 +00:00
|
|
|
) = retrieveAccumulatedUpdates(
|
|
|
|
avoidInlineQueries,
|
|
|
|
avoidCallbackQueries,
|
|
|
|
scope,
|
|
|
|
exceptionsHandler,
|
|
|
|
flowsUpdatesFilter.allowedUpdates,
|
2022-12-31 09:13:50 +00:00
|
|
|
autoDisableWebhooks,
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis,
|
2022-04-04 07:16:18 +00:00
|
|
|
flowsUpdatesFilter.asUpdateReceiver
|
|
|
|
)
|
|
|
|
|
2023-03-01 07:14:18 +00:00
|
|
|
/**
|
|
|
|
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
|
|
|
|
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
|
|
|
|
* retrieved in different updates
|
|
|
|
*/
|
2022-04-04 07:16:18 +00:00
|
|
|
suspend fun TelegramBot.flushAccumulatedUpdates(
|
|
|
|
avoidInlineQueries: Boolean = false,
|
|
|
|
avoidCallbackQueries: Boolean = false,
|
|
|
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
2022-08-23 05:55:28 +00:00
|
|
|
allowedUpdates: List<String>? = ALL_UPDATES_LIST,
|
2022-04-04 07:16:18 +00:00
|
|
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
2022-12-31 09:13:50 +00:00
|
|
|
autoDisableWebhooks: Boolean = true,
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis: Long? = 1000L,
|
2022-04-04 07:16:18 +00:00
|
|
|
updatesReceiver: UpdateReceiver<Update> = {}
|
|
|
|
) = retrieveAccumulatedUpdates(
|
|
|
|
avoidInlineQueries,
|
|
|
|
avoidCallbackQueries,
|
|
|
|
scope,
|
|
|
|
exceptionsHandler,
|
|
|
|
allowedUpdates,
|
2022-12-31 09:13:50 +00:00
|
|
|
autoDisableWebhooks,
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis,
|
2022-04-04 07:16:18 +00:00
|
|
|
updatesReceiver
|
|
|
|
).join()
|
2021-02-08 13:35:32 +00:00
|
|
|
|
2021-01-09 16:10:38 +00:00
|
|
|
/**
|
2023-03-01 07:14:18 +00:00
|
|
|
* Will [startGettingOfUpdatesByLongPolling] using incoming [updatesFilter]. It is assumed that you ALREADY CONFIGURE
|
2021-01-09 16:10:38 +00:00
|
|
|
* all updates receivers, because this method will trigger getting of updates and.
|
2023-03-01 07:14:18 +00:00
|
|
|
*
|
|
|
|
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
|
|
|
|
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
|
|
|
|
* retrieved in different updates
|
2021-01-09 16:10:38 +00:00
|
|
|
*/
|
|
|
|
fun TelegramBot.longPolling(
|
2022-05-22 16:36:56 +00:00
|
|
|
updatesFilter: UpdatesFilter,
|
2021-01-09 16:10:38 +00:00
|
|
|
timeoutSeconds: Seconds = 30,
|
|
|
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
2022-12-31 09:13:50 +00:00
|
|
|
autoDisableWebhooks: Boolean = true,
|
2023-02-06 07:28:38 +00:00
|
|
|
autoSkipTimeoutExceptions: Boolean = true,
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis: Long? = 1000L,
|
2021-01-09 16:10:38 +00:00
|
|
|
exceptionsHandler: ExceptionHandler<Unit>? = null
|
2022-05-22 16:36:56 +00:00
|
|
|
): Job = updatesFilter.run {
|
2023-02-06 07:28:38 +00:00
|
|
|
startGettingOfUpdatesByLongPolling(
|
|
|
|
timeoutSeconds = timeoutSeconds,
|
|
|
|
scope = scope,
|
|
|
|
exceptionsHandler = exceptionsHandler,
|
|
|
|
allowedUpdates = allowedUpdates,
|
|
|
|
autoDisableWebhooks = autoDisableWebhooks,
|
|
|
|
autoSkipTimeoutExceptions = autoSkipTimeoutExceptions,
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis = mediaGroupsDebounceTimeMillis,
|
2023-02-06 07:28:38 +00:00
|
|
|
updatesReceiver = asUpdateReceiver
|
|
|
|
)
|
2021-01-09 16:10:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will enable [longPolling] by creating [FlowsUpdatesFilter] with [flowsUpdatesFilterUpdatesKeeperCount] as an argument
|
|
|
|
* and applied [flowUpdatesPreset]. It is assumed that you WILL CONFIGURE all updates receivers in [flowUpdatesPreset],
|
|
|
|
* because of after [flowUpdatesPreset] method calling will be triggered getting of updates.
|
2023-03-01 07:14:18 +00:00
|
|
|
*
|
|
|
|
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
|
|
|
|
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
|
|
|
|
* retrieved in different updates
|
2021-01-09 16:10:38 +00:00
|
|
|
*/
|
|
|
|
@Suppress("unused")
|
|
|
|
fun TelegramBot.longPolling(
|
|
|
|
timeoutSeconds: Seconds = 30,
|
|
|
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
|
|
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
|
|
|
flowsUpdatesFilterUpdatesKeeperCount: Int = 100,
|
2022-12-31 09:13:50 +00:00
|
|
|
autoDisableWebhooks: Boolean = true,
|
2023-02-06 07:28:38 +00:00
|
|
|
autoSkipTimeoutExceptions: Boolean = true,
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis: Long? = 1000L,
|
2021-01-09 16:10:38 +00:00
|
|
|
flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit
|
2023-03-01 05:55:17 +00:00
|
|
|
): Job = longPolling(FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply(flowUpdatesPreset), timeoutSeconds, scope, autoDisableWebhooks, autoSkipTimeoutExceptions, mediaGroupsDebounceTimeMillis, exceptionsHandler)
|
2021-01-09 16:10:38 +00:00
|
|
|
|
2023-03-01 07:14:18 +00:00
|
|
|
/**
|
|
|
|
* @param mediaGroupsDebounceTimeMillis Will be used for calling of [updateHandlerWithMediaGroupsAdaptation]. Pass null
|
|
|
|
* in case you wish to enable classic way of updates handling, but in that mode some media group messages can be
|
|
|
|
* retrieved in different updates
|
|
|
|
*/
|
2020-05-13 17:22:35 +00:00
|
|
|
fun RequestsExecutor.startGettingOfUpdatesByLongPolling(
|
|
|
|
updatesFilter: UpdatesFilter,
|
|
|
|
timeoutSeconds: Seconds = 30,
|
2020-05-14 18:28:16 +00:00
|
|
|
exceptionsHandler: ExceptionHandler<Unit>? = null,
|
2022-12-31 09:13:50 +00:00
|
|
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
|
|
|
|
autoDisableWebhooks: Boolean = true,
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis: Long? = 1000L,
|
2023-02-06 07:28:38 +00:00
|
|
|
autoSkipTimeoutExceptions: Boolean = true,
|
2020-05-13 17:22:35 +00:00
|
|
|
): Job = startGettingOfUpdatesByLongPolling(
|
|
|
|
timeoutSeconds,
|
|
|
|
scope,
|
|
|
|
exceptionsHandler,
|
|
|
|
updatesFilter.allowedUpdates,
|
2022-12-31 09:13:50 +00:00
|
|
|
autoDisableWebhooks,
|
2023-02-06 07:28:38 +00:00
|
|
|
autoSkipTimeoutExceptions,
|
2023-03-01 05:55:17 +00:00
|
|
|
mediaGroupsDebounceTimeMillis,
|
2020-05-13 17:22:35 +00:00
|
|
|
updatesFilter.asUpdateReceiver
|
|
|
|
)
|