1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-09-19 09:06:09 +00:00

Bot API 7.7

implemented scanQrPopupClosed event
This commit is contained in:
bpavuk 2024-07-07 19:48:37 +03:00
parent 6edf466220
commit cb33176e8b
2 changed files with 19 additions and 1 deletions

View File

@ -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")
}

View File

@ -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<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 +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,