1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

fixes in popup params and buttons

This commit is contained in:
InsanusMokrassar 2022-08-15 01:20:29 +06:00
parent 69dde19543
commit a08d07f7b3
3 changed files with 67 additions and 17 deletions

View File

@ -3,8 +3,7 @@ package dev.inmo.tgbotapi.webapps
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback
import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo
import dev.inmo.tgbotapi.webapps.popup.ClosePopupCallback
import dev.inmo.tgbotapi.webapps.popup.PopupParams
import dev.inmo.tgbotapi.webapps.popup.*
external class WebApp {
val version: String
@ -158,3 +157,32 @@ fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).ch
initData,
initDataUnsafe.hash
)
fun WebApp.showPopup(
message: String,
title: String?,
buttons: Array<PopupButton>,
callback: ClosePopupCallback? = null
) = showPopup(
PopupParams(
message,
title,
buttons
),
callback
)
fun WebApp.showPopup(
message: String,
title: String?,
firstButton: PopupButton,
vararg otherButtons: PopupButton,
callback: ClosePopupCallback? = null
) = showPopup(
PopupParams(
message,
title,
arrayOf(firstButton, *otherButtons)
),
callback
)

View File

@ -1,15 +1,25 @@
package dev.inmo.tgbotapi.webapps.popup
external class PopupButton(
id: String,
type: String,
text: String? = definedExternally
) {
import kotlin.js.json
external interface PopupButton {
val id: String
val type: String
val type: PopupButtonType
val text: String?
}
fun PopupButton(
id: String,
type: PopupButtonType,
text: String? = null
) = json(
*listOfNotNull(
"id" to id,
"type" to type.typeName,
("text" to text).takeIf { text != null }
).toTypedArray()
).unsafeCast<PopupButton>()
value class PopupButtonType(
val typeName: String
) {
@ -25,21 +35,21 @@ value class PopupButtonType(
fun DefaultPopupButton(
id: String,
text: String
) = PopupButton(id, PopupButtonType.Default.typeName, text)
) = PopupButton(id, PopupButtonType.Default, text)
fun OkPopupButton(
id: String
) = PopupButton(id, PopupButtonType.Ok.typeName)
) = PopupButton(id, PopupButtonType.Ok)
fun ClosePopupButton(
id: String
) = PopupButton(id, PopupButtonType.Close.typeName)
) = PopupButton(id, PopupButtonType.Close)
fun CancelPopupButton(
id: String
) = PopupButton(id, PopupButtonType.Cancel.typeName)
) = PopupButton(id, PopupButtonType.Cancel)
fun DestructivePopupButton(
id: String,
text: String
) = PopupButton(id, PopupButtonType.Destructive.typeName, text)
) = PopupButton(id, PopupButtonType.Destructive, text)

View File

@ -1,12 +1,24 @@
package dev.inmo.tgbotapi.webapps.popup
external class PopupParams(
import kotlin.js.json
external interface PopupParams {
val message: String
val title: String?
val buttons: Array<PopupButton>
}
fun PopupParams(
message: String,
title: String?,
buttons: Array<PopupButton>
) {
val title: String?
}
) = json(
*listOfNotNull(
"message" to message,
"buttons" to buttons,
("title" to title).takeIf { title != null }
).toTypedArray()
).unsafeCast<PopupParams>()
fun PopupParams(
message: String,