mirror of
				https://github.com/InsanusMokrassar/TelegramBotAPI.git
				synced 2025-10-25 01:00:13 +00:00 
			
		
		
		
	updates in long polling methods
This commit is contained in:
		| @@ -7,6 +7,10 @@ | ||||
| * `Behaviour Builder`: | ||||
|     * Extension `TelegramBot#buildBehaviour` have changed its return value: now it is `Job` instead of | ||||
|       `FlowsUpdatesFilter` | ||||
| * `Utils` | ||||
|     * New extensions `TelegramBot#longPolling` were added as new recommended way to start getting updates via long | ||||
|       polling | ||||
|         * Old extensions `RequestsExecutor#startGettingFlowsUpdatesByLongPolling` has been deprecated | ||||
|  | ||||
| ## 0.30.13 | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package dev.inmo.tgbotapi.extensions.behaviour_builder | ||||
|  | ||||
| import dev.inmo.tgbotapi.bot.TelegramBot | ||||
| import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling | ||||
| import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingOfUpdatesByLongPolling | ||||
| import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter | ||||
| import dev.inmo.tgbotapi.utils.PreviewFeature | ||||
| @@ -46,8 +47,8 @@ suspend fun TelegramBot.buildBehaviour( | ||||
|         it, | ||||
|         block | ||||
|     ) | ||||
|     startGettingOfUpdatesByLongPolling( | ||||
|         updatesFilter = it, | ||||
|     longPolling( | ||||
|         it, | ||||
|         scope = scope | ||||
|     ) | ||||
| } | ||||
|   | ||||
| @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving | ||||
| import dev.inmo.micro_utils.coroutines.ExceptionHandler | ||||
| import dev.inmo.micro_utils.coroutines.safely | ||||
| import dev.inmo.tgbotapi.bot.RequestsExecutor | ||||
| import dev.inmo.tgbotapi.bot.TelegramBot | ||||
| import dev.inmo.tgbotapi.bot.exceptions.RequestException | ||||
| import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates | ||||
| import dev.inmo.tgbotapi.extensions.utils.updates.lastUpdateIdentifier | ||||
| @@ -15,7 +16,7 @@ import dev.inmo.tgbotapi.updateshandlers.* | ||||
| import dev.inmo.tgbotapi.utils.* | ||||
| import kotlinx.coroutines.* | ||||
|  | ||||
| fun RequestsExecutor.startGettingOfUpdatesByLongPolling( | ||||
| fun TelegramBot.startGettingOfUpdatesByLongPolling( | ||||
|     timeoutSeconds: Seconds = 30, | ||||
|     scope: CoroutineScope = CoroutineScope(Dispatchers.Default), | ||||
|     exceptionsHandler: (ExceptionHandler<Unit>)? = null, | ||||
| @@ -65,6 +66,33 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling( | ||||
|     } | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Will [startGettingOfUpdatesByLongPolling] using incoming [flowsUpdatesFilter]. It is assumed that you ALREADY CONFIGURE | ||||
|  * all updates receivers, because this method will trigger getting of updates and. | ||||
|  */ | ||||
| fun TelegramBot.longPolling( | ||||
|     flowsUpdatesFilter: FlowsUpdatesFilter, | ||||
|     timeoutSeconds: Seconds = 30, | ||||
|     scope: CoroutineScope = CoroutineScope(Dispatchers.Default), | ||||
|     exceptionsHandler: ExceptionHandler<Unit>? = null | ||||
| ): Job = flowsUpdatesFilter.run { | ||||
|     startGettingOfUpdatesByLongPolling(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, asUpdateReceiver) | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * 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. | ||||
|  */ | ||||
| @Suppress("unused") | ||||
| fun TelegramBot.longPolling( | ||||
|     timeoutSeconds: Seconds = 30, | ||||
|     scope: CoroutineScope = CoroutineScope(Dispatchers.Default), | ||||
|     exceptionsHandler: ExceptionHandler<Unit>? = null, | ||||
|     flowsUpdatesFilterUpdatesKeeperCount: Int = 100, | ||||
|     flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit | ||||
| ): Job = longPolling(FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply(flowUpdatesPreset), timeoutSeconds, scope, exceptionsHandler) | ||||
|  | ||||
| /** | ||||
|  * This method will create a new one [FlowsUpdatesFilter]. This method could be unsafe due to the fact that it will start | ||||
|  * getting updates IMMEDIATELY. That means that your bot will be able to skip some of them until you will call | ||||
| @@ -72,6 +100,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling( | ||||
|  * [flowUpdatesPreset] lambda - it will be called BEFORE starting updates getting | ||||
|  */ | ||||
| @FlowPreview | ||||
| @Deprecated("Will be removed soon", ReplaceWith("longPolling", "dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling")) | ||||
| @Suppress("unused") | ||||
| fun RequestsExecutor.startGettingFlowsUpdatesByLongPolling( | ||||
|     timeoutSeconds: Seconds = 30, | ||||
| @@ -97,6 +126,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling( | ||||
|     updatesFilter.asUpdateReceiver | ||||
| ) | ||||
|  | ||||
| @Deprecated("Will be removed soon", ReplaceWith("longPolling", "dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling")) | ||||
| fun RequestsExecutor.startGettingOfUpdatesByLongPolling( | ||||
|     messageCallback: UpdateReceiver<MessageUpdate>? = null, | ||||
|     messageMediaGroupCallback: UpdateReceiver<MessageMediaGroupUpdate>? = null, | ||||
| @@ -141,6 +171,7 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling( | ||||
|     ) | ||||
| } | ||||
|  | ||||
| @Deprecated("Will be removed soon", ReplaceWith("longPolling", "dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling")) | ||||
| @Suppress("unused") | ||||
| fun RequestsExecutor.startGettingOfUpdatesByLongPolling( | ||||
|     messageCallback: UpdateReceiver<MessageUpdate>? = null, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user