1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

additional callback for polls in UpdatesFilter

This commit is contained in:
InsanusMokrassar 2019-05-10 13:14:50 +08:00
parent 981e6f43d9
commit a5ca9c0ce7
6 changed files with 22 additions and 6 deletions

View File

@ -23,6 +23,7 @@ some default library
* Replace `UpdatesFilter` and `UpdatesPoller` into another package * Replace `UpdatesFilter` and `UpdatesPoller` into another package
* Replace `WebhookPrivateKeyConfig` * Replace `WebhookPrivateKeyConfig`
* Added `FlowsUpdatesFilter` * Added `FlowsUpdatesFilter`
* `UpdatesFilter` now have additional callback for polls
## 0.13.0 Telegram Polls ## 0.13.0 Telegram Polls

View File

@ -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 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")) @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 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 @Serializable
data class GetUpdates( data class GetUpdates(

View File

@ -9,6 +9,7 @@ const val UPDATE_INLINE_QUERY = "inline_query"
const val UPDATE_CALLBACK_QUERY = "callback_query" const val UPDATE_CALLBACK_QUERY = "callback_query"
const val UPDATE_SHIPPING_QUERY = "shipping_query" const val UPDATE_SHIPPING_QUERY = "shipping_query"
const val UPDATE_PRE_CHECKOUT_QUERY = "pre_checkout_query" const val UPDATE_PRE_CHECKOUT_QUERY = "pre_checkout_query"
const val UPDATE_POLL = "poll"
val ALL_UPDATES_LIST = listOf( val ALL_UPDATES_LIST = listOf(
UPDATE_MESSAGE, UPDATE_MESSAGE,
@ -19,5 +20,6 @@ val ALL_UPDATES_LIST = listOf(
UPDATE_INLINE_QUERY, UPDATE_INLINE_QUERY,
UPDATE_CALLBACK_QUERY, UPDATE_CALLBACK_QUERY,
UPDATE_SHIPPING_QUERY, UPDATE_SHIPPING_QUERY,
UPDATE_PRE_CHECKOUT_QUERY UPDATE_PRE_CHECKOUT_QUERY,
UPDATE_POLL
) )

View File

@ -24,6 +24,7 @@ class FlowsUpdatesFilter {
private val callbackQueryChannel: BroadcastChannel<CallbackQueryUpdate> = BroadcastChannel(Channel.CONFLATED) private val callbackQueryChannel: BroadcastChannel<CallbackQueryUpdate> = BroadcastChannel(Channel.CONFLATED)
private val shippingQueryChannel: BroadcastChannel<ShippingQueryUpdate> = BroadcastChannel(Channel.CONFLATED) private val shippingQueryChannel: BroadcastChannel<ShippingQueryUpdate> = BroadcastChannel(Channel.CONFLATED)
private val preCheckoutQueryChannel: BroadcastChannel<PreCheckoutQueryUpdate> = BroadcastChannel(Channel.CONFLATED) private val preCheckoutQueryChannel: BroadcastChannel<PreCheckoutQueryUpdate> = BroadcastChannel(Channel.CONFLATED)
private val pollChannel: BroadcastChannel<PollUpdate> = BroadcastChannel(Channel.CONFLATED)
val filter = UpdatesFilter( val filter = UpdatesFilter(
messageChannel.createUpdateReceiver(), messageChannel.createUpdateReceiver(),
@ -54,4 +55,5 @@ class FlowsUpdatesFilter {
val callbackQueryFlow: Flow<CallbackQueryUpdate> = callbackQueryChannel.asFlow() val callbackQueryFlow: Flow<CallbackQueryUpdate> = callbackQueryChannel.asFlow()
val shippingQueryFlow: Flow<ShippingQueryUpdate> = shippingQueryChannel.asFlow() val shippingQueryFlow: Flow<ShippingQueryUpdate> = shippingQueryChannel.asFlow()
val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate> = preCheckoutQueryChannel.asFlow() val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate> = preCheckoutQueryChannel.asFlow()
val pollFlow: Flow<PollUpdate> = pollChannel.asFlow()
} }

View File

@ -19,7 +19,8 @@ data class UpdatesFilter(
private val inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null, private val inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
private val callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null, private val callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
private val shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null, private val shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
private val preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null private val preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
private val pollUpdateCallback: UpdateReceiver<PollUpdate>? = null
) { ) {
val asUpdateReceiver: UpdateReceiver<Update> = this::invoke val asUpdateReceiver: UpdateReceiver<Update> = this::invoke
val allowedUpdates = listOfNotNull( val allowedUpdates = listOfNotNull(
@ -31,7 +32,8 @@ data class UpdatesFilter(
inlineQueryCallback ?.let { UPDATE_INLINE_QUERY }, inlineQueryCallback ?.let { UPDATE_INLINE_QUERY },
callbackQueryCallback ?.let { UPDATE_CALLBACK_QUERY }, callbackQueryCallback ?.let { UPDATE_CALLBACK_QUERY },
shippingQueryCallback ?.let { UPDATE_SHIPPING_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) { suspend fun invoke(update: Update) {
@ -73,6 +75,7 @@ data class UpdatesFilter(
is CallbackQueryUpdate -> callbackQueryCallback ?.invoke(update) is CallbackQueryUpdate -> callbackQueryCallback ?.invoke(update)
is ShippingQueryUpdate -> shippingQueryCallback ?.invoke(update) is ShippingQueryUpdate -> shippingQueryCallback ?.invoke(update)
is PreCheckoutQueryUpdate -> preCheckoutQueryCallback ?.invoke(update) is PreCheckoutQueryUpdate -> preCheckoutQueryCallback ?.invoke(update)
is PollUpdate -> pollUpdateCallback ?.invoke(update)
} }
} }
} }
@ -87,7 +90,8 @@ fun createSimpleUpdateFilter(
inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null, inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null, callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null, shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
pollCallback: UpdateReceiver<PollUpdate>? = null
): UpdatesFilter = UpdatesFilter( ): UpdatesFilter = UpdatesFilter(
messageCallback = messageCallback, messageCallback = messageCallback,
messageMediaGroupCallback = mediaGroupCallback, messageMediaGroupCallback = mediaGroupCallback,
@ -101,5 +105,6 @@ fun createSimpleUpdateFilter(
inlineQueryCallback = inlineQueryCallback, inlineQueryCallback = inlineQueryCallback,
callbackQueryCallback = callbackQueryCallback, callbackQueryCallback = callbackQueryCallback,
shippingQueryCallback = shippingQueryCallback, shippingQueryCallback = shippingQueryCallback,
preCheckoutQueryCallback = preCheckoutQueryCallback preCheckoutQueryCallback = preCheckoutQueryCallback,
pollUpdateCallback = pollCallback
) )

View File

@ -34,6 +34,7 @@ suspend fun RequestsExecutor.startGettingOfUpdates(
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null, callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null, shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null, preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
pollCallback: UpdateReceiver<PollUpdate>? = null,
requestsDelayMillis: Long = 1000, requestsDelayMillis: Long = 1000,
scope: CoroutineScope = GlobalScope scope: CoroutineScope = GlobalScope
): Job { ): Job {
@ -50,7 +51,8 @@ suspend fun RequestsExecutor.startGettingOfUpdates(
inlineQueryCallback, inlineQueryCallback,
callbackQueryCallback, callbackQueryCallback,
shippingQueryCallback, shippingQueryCallback,
preCheckoutQueryCallback preCheckoutQueryCallback,
pollCallback
) )
return startGettingOfUpdates( return startGettingOfUpdates(
requestsDelayMillis, requestsDelayMillis,
@ -71,6 +73,7 @@ suspend fun RequestsExecutor.startGettingOfUpdates(
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null, callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null, shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null, preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
pollCallback: UpdateReceiver<PollUpdate>? = null,
requestsDelayMillis: Long = 1000, requestsDelayMillis: Long = 1000,
scope: CoroutineScope = GlobalScope scope: CoroutineScope = GlobalScope
): Job = startGettingOfUpdates( ): Job = startGettingOfUpdates(
@ -87,6 +90,7 @@ suspend fun RequestsExecutor.startGettingOfUpdates(
callbackQueryCallback = callbackQueryCallback, callbackQueryCallback = callbackQueryCallback,
shippingQueryCallback = shippingQueryCallback, shippingQueryCallback = shippingQueryCallback,
preCheckoutQueryCallback = preCheckoutQueryCallback, preCheckoutQueryCallback = preCheckoutQueryCallback,
pollCallback = pollCallback,
requestsDelayMillis = requestsDelayMillis, requestsDelayMillis = requestsDelayMillis,
scope = scope scope = scope
) )