mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
additional callback for polls in UpdatesFilter
This commit is contained in:
parent
981e6f43d9
commit
a5ca9c0ce7
@ -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
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -24,6 +24,7 @@ class FlowsUpdatesFilter {
|
||||
private val callbackQueryChannel: BroadcastChannel<CallbackQueryUpdate> = BroadcastChannel(Channel.CONFLATED)
|
||||
private val shippingQueryChannel: BroadcastChannel<ShippingQueryUpdate> = BroadcastChannel(Channel.CONFLATED)
|
||||
private val preCheckoutQueryChannel: BroadcastChannel<PreCheckoutQueryUpdate> = BroadcastChannel(Channel.CONFLATED)
|
||||
private val pollChannel: BroadcastChannel<PollUpdate> = BroadcastChannel(Channel.CONFLATED)
|
||||
|
||||
val filter = UpdatesFilter(
|
||||
messageChannel.createUpdateReceiver(),
|
||||
@ -54,4 +55,5 @@ class FlowsUpdatesFilter {
|
||||
val callbackQueryFlow: Flow<CallbackQueryUpdate> = callbackQueryChannel.asFlow()
|
||||
val shippingQueryFlow: Flow<ShippingQueryUpdate> = shippingQueryChannel.asFlow()
|
||||
val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate> = preCheckoutQueryChannel.asFlow()
|
||||
val pollFlow: Flow<PollUpdate> = pollChannel.asFlow()
|
||||
}
|
@ -19,7 +19,8 @@ data class UpdatesFilter(
|
||||
private val inlineQueryCallback: UpdateReceiver<InlineQueryUpdate>? = null,
|
||||
private val callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = 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 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<InlineQueryUpdate>? = null,
|
||||
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
||||
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
|
||||
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null
|
||||
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
|
||||
pollCallback: UpdateReceiver<PollUpdate>? = 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
|
||||
)
|
||||
|
@ -34,6 +34,7 @@ suspend fun RequestsExecutor.startGettingOfUpdates(
|
||||
callbackQueryCallback: UpdateReceiver<CallbackQueryUpdate>? = null,
|
||||
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
|
||||
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
|
||||
pollCallback: UpdateReceiver<PollUpdate>? = 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<CallbackQueryUpdate>? = null,
|
||||
shippingQueryCallback: UpdateReceiver<ShippingQueryUpdate>? = null,
|
||||
preCheckoutQueryCallback: UpdateReceiver<PreCheckoutQueryUpdate>? = null,
|
||||
pollCallback: UpdateReceiver<PollUpdate>? = 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
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user