mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
commit
5c655dd84c
@ -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<SuccessfulPaymentEvent>(initRequest, errorFactory)
|
||||
suspend fun BehaviourContext.waitRefundedPaymentEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEvents<RefundedPaymentEvent>(initRequest, errorFactory)
|
||||
suspend fun BehaviourContext.waitUserLoggedInEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
|
@ -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<SuccessfulPaymentEvent>(initRequest, errorFactory)
|
||||
suspend fun BehaviourContext.waitRefundedPaymentEventsMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEventsMessages<RefundedPaymentEvent>(initRequest, errorFactory)
|
||||
suspend fun BehaviourContext.waitUserLoggedInEventsMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
|
@ -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 : BehaviourContext> BC.onSuccessfulPayment(
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<SuccessfulPaymentEvent>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
||||
// TODO: add documentation
|
||||
suspend fun <BC : BehaviourContext> BC.onRefundedPayment(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<RefundedPaymentEvent>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<RefundedPaymentEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<RefundedPaymentEvent>, Any>? = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<RefundedPaymentEvent>>
|
||||
) = 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,
|
||||
|
@ -30,6 +30,7 @@ import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||
import dev.inmo.tgbotapi.types.message.payments.*
|
||||
import dev.inmo.tgbotapi.types.passport.PassportData
|
||||
import dev.inmo.tgbotapi.types.payments.Invoice
|
||||
import dev.inmo.tgbotapi.types.payments.RefundedPayment
|
||||
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
|
||||
import dev.inmo.tgbotapi.types.polls.Poll
|
||||
import dev.inmo.tgbotapi.types.request.ChatShared
|
||||
@ -99,6 +100,7 @@ internal data class RawMessage(
|
||||
private val invoice: Invoice? = null,
|
||||
private val dice: Dice? = null,
|
||||
private val successful_payment: SuccessfulPayment? = null,
|
||||
private val refunded_payment: RefundedPayment? = null,
|
||||
private val giveaway: Giveaway? = null,
|
||||
private val giveaway_winners: GiveawayResults? = null,
|
||||
private val sender_boost_count: Int? = null,
|
||||
@ -269,6 +271,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
|
||||
|
@ -0,0 +1,9 @@
|
||||
package dev.inmo.tgbotapi.types.message.payments
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent
|
||||
import dev.inmo.tgbotapi.types.message.payments.abstracts.PaymentInfo
|
||||
import dev.inmo.tgbotapi.types.payments.RefundedPayment
|
||||
|
||||
data class RefundedPaymentEvent(
|
||||
val payment: RefundedPayment
|
||||
) : PaymentInfo, CommonEvent
|
@ -0,0 +1,23 @@
|
||||
package dev.inmo.tgbotapi.types.payments
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Amounted
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currencied
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.TelegramPaymentChargeId
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class RefundedPayment(
|
||||
@SerialName(currencyField)
|
||||
override val currency: Currency,
|
||||
@SerialName(totalAmountField)
|
||||
override val amount: Long,
|
||||
@SerialName(invoicePayloadField)
|
||||
val invoicePayload: String,
|
||||
@SerialName(telegramPaymentChargeIdField)
|
||||
val telegramPaymentChargeId: TelegramPaymentChargeId,
|
||||
@SerialName(providerPaymentChargeIdField)
|
||||
val providerPaymentChargeId: String? = null
|
||||
): Amounted, Currencied
|
@ -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 <T> 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 <T> ChatEvent.whenProximityAlertTriggered(block: (ProximityAlertTriggered) -> T) =
|
||||
asProximityAlertTriggered()?.let(block)
|
||||
|
@ -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 <T> 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 <T> ChatEvent.ifRefundedPaymentEvent(block: (RefundedPaymentEvent) -> T): T? =
|
||||
refundedPaymentEventOrNull() ?.let(block)
|
||||
|
||||
public inline fun ChatEvent.chatSharedOrNull(): ChatShared? = this as?
|
||||
dev.inmo.tgbotapi.types.request.ChatShared
|
||||
|
||||
|
@ -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<ChatEventMessage<*>>.newChannelPinnedMessageEvents() = filterCha
|
||||
inline fun FlowsUpdatesFilter.newChannelPinnedMessageEvents() = filterChannelEvents<PinnedMessage>()
|
||||
inline fun Flow<ChatEventMessage<*>>.successfulPaymentInChannelEvents() = filterChannelEvents<SuccessfulPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.successfulPaymentInChannelEvents() = filterChannelEvents<SuccessfulPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.refundedPaymentInChannelEvents() = filterChannelEvents<RefundedPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.refundedPaymentInChannelEvents() = filterChannelEvents<RefundedPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.channelEvents() = filterChannelEvents<ChannelEvent>()
|
||||
|
||||
@RiskFeature("Use with caution")
|
||||
@ -84,6 +87,8 @@ inline fun Flow<ChatEventMessage<*>>.proximityAlertTriggeredInGroupEvents() = fi
|
||||
inline fun FlowsUpdatesFilter.proximityAlertTriggeredInGroupEvents() = filterGroupEvents<ProximityAlertTriggered>()
|
||||
inline fun Flow<ChatEventMessage<*>>.successfulPaymentInGroupEvents() = filterGroupEvents<SuccessfulPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.successfulPaymentInGroupEvents() = filterGroupEvents<SuccessfulPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.refundedPaymentInGroupEvents() = filterGroupEvents<RefundedPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.refundedPaymentInGroupEvents() = filterGroupEvents<RefundedPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.groupEvents() = filterGroupEvents<GroupEvent>()
|
||||
|
||||
|
||||
@ -109,6 +114,8 @@ inline fun Flow<ChatEventMessage<*>>.proximityAlertTriggeredInSupergroupEvents()
|
||||
inline fun FlowsUpdatesFilter.proximityAlertTriggeredInSupergroupEvents() = filterSupergroupEvents<ProximityAlertTriggered>()
|
||||
inline fun Flow<ChatEventMessage<*>>.successfulPaymentInSupergroupEvents() = filterSupergroupEvents<SuccessfulPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.successfulPaymentInSupergroupEvents() = filterSupergroupEvents<SuccessfulPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.refundedPaymentInSupergroupEvents() = filterSupergroupEvents<RefundedPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.refundedPaymentInSupergroupEvents() = filterSupergroupEvents<RefundedPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.supergroupEvents() = filterSupergroupEvents<SupergroupEvent>()
|
||||
|
||||
@RiskFeature("Use with caution")
|
||||
@ -117,6 +124,8 @@ inline fun <reified T : PrivateEvent> Flow<ChatEventMessage<*>>.filterPrivateEve
|
||||
inline fun <reified T : PrivateEvent> FlowsUpdatesFilter.filterPrivateEvents() = privateEvents().filterByChatEvent<T, PrivateEventMessage<T>>()
|
||||
inline fun Flow<ChatEventMessage<*>>.successfulPaymentInPrivateEvents() = filterPrivateEvents<SuccessfulPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.successfulPaymentInPrivateEvents() = filterPrivateEvents<SuccessfulPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.refundedPaymentInPrivateEvents() = filterPrivateEvents<RefundedPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.refundedPaymentInPrivateEvents() = filterPrivateEvents<RefundedPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.newPrivatePinnedMessageEvents() = filterPrivateEvents<PinnedMessage>()
|
||||
inline fun FlowsUpdatesFilter.newPrivatePinnedMessageEvents() = filterPrivateEvents<PinnedMessage>()
|
||||
inline fun Flow<ChatEventMessage<*>>.privateEvents() = filterPrivateEvents<PrivateEvent>()
|
||||
|
@ -10,3 +10,4 @@ typealias QRTextReceivedEventHandler = WebApp.(String) -> Boolean
|
||||
typealias TextReceivedEventHandler = WebApp.(String) -> Unit
|
||||
typealias WriteAccessRequestedHandler = WebApp.(Boolean) -> Unit
|
||||
typealias ContactRequestedHandler = WebApp.(Boolean) -> Unit
|
||||
typealias onScanQRPopupClosedHandler = WebApp.() -> Unit
|
||||
|
@ -1,15 +1,16 @@
|
||||
package dev.inmo.tgbotapi.webapps
|
||||
|
||||
sealed class EventType(val typeName: String) {
|
||||
object ThemeChanged : EventType("themeChanged")
|
||||
object ViewportChanged : EventType("viewportChanged")
|
||||
object MainButtonClicked : EventType("mainButtonClicked")
|
||||
object BackButtonClicked : EventType("backButtonClicked")
|
||||
object SettingsButtonClicked : EventType("settingsButtonClicked")
|
||||
object InvoiceClosed : EventType("invoiceClosed")
|
||||
object PopupClosed : EventType("popupClosed")
|
||||
object QRTextReceived : EventType("qrTextReceived")
|
||||
object ClipboardTextReceived : EventType("clipboardTextReceived")
|
||||
object WriteAccessRequested : EventType("writeAccessRequested")
|
||||
object ContactRequested : EventType("contactRequested")
|
||||
data object ThemeChanged : EventType("themeChanged")
|
||||
data object ViewportChanged : EventType("viewportChanged")
|
||||
data object MainButtonClicked : EventType("mainButtonClicked")
|
||||
data object BackButtonClicked : EventType("backButtonClicked")
|
||||
data object SettingsButtonClicked : EventType("settingsButtonClicked")
|
||||
data object InvoiceClosed : EventType("invoiceClosed")
|
||||
data object PopupClosed : EventType("popupClosed")
|
||||
data object QRTextReceived : EventType("qrTextReceived")
|
||||
data object ClipboardTextReceived : EventType("clipboardTextReceived")
|
||||
data object WriteAccessRequested : EventType("writeAccessRequested")
|
||||
data object ContactRequested : EventType("contactRequested")
|
||||
data object ScanQRPopupClosed : EventType("scanQrPopupClosed")
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import dev.inmo.tgbotapi.webapps.cloud.CloudStorage
|
||||
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback
|
||||
import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo
|
||||
import dev.inmo.tgbotapi.webapps.popup.*
|
||||
import kotlin.js.Json
|
||||
|
||||
external class WebApp {
|
||||
val version: String
|
||||
@ -31,6 +30,10 @@ external class WebApp {
|
||||
val viewportHeight: Float
|
||||
val viewportStableHeight: Float
|
||||
|
||||
val isVerticalSwipesEnabled: Boolean
|
||||
fun enableVerticalSwipes()
|
||||
fun disableVerticalSwipes()
|
||||
|
||||
|
||||
val isClosingConfirmationEnabled: Boolean
|
||||
fun enableClosingConfirmation()
|
||||
@ -78,6 +81,8 @@ external class WebApp {
|
||||
internal fun onEventWithContactRequested(type: String, callback: (RequestStatus) -> Unit)
|
||||
@JsName("onEvent")
|
||||
internal fun onEventWithSettingsButtonClicked(type: String, callback: () -> Unit)
|
||||
@JsName("onEvent")
|
||||
internal fun onEventWithScanQRPopupClosed(type: String, callback: () -> Unit)
|
||||
|
||||
fun offEvent(type: String, callback: () -> Unit)
|
||||
@JsName("offEvent")
|
||||
@ -215,6 +220,18 @@ fun WebApp.onEvent(type: EventType.SettingsButtonClicked, eventHandler: EventHan
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The callback which should be used in case you want to turn off events handling
|
||||
*/
|
||||
fun WebApp.onEvent(type: EventType.ScanQRPopupClosed, eventHandler: EventHandler) = {
|
||||
eventHandler(js("this").unsafeCast<WebApp>())
|
||||
}.also {
|
||||
onEventWithScanQRPopupClosed(
|
||||
type.typeName,
|
||||
callback = it
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The callback which should be used in case you want to turn off events handling
|
||||
*/
|
||||
@ -259,6 +276,10 @@ fun WebApp.onWriteAccessRequested(eventHandler: WriteAccessRequestedHandler) = o
|
||||
* @return The callback which should be used in case you want to turn off events handling
|
||||
*/
|
||||
fun WebApp.onContactRequested(eventHandler: ContactRequestedHandler) = onEvent(EventType.ContactRequested, eventHandler)
|
||||
/**
|
||||
* @return The callback which should be used in case you want to turn off events handling
|
||||
*/
|
||||
fun WebApp.onScanQRPopupClosed(eventHandler: onScanQRPopupClosedHandler) = onEvent(EventType.ScanQRPopupClosed, eventHandler)
|
||||
|
||||
fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).checkWebAppData(
|
||||
initData,
|
||||
|
Loading…
Reference in New Issue
Block a user