diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt index 8db0996f95..5c45d40caf 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt @@ -17,6 +17,7 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidde import dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage +import dev.inmo.tgbotapi.types.message.payments.RefundedPaymentEvent import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.types.request.ChatShared import dev.inmo.tgbotapi.types.request.ChatSharedRequest @@ -140,6 +141,10 @@ suspend fun BehaviourContext.waitSuccessfulPaymentEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } ) = waitEvents(initRequest, errorFactory) +suspend fun BehaviourContext.waitRefundedPaymentEvents( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitEvents(initRequest, errorFactory) suspend fun BehaviourContext.waitUserLoggedInEvents( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt index 9805e194bc..9756b2017f 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt @@ -17,6 +17,7 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.forum.GeneralForumTopicUnhidde import dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage +import dev.inmo.tgbotapi.types.message.payments.RefundedPaymentEvent import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.types.request.ChatShared import dev.inmo.tgbotapi.types.request.ChatSharedRequest @@ -137,6 +138,10 @@ suspend fun BehaviourContext.waitSuccessfulPaymentEventsMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } ) = waitEventsMessages(initRequest, errorFactory) +suspend fun BehaviourContext.waitRefundedPaymentEventsMessages( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitEventsMessages(initRequest, errorFactory) suspend fun BehaviourContext.waitUserLoggedInEventsMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt index 8ff4fc5aaa..8cd2033b82 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -24,6 +24,7 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.PrivateEventMessage import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage import dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage +import dev.inmo.tgbotapi.types.message.payments.RefundedPaymentEvent import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.types.request.ChatShared import dev.inmo.tgbotapi.types.request.ChatSharedRequest @@ -513,6 +514,14 @@ suspend fun BC.onSuccessfulPayment( scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) +// TODO: add documentation +suspend fun BC.onRefundedPayment( + initialFilter: SimpleFilter>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + markerFactory: MarkerFactory, Any>? = ByChatMessageMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> +) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) + /** * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 55d1bf34ec..8aca07a40d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -264,6 +264,7 @@ internal data class RawMessage( pinned_message != null -> PinnedMessage(pinned_message.asMessage) proximity_alert_triggered != null -> proximity_alert_triggered successful_payment != null -> SuccessfulPaymentEvent(successful_payment) + refunded_payment != null -> RefundedPaymentEvent(refunded_payment) connected_website != null -> UserLoggedIn(connected_website) web_app_data != null -> web_app_data users_shared != null -> users_shared diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index ccb25f7023..0e3572da79 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -34,6 +34,7 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.message.content.* +import dev.inmo.tgbotapi.types.message.payments.RefundedPaymentEvent import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.types.message.textsources.* import dev.inmo.tgbotapi.types.passport.* @@ -3225,6 +3226,16 @@ inline fun ChatEvent.asSuccessfulPaymentEvent(): SuccessfulPaymentEvent? = this @PreviewFeature inline fun ChatEvent.requireSuccessfulPaymentEvent(): SuccessfulPaymentEvent = this as SuccessfulPaymentEvent +@PreviewFeature +inline fun ChatEvent.whenRefundedPaymentEvent(block: (RefundedPaymentEvent) -> T) = + asRefundedPaymentEvent()?.let(block) + +@PreviewFeature +inline fun ChatEvent.asRefundedPaymentEvent(): RefundedPaymentEvent? = this as? RefundedPaymentEvent + +@PreviewFeature +inline fun ChatEvent.requireRefundedPaymentEvent(): RefundedPaymentEvent = this as RefundedPaymentEvent + @PreviewFeature inline fun ChatEvent.whenProximityAlertTriggered(block: (ProximityAlertTriggered) -> T) = asProximityAlertTriggered()?.let(block) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt index e9ead34db5..1a95fb2584 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt @@ -340,6 +340,7 @@ import dev.inmo.tgbotapi.types.message.content.VideoNoteContent import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent import dev.inmo.tgbotapi.types.message.content.VoiceContent import dev.inmo.tgbotapi.types.message.content.WithCustomizedCaptionMediaContent +import dev.inmo.tgbotapi.types.message.payments.RefundedPaymentEvent import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.types.message.textsources.BlockquoteTextSource import dev.inmo.tgbotapi.types.message.textsources.BoldTextSource @@ -3441,6 +3442,15 @@ public inline fun ChatEvent.successfulPaymentEventOrThrow(): SuccessfulPaymentEv public inline fun ChatEvent.ifSuccessfulPaymentEvent(block: (SuccessfulPaymentEvent) -> T): T? = successfulPaymentEventOrNull() ?.let(block) +public inline fun ChatEvent.refundedPaymentEventOrNull(): RefundedPaymentEvent? = this as? + dev.inmo.tgbotapi.types.message.payments.RefundedPaymentEvent + +public inline fun ChatEvent.refundedPaymentEventOrThrow(): RefundedPaymentEvent = this as + dev.inmo.tgbotapi.types.message.payments.RefundedPaymentEvent + +public inline fun ChatEvent.ifRefundedPaymentEvent(block: (RefundedPaymentEvent) -> T): T? = + refundedPaymentEventOrNull() ?.let(block) + public inline fun ChatEvent.chatSharedOrNull(): ChatShared? = this as? dev.inmo.tgbotapi.types.request.ChatShared diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/EventsShortcuts.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/EventsShortcuts.kt index 93255bcf59..b3366ac685 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/EventsShortcuts.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/EventsShortcuts.kt @@ -8,6 +8,7 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.PrivateEventMessage import dev.inmo.tgbotapi.types.message.abstracts.* +import dev.inmo.tgbotapi.types.message.payments.RefundedPaymentEvent import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import dev.inmo.tgbotapi.utils.RiskFeature @@ -60,6 +61,8 @@ inline fun Flow>.newChannelPinnedMessageEvents() = filterCha inline fun FlowsUpdatesFilter.newChannelPinnedMessageEvents() = filterChannelEvents() inline fun Flow>.successfulPaymentInChannelEvents() = filterChannelEvents() inline fun FlowsUpdatesFilter.successfulPaymentInChannelEvents() = filterChannelEvents() +inline fun Flow>.refundedPaymentInChannelEvents() = filterChannelEvents() +inline fun FlowsUpdatesFilter.refundedPaymentInChannelEvents() = filterChannelEvents() inline fun Flow>.channelEvents() = filterChannelEvents() @RiskFeature("Use with caution") @@ -84,6 +87,8 @@ inline fun Flow>.proximityAlertTriggeredInGroupEvents() = fi inline fun FlowsUpdatesFilter.proximityAlertTriggeredInGroupEvents() = filterGroupEvents() inline fun Flow>.successfulPaymentInGroupEvents() = filterGroupEvents() inline fun FlowsUpdatesFilter.successfulPaymentInGroupEvents() = filterGroupEvents() +inline fun Flow>.refundedPaymentInGroupEvents() = filterGroupEvents() +inline fun FlowsUpdatesFilter.refundedPaymentInGroupEvents() = filterGroupEvents() inline fun Flow>.groupEvents() = filterGroupEvents() @@ -109,6 +114,8 @@ inline fun Flow>.proximityAlertTriggeredInSupergroupEvents() inline fun FlowsUpdatesFilter.proximityAlertTriggeredInSupergroupEvents() = filterSupergroupEvents() inline fun Flow>.successfulPaymentInSupergroupEvents() = filterSupergroupEvents() inline fun FlowsUpdatesFilter.successfulPaymentInSupergroupEvents() = filterSupergroupEvents() +inline fun Flow>.refundedPaymentInSupergroupEvents() = filterSupergroupEvents() +inline fun FlowsUpdatesFilter.refundedPaymentInSupergroupEvents() = filterSupergroupEvents() inline fun Flow>.supergroupEvents() = filterSupergroupEvents() @RiskFeature("Use with caution") @@ -117,6 +124,8 @@ inline fun Flow>.filterPrivateEve inline fun FlowsUpdatesFilter.filterPrivateEvents() = privateEvents().filterByChatEvent>() inline fun Flow>.successfulPaymentInPrivateEvents() = filterPrivateEvents() inline fun FlowsUpdatesFilter.successfulPaymentInPrivateEvents() = filterPrivateEvents() +inline fun Flow>.refundedPaymentInPrivateEvents() = filterPrivateEvents() +inline fun FlowsUpdatesFilter.refundedPaymentInPrivateEvents() = filterPrivateEvents() inline fun Flow>.newPrivatePinnedMessageEvents() = filterPrivateEvents() inline fun FlowsUpdatesFilter.newPrivatePinnedMessageEvents() = filterPrivateEvents() inline fun Flow>.privateEvents() = filterPrivateEvents()