diff --git a/CHANGELOG.md b/CHANGELOG.md index 56386fae3d..86b0f9e79e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ some default library * Replace `UpdatesFilter` and `UpdatesPoller` into another package * Replace `WebhookPrivateKeyConfig` * Added `FlowsUpdatesFilter` +* `UpdatesFilter` now have additional callback for polls ## 0.13.0 Telegram Polls diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt index b5f88f9882..3c697c3a7d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt @@ -26,6 +26,8 @@ const val UPDATE_CALLBACK_QUERY = com.github.insanusmokrassar.TelegramBotAPI.typ const val UPDATE_SHIPPING_QUERY = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_SHIPPING_QUERY @Deprecated("Replaced to other package", ReplaceWith("UPDATE_PRE_CHECKOUT_QUERY", "com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_PRE_CHECKOUT_QUERY")) const val UPDATE_PRE_CHECKOUT_QUERY = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_PRE_CHECKOUT_QUERY +@Deprecated("Replaced to other package", ReplaceWith("UPDATE_POLL", "com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_POLL")) +const val UPDATE_POLL = com.github.insanusmokrassar.TelegramBotAPI.types.UPDATE_POLL @Serializable data class GetUpdates( diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/UpdateTypes.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/UpdateTypes.kt index e5d477db3f..a24e00d4eb 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/UpdateTypes.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/UpdateTypes.kt @@ -9,6 +9,7 @@ const val UPDATE_INLINE_QUERY = "inline_query" const val UPDATE_CALLBACK_QUERY = "callback_query" const val UPDATE_SHIPPING_QUERY = "shipping_query" const val UPDATE_PRE_CHECKOUT_QUERY = "pre_checkout_query" +const val UPDATE_POLL = "poll" val ALL_UPDATES_LIST = listOf( UPDATE_MESSAGE, @@ -19,5 +20,6 @@ val ALL_UPDATES_LIST = listOf( UPDATE_INLINE_QUERY, UPDATE_CALLBACK_QUERY, UPDATE_SHIPPING_QUERY, - UPDATE_PRE_CHECKOUT_QUERY + UPDATE_PRE_CHECKOUT_QUERY, + UPDATE_POLL ) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt index 93603d1119..5fa8b96d1a 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/FlowsUpdatesFilter.kt @@ -24,6 +24,7 @@ class FlowsUpdatesFilter { private val callbackQueryChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) private val shippingQueryChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) private val preCheckoutQueryChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) + private val pollChannel: BroadcastChannel = BroadcastChannel(Channel.CONFLATED) val filter = UpdatesFilter( messageChannel.createUpdateReceiver(), @@ -54,4 +55,5 @@ class FlowsUpdatesFilter { val callbackQueryFlow: Flow = callbackQueryChannel.asFlow() val shippingQueryFlow: Flow = shippingQueryChannel.asFlow() val preCheckoutQueryFlow: Flow = preCheckoutQueryChannel.asFlow() + val pollFlow: Flow = pollChannel.asFlow() } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/UpdatesFilter.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/UpdatesFilter.kt index e63a3862c6..218ec5737b 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/UpdatesFilter.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/UpdatesFilter.kt @@ -19,7 +19,8 @@ data class UpdatesFilter( private val inlineQueryCallback: UpdateReceiver? = null, private val callbackQueryCallback: UpdateReceiver? = null, private val shippingQueryCallback: UpdateReceiver? = null, - private val preCheckoutQueryCallback: UpdateReceiver? = null + private val preCheckoutQueryCallback: UpdateReceiver? = null, + private val pollUpdateCallback: UpdateReceiver? = null ) { val asUpdateReceiver: UpdateReceiver = this::invoke val allowedUpdates = listOfNotNull( @@ -31,7 +32,8 @@ data class UpdatesFilter( inlineQueryCallback ?.let { UPDATE_INLINE_QUERY }, callbackQueryCallback ?.let { UPDATE_CALLBACK_QUERY }, shippingQueryCallback ?.let { UPDATE_SHIPPING_QUERY }, - preCheckoutQueryCallback ?.let { UPDATE_PRE_CHECKOUT_QUERY } + preCheckoutQueryCallback ?.let { UPDATE_PRE_CHECKOUT_QUERY }, + pollUpdateCallback ?.let { UPDATE_POLL } ) suspend fun invoke(update: Update) { @@ -73,6 +75,7 @@ data class UpdatesFilter( is CallbackQueryUpdate -> callbackQueryCallback ?.invoke(update) is ShippingQueryUpdate -> shippingQueryCallback ?.invoke(update) is PreCheckoutQueryUpdate -> preCheckoutQueryCallback ?.invoke(update) + is PollUpdate -> pollUpdateCallback ?.invoke(update) } } } @@ -87,7 +90,8 @@ fun createSimpleUpdateFilter( inlineQueryCallback: UpdateReceiver? = null, callbackQueryCallback: UpdateReceiver? = null, shippingQueryCallback: UpdateReceiver? = null, - preCheckoutQueryCallback: UpdateReceiver? = null + preCheckoutQueryCallback: UpdateReceiver? = null, + pollCallback: UpdateReceiver? = null ): UpdatesFilter = UpdatesFilter( messageCallback = messageCallback, messageMediaGroupCallback = mediaGroupCallback, @@ -101,5 +105,6 @@ fun createSimpleUpdateFilter( inlineQueryCallback = inlineQueryCallback, callbackQueryCallback = callbackQueryCallback, shippingQueryCallback = shippingQueryCallback, - preCheckoutQueryCallback = preCheckoutQueryCallback + preCheckoutQueryCallback = preCheckoutQueryCallback, + pollUpdateCallback = pollCallback ) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt index 09250d70d5..42b87eced1 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesPolling.kt @@ -34,6 +34,7 @@ suspend fun RequestsExecutor.startGettingOfUpdates( callbackQueryCallback: UpdateReceiver? = null, shippingQueryCallback: UpdateReceiver? = null, preCheckoutQueryCallback: UpdateReceiver? = null, + pollCallback: UpdateReceiver? = null, requestsDelayMillis: Long = 1000, scope: CoroutineScope = GlobalScope ): Job { @@ -50,7 +51,8 @@ suspend fun RequestsExecutor.startGettingOfUpdates( inlineQueryCallback, callbackQueryCallback, shippingQueryCallback, - preCheckoutQueryCallback + preCheckoutQueryCallback, + pollCallback ) return startGettingOfUpdates( requestsDelayMillis, @@ -71,6 +73,7 @@ suspend fun RequestsExecutor.startGettingOfUpdates( callbackQueryCallback: UpdateReceiver? = null, shippingQueryCallback: UpdateReceiver? = null, preCheckoutQueryCallback: UpdateReceiver? = null, + pollCallback: UpdateReceiver? = null, requestsDelayMillis: Long = 1000, scope: CoroutineScope = GlobalScope ): Job = startGettingOfUpdates( @@ -87,6 +90,7 @@ suspend fun RequestsExecutor.startGettingOfUpdates( callbackQueryCallback = callbackQueryCallback, shippingQueryCallback = shippingQueryCallback, preCheckoutQueryCallback = preCheckoutQueryCallback, + pollCallback = pollCallback, requestsDelayMillis = requestsDelayMillis, scope = scope )