Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
commonMain.com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.UpdatesPolling.kt Maven / Gradle / Ivy
package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
import com.github.insanusmokrassar.TelegramBotAPI.bot.UpdatesPoller
import com.github.insanusmokrassar.TelegramBotAPI.types.ALL_UPDATES_LIST
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.KtorUpdatesPoller
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.UpdatesFilter
import kotlinx.coroutines.*
typealias UpdateReceiver = suspend (T) -> Unit
fun RequestsExecutor.startGettingOfUpdates(
timeoutMillis: Long = 30 * 1000,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default),
allowedUpdates: List? = null,
block: UpdateReceiver
): UpdatesPoller {
return KtorUpdatesPoller(
this,
timeoutMillis.toInt() / 1000,
allowedUpdates = allowedUpdates ?: ALL_UPDATES_LIST,
updatesReceiver = block
).also {
it.start(scope)
}
}
fun RequestsExecutor.startGettingOfUpdates(
messageCallback: UpdateReceiver? = null,
messageMediaGroupCallback: UpdateReceiver? = null,
editedMessageCallback: UpdateReceiver? = null,
editedMessageMediaGroupCallback: UpdateReceiver? = null,
channelPostCallback: UpdateReceiver? = null,
channelPostMediaGroupCallback: UpdateReceiver? = null,
editedChannelPostCallback: UpdateReceiver? = null,
editedChannelPostMediaGroupCallback: UpdateReceiver? = null,
chosenInlineResultCallback: UpdateReceiver? = null,
inlineQueryCallback: UpdateReceiver? = null,
callbackQueryCallback: UpdateReceiver? = null,
shippingQueryCallback: UpdateReceiver? = null,
preCheckoutQueryCallback: UpdateReceiver? = null,
pollCallback: UpdateReceiver? = null,
pollAnswerCallback: UpdateReceiver? = null,
timeoutMillis: Long = 30 * 1000,
scope: CoroutineScope = GlobalScope
): UpdatesPoller {
val filter = UpdatesFilter(
messageCallback,
messageMediaGroupCallback,
editedMessageCallback,
editedMessageMediaGroupCallback,
channelPostCallback,
channelPostMediaGroupCallback,
editedChannelPostCallback,
editedChannelPostMediaGroupCallback,
chosenInlineResultCallback,
inlineQueryCallback,
callbackQueryCallback,
shippingQueryCallback,
preCheckoutQueryCallback,
pollCallback,
pollAnswerCallback
)
return startGettingOfUpdates(
timeoutMillis,
scope,
filter.allowedUpdates,
filter.asUpdateReceiver
)
}
fun RequestsExecutor.startGettingOfUpdates(
messageCallback: UpdateReceiver? = null,
mediaGroupCallback: UpdateReceiver? = null,
editedMessageCallback: UpdateReceiver? = null,
channelPostCallback: UpdateReceiver? = null,
editedChannelPostCallback: UpdateReceiver? = null,
chosenInlineResultCallback: UpdateReceiver? = null,
inlineQueryCallback: UpdateReceiver? = null,
callbackQueryCallback: UpdateReceiver? = null,
shippingQueryCallback: UpdateReceiver? = null,
preCheckoutQueryCallback: UpdateReceiver? = null,
pollCallback: UpdateReceiver? = null,
pollAnswerCallback: UpdateReceiver? = null,
timeoutMillis: Long = 30 * 1000,
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
): UpdatesPoller = startGettingOfUpdates(
messageCallback = messageCallback,
messageMediaGroupCallback = mediaGroupCallback,
editedMessageCallback = editedMessageCallback,
editedMessageMediaGroupCallback = mediaGroupCallback,
channelPostCallback = channelPostCallback,
channelPostMediaGroupCallback = mediaGroupCallback,
editedChannelPostCallback = editedChannelPostCallback,
editedChannelPostMediaGroupCallback = mediaGroupCallback,
chosenInlineResultCallback = chosenInlineResultCallback,
inlineQueryCallback = inlineQueryCallback,
callbackQueryCallback = callbackQueryCallback,
shippingQueryCallback = shippingQueryCallback,
preCheckoutQueryCallback = preCheckoutQueryCallback,
pollCallback = pollCallback,
pollAnswerCallback = pollAnswerCallback,
timeoutMillis = timeoutMillis,
scope = scope
)