1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 00:03:48 +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.utils.TelegramAPIUrlsKeeper
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback
import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo
import dev.inmo.tgbotapi.webapps.popup.ClosePopupCallback import dev.inmo.tgbotapi.webapps.popup.*
import dev.inmo.tgbotapi.webapps.popup.PopupParams
external class WebApp { external class WebApp {
val version: String val version: String
@ -158,3 +157,32 @@ fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).ch
initData, initData,
initDataUnsafe.hash 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 package dev.inmo.tgbotapi.webapps.popup
external class PopupButton( import kotlin.js.json
id: String,
type: String, external interface PopupButton {
text: String? = definedExternally
) {
val id: String val id: String
val type: String val type: PopupButtonType
val text: String? 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( value class PopupButtonType(
val typeName: String val typeName: String
) { ) {
@ -25,21 +35,21 @@ value class PopupButtonType(
fun DefaultPopupButton( fun DefaultPopupButton(
id: String, id: String,
text: String text: String
) = PopupButton(id, PopupButtonType.Default.typeName, text) ) = PopupButton(id, PopupButtonType.Default, text)
fun OkPopupButton( fun OkPopupButton(
id: String id: String
) = PopupButton(id, PopupButtonType.Ok.typeName) ) = PopupButton(id, PopupButtonType.Ok)
fun ClosePopupButton( fun ClosePopupButton(
id: String id: String
) = PopupButton(id, PopupButtonType.Close.typeName) ) = PopupButton(id, PopupButtonType.Close)
fun CancelPopupButton( fun CancelPopupButton(
id: String id: String
) = PopupButton(id, PopupButtonType.Cancel.typeName) ) = PopupButton(id, PopupButtonType.Cancel)
fun DestructivePopupButton( fun DestructivePopupButton(
id: String, id: String,
text: 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 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, message: String,
title: String?, title: String?,
buttons: Array<PopupButton> buttons: Array<PopupButton>
) { ) = json(
val title: String? *listOfNotNull(
} "message" to message,
"buttons" to buttons,
("title" to title).takeIf { title != null }
).toTypedArray()
).unsafeCast<PopupParams>()
fun PopupParams( fun PopupParams(
message: String, message: String,