mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
include media groups
This commit is contained in:
parent
633239961a
commit
ce0fceb240
@ -34,11 +34,11 @@ suspend fun <T> FlowsUpdatesFilter.expectFlow(
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
||||
filter: suspend (Update) -> T?
|
||||
filter: suspend (Update) -> List<T>
|
||||
): Flow<T> {
|
||||
val flow = allUpdatesFlow.mapNotNull {
|
||||
val flow = allUpdatesFlow.flatMapConcat {
|
||||
val result = safelyWithoutExceptions { filter(it) }
|
||||
if (result == null) {
|
||||
(if (result == null || result.isEmpty()) {
|
||||
if (cancelTrigger(it)) {
|
||||
cancelRequestFactory(it) ?.also {
|
||||
safelyWithoutExceptions { bot.execute(it) }
|
||||
@ -48,10 +48,10 @@ suspend fun <T> FlowsUpdatesFilter.expectFlow(
|
||||
errorFactory(it) ?.also { errorRequest ->
|
||||
safelyWithoutExceptions { bot.execute(errorRequest) }
|
||||
}
|
||||
null
|
||||
emptyList()
|
||||
} else {
|
||||
result
|
||||
}
|
||||
}).asFlow()
|
||||
}
|
||||
val result = if (count == null) {
|
||||
flow
|
||||
@ -79,7 +79,7 @@ suspend fun <T> BehaviourContext.expectFlow(
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
||||
filter: suspend (Update) -> T?
|
||||
filter: suspend (Update) -> List<T>
|
||||
) = flowsUpdatesFilter.expectFlow(bot, initRequest, count, errorFactory, cancelRequestFactory, cancelTrigger, filter)
|
||||
|
||||
/**
|
||||
@ -99,8 +99,10 @@ suspend fun <T> FlowsUpdatesFilter.expectOne(
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelRequestFactory: NullableRequestBuilder<*> = { null },
|
||||
cancelTrigger: suspend (Update) -> Boolean = { cancelRequestFactory(it) != null },
|
||||
filter: suspend (Update) -> T?,
|
||||
): T = expectFlow(bot, initRequest, 1, errorFactory, cancelRequestFactory, cancelTrigger, filter).first()
|
||||
filter: suspend (Update) -> T?
|
||||
): T = expectFlow(bot, initRequest, 1, errorFactory, cancelRequestFactory, cancelTrigger) {
|
||||
listOfNotNull(filter.invoke(it))
|
||||
}.first()
|
||||
|
||||
/**
|
||||
* @param initRequest If not null, this request will be sent by [bot] before returning value
|
||||
|
@ -20,7 +20,7 @@ private suspend fun <O> BehaviourContext.waitCallbackQueries(
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
it.asCallbackQueryUpdate() ?.data ?.mapper()
|
||||
it.asCallbackQueryUpdate() ?.data ?.mapper().let(::listOfNotNull)
|
||||
}.toList().toList()
|
||||
|
||||
|
||||
|
@ -3,10 +3,10 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.utils.asContentMessage
|
||||
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.*
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.content.media.*
|
||||
@ -18,6 +18,7 @@ typealias ContentMessageToContentMapper<T> = suspend ContentMessage<T>.() -> T?
|
||||
private suspend fun <O> BehaviourContext.waitContentMessage(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
includeMediaGroups: Boolean = true,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
mapper: suspend ContentMessage<MessageContent>.() -> O?
|
||||
): List<O> = expectFlow(
|
||||
@ -25,17 +26,24 @@ private suspend fun <O> BehaviourContext.waitContentMessage(
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
it.asMessageUpdate() ?.data ?.asContentMessage() ?.mapper()
|
||||
if (includeMediaGroups) {
|
||||
it.asSentMediaGroupUpdate() ?.data ?.mapNotNull {
|
||||
(it as ContentMessage<MessageContent>).mapper()
|
||||
} ?.let { return@expectFlow it }
|
||||
}
|
||||
it.asMessageUpdate() ?.data ?.asContentMessage() ?.mapper().let(::listOfNotNull)
|
||||
}.toList().toList()
|
||||
|
||||
private suspend inline fun <reified T : MessageContent> BehaviourContext.waitContent(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
includeMediaGroups: Boolean = true,
|
||||
noinline errorFactory: NullableRequestBuilder<*> = { null },
|
||||
noinline filter: ContentMessageToContentMapper<T>? = null
|
||||
) : List<T> = waitContentMessage<T>(
|
||||
count,
|
||||
initRequest,
|
||||
includeMediaGroups,
|
||||
errorFactory
|
||||
) {
|
||||
if (content is T) {
|
||||
@ -56,124 +64,124 @@ suspend fun BehaviourContext.waitContact(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<ContactContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitDice(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<DiceContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitGame(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<GameContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitLocation(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<LocationContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitPoll(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<PollContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitText(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<TextContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitVenue(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<VenueContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitAudioMediaGroup(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<AudioMediaGroupContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, true, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitDocumentMediaGroup(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<DocumentMediaGroupContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, true, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitMedia(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<MediaContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, true, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitMediaGroup(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<MediaGroupContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, true, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitVisualMediaGroup(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<VisualMediaGroupContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, true, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitAnimation(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<AnimationContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitAudio(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<AudioContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, true, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitDocument(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<DocumentContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, true, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitPhoto(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<PhotoContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, true, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitSticker(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<StickerContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitVideo(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<VideoContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, true, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitVideoNote(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<VideoNoteContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitVoice(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<VoiceContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, true, errorFactory, filter)
|
||||
suspend fun BehaviourContext.waitInvoice(
|
||||
count: Int = 1,
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
filter: ContentMessageToContentMapper<InvoiceContent>? = null
|
||||
) = waitContent(count, initRequest, errorFactory, filter)
|
||||
) = waitContent(count, initRequest, false, errorFactory, filter)
|
||||
|
@ -23,7 +23,7 @@ private suspend fun <O> BehaviourContext.waitEventMessages(
|
||||
count,
|
||||
errorFactory
|
||||
) {
|
||||
it.asMessageUpdate() ?.data ?.asChatEventMessage() ?.mapper()
|
||||
it.asMessageUpdate() ?.data ?.asChatEventMessage() ?.mapper().let(::listOfNotNull)
|
||||
}.toList().toList()
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ internal suspend inline fun <reified T : CallbackQuery> BehaviourContext.onCallb
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}.let(::listOfNotNull)
|
||||
}.subscribeSafelyWithoutExceptions(scope) { triggerQuery ->
|
||||
val (jobToCancel, scenario) = if (includeFilterByChatInBehaviourSubContext) {
|
||||
val subFilter = FlowsUpdatesFilter()
|
||||
|
@ -6,8 +6,7 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow
|
||||
import dev.inmo.tgbotapi.extensions.utils.asContentMessage
|
||||
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat
|
||||
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
@ -21,9 +20,22 @@ import kotlinx.coroutines.flow.filter
|
||||
|
||||
internal suspend inline fun <reified T : MessageContent> BehaviourContext.onContent(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
includeMediaGroups: Boolean = true,
|
||||
noinline additionalFilter: (suspend (ContentMessage<T>) -> Boolean)? = null,
|
||||
noinline scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<T>>
|
||||
) = flowsUpdatesFilter.expectFlow(bot) {
|
||||
if (includeMediaGroups) {
|
||||
it.asSentMediaGroupUpdate() ?.data ?.mapNotNull {
|
||||
if (it.content is T) {
|
||||
val adaptedMessage = it as ContentMessage<T>
|
||||
if (additionalFilter == null || additionalFilter(adaptedMessage)) adaptedMessage else null
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} ?.let {
|
||||
return@expectFlow it
|
||||
}
|
||||
}
|
||||
it.asMessageUpdate() ?.data ?.asContentMessage() ?.let { message ->
|
||||
if (message.content is T) {
|
||||
val adaptedMessage = message as ContentMessage<T>
|
||||
@ -31,7 +43,7 @@ internal suspend inline fun <reified T : MessageContent> BehaviourContext.onCont
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}.let(::listOfNotNull)
|
||||
}.subscribeSafelyWithoutExceptions(scope) { triggerMessage ->
|
||||
val (jobToCancel, scenario) = if (includeFilterByChatInBehaviourSubContext) {
|
||||
val subFilter = FlowsUpdatesFilter()
|
||||
@ -52,109 +64,109 @@ suspend fun BehaviourContext.onContact(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<ContactContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<ContactContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onDice(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<DiceContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<DiceContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onGame(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<GameContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<GameContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onLocation(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<LocationContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<LocationContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onPoll(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<PollContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<PollContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onText(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<TextContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<TextContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onVenue(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<VenueContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<VenueContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onAudioMediaGroup(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<AudioMediaGroupContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<AudioMediaGroupContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onDocumentMediaGroup(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<DocumentMediaGroupContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<DocumentMediaGroupContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onMediaCollection(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<MediaCollectionContent<TelegramMediaFile>>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<MediaCollectionContent<TelegramMediaFile>>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onMedia(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<MediaContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<MediaContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onMediaGroup(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<MediaGroupContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<MediaGroupContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onVisualMediaGroup(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<VisualMediaGroupContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<VisualMediaGroupContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onAnimation(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<AnimationContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<AnimationContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onAudio(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<AudioContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<AudioContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onDocument(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<DocumentContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<DocumentContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onPhoto(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<PhotoContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<PhotoContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onSticker(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<StickerContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<StickerContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onVideo(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<VideoContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<VideoContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onVideoNote(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<VideoNoteContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<VideoNoteContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onVoice(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<VoiceContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<VoiceContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
suspend fun BehaviourContext.onInvoice(
|
||||
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||
additionalFilter: (suspend (ContentMessage<InvoiceContent>) -> Boolean)? = null,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ContentMessage<InvoiceContent>>
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver)
|
||||
) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver)
|
||||
|
@ -29,7 +29,7 @@ internal suspend inline fun <reified T : ChatEvent> BehaviourContext.onEvent(
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}.let(::listOfNotNull)
|
||||
}.subscribeSafelyWithoutExceptions(scope) { triggerMessage ->
|
||||
val (jobToCancel, scenario) = if (includeFilterByChatInBehaviourSubContext) {
|
||||
val subFilter = FlowsUpdatesFilter()
|
||||
|
Loading…
Reference in New Issue
Block a user