From cb33176e8b0f0d95b86422744b849545256543f8 Mon Sep 17 00:00:00 2001 From: bpavuk Date: Sun, 7 Jul 2024 19:48:37 +0300 Subject: [PATCH] Bot API 7.7 implemented scanQrPopupClosed event --- .../dev/inmo/tgbotapi/webapps/EventType.kt | 1 + .../dev/inmo/tgbotapi/webapps/WebApp.kt | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt index d40cd1cb85..fc2b32ecc4 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventType.kt @@ -12,4 +12,5 @@ sealed class EventType(val typeName: String) { object ClipboardTextReceived : EventType("clipboardTextReceived") object WriteAccessRequested : EventType("writeAccessRequested") object ContactRequested : EventType("contactRequested") + object ScanQRPopupClosed : EventType("scanQrPopupClosed") } diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt index fe8738feb9..25cbc020d2 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt @@ -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 @@ -78,6 +77,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 +216,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()) +}.also { + onEventWithScanQRPopupClosed( + type.typeName, + callback = it + ) +} + /** * @return The callback which should be used in case you want to turn off events handling */ @@ -259,6 +272,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: EventHandler) = onEvent(EventType.ScanQRPopupClosed, eventHandler) fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).checkWebAppData( initData,