1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-23 10:38:43 +00:00

potentially complete implementation of Bot API 7.10

This commit is contained in:
InsanusMokrassar 2024-09-07 00:19:33 +06:00
parent 5d8deb4b9b
commit b60b0259db
4 changed files with 32 additions and 15 deletions

View File

@ -3,35 +3,35 @@ package dev.inmo.tgbotapi.webapps
import kotlin.js.Json import kotlin.js.Json
import kotlin.js.json import kotlin.js.json
external class MainButton { external class BottomButton {
val text: String val text: String
fun setText(text: String): MainButton fun setText(text: String): BottomButton
var color: String var color: String
var textColor: String var textColor: String
val isVisible: Boolean val isVisible: Boolean
fun show(): MainButton fun show(): BottomButton
fun hide(): MainButton fun hide(): BottomButton
val isActive: Boolean val isActive: Boolean
fun enable(): MainButton fun enable(): BottomButton
fun disable(): MainButton fun disable(): BottomButton
val isProgressVisible: Boolean val isProgressVisible: Boolean
fun showProgress(leaveActive: Boolean = definedExternally): MainButton fun showProgress(leaveActive: Boolean = definedExternally): BottomButton
fun hideProgress(): MainButton fun hideProgress(): BottomButton
/** /**
* **This method argument do not accept `this` [WebApp] object** * **This method argument do not accept `this` [WebApp] object**
*/ */
fun onClick(eventHandler: () -> Unit): MainButton fun onClick(eventHandler: () -> Unit): BottomButton
fun offClick(eventHandler: () -> Unit): MainButton fun offClick(eventHandler: () -> Unit): BottomButton
internal fun setParams(params: Json): MainButton internal fun setParams(params: Json): BottomButton
} }
data class MainButtonParams( data class BottomButtonParams(
val text: String? = null, val text: String? = null,
val color: String? = null, val color: String? = null,
val textColor: String? = null, val textColor: String? = null,
@ -39,7 +39,7 @@ data class MainButtonParams(
val isVisible: Boolean? = null val isVisible: Boolean? = null
) )
fun MainButton.setParams(params: MainButtonParams) = setParams( fun BottomButton.setParams(params: BottomButtonParams) = setParams(
json( json(
*listOfNotNull( *listOfNotNull(
params.text ?.let { "text" to params.text }, params.text ?.let { "text" to params.text },
@ -51,4 +51,7 @@ fun MainButton.setParams(params: MainButtonParams) = setParams(
) )
) )
@Deprecated("Renamed in telegram api", ReplaceWith("BottomButton", "dev.inmo.tgbotapi.webapps.BottomButton"))
typealias MainButton = BottomButton

View File

@ -1,11 +1,12 @@
package dev.inmo.tgbotapi.webapps package dev.inmo.tgbotapi.webapps
import dev.inmo.micro_utils.common.Warning
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
sealed interface Color { sealed interface Color {
val value: String val value: String
@Serializable @Serializable
value class BackgroundColor(override val value: String) : Color value class BackgroundColor @Warning("This constructor is not supposed to be called ouside of ktgbotapi library") constructor (override val value: String) : Color
@Serializable @Serializable
value class Hex(override val value: String) : Color { value class Hex(override val value: String) : Color {
@ -15,6 +16,7 @@ sealed interface Color {
companion object { companion object {
val BackgroundColor = BackgroundColor("bg_color") val BackgroundColor = BackgroundColor("bg_color")
val SecondaryBackgroundColor = BackgroundColor("secondary_bg_color") val SecondaryBackgroundColor = BackgroundColor("secondary_bg_color")
val BottomBarBackgroundColor = BackgroundColor("bottom_bar_bg_color")
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline operator fun invoke(value: String) = Hex(value) inline operator fun invoke(value: String) = Hex(value)

View File

@ -4,6 +4,7 @@ sealed class EventType(val typeName: String) {
data object ThemeChanged : EventType("themeChanged") data object ThemeChanged : EventType("themeChanged")
data object ViewportChanged : EventType("viewportChanged") data object ViewportChanged : EventType("viewportChanged")
data object MainButtonClicked : EventType("mainButtonClicked") data object MainButtonClicked : EventType("mainButtonClicked")
data object SecondaryButtonClicked : EventType("secondaryButtonClicked")
data object BackButtonClicked : EventType("backButtonClicked") data object BackButtonClicked : EventType("backButtonClicked")
data object SettingsButtonClicked : EventType("settingsButtonClicked") data object SettingsButtonClicked : EventType("settingsButtonClicked")
data object InvoiceClosed : EventType("invoiceClosed") data object InvoiceClosed : EventType("invoiceClosed")

View File

@ -19,10 +19,15 @@ external class WebApp {
val headerColor: HEXColor? val headerColor: HEXColor?
fun setHeaderColor(color: Color.BackgroundColor) fun setHeaderColor(color: Color.BackgroundColor)
fun setHeaderColor(color: Color.Hex) fun setHeaderColor(color: Color.Hex)
val backgroundColor: HEXColor? val backgroundColor: HEXColor?
fun setBackgroundColor(color: Color.Hex) fun setBackgroundColor(color: Color.Hex)
fun setBackgroundColor(color: Color.BackgroundColor) fun setBackgroundColor(color: Color.BackgroundColor)
val bottomBarColor: HEXColor?
fun setBottomBarColor(color: Color.Hex)
fun setBottomBarColor(color: Color.BackgroundColor)
@JsName("colorScheme") @JsName("colorScheme")
val colorSchemeRaw: String val colorSchemeRaw: String
val themeParams: ThemeParams val themeParams: ThemeParams
@ -48,7 +53,9 @@ external class WebApp {
fun readTextFromClipboard(callback: TextReceivedCallback? = definedExternally) fun readTextFromClipboard(callback: TextReceivedCallback? = definedExternally)
@JsName("MainButton") @JsName("MainButton")
val mainButton: MainButton val mainButton: BottomButton
@JsName("SecondaryButton")
val secondaryButton: BottomButton
@JsName("BackButton") @JsName("BackButton")
val backButton: BackButton val backButton: BackButton
@ -243,6 +250,10 @@ fun WebApp.onThemeChanged(eventHandler: EventHandler) = onEvent(EventType.ThemeC
* @return The callback which should be used in case you want to turn off events handling * @return The callback which should be used in case you want to turn off events handling
*/ */
fun WebApp.onMainButtonClicked(eventHandler: EventHandler) = onEvent(EventType.MainButtonClicked, eventHandler) fun WebApp.onMainButtonClicked(eventHandler: EventHandler) = onEvent(EventType.MainButtonClicked, eventHandler)
/**
* @return The callback which should be used in case you want to turn off events handling
*/
fun WebApp.onSecondaryButtonClicked(eventHandler: EventHandler) = onEvent(EventType.SecondaryButtonClicked, eventHandler)
/** /**
* @return The callback which should be used in case you want to turn off events handling * @return The callback which should be used in case you want to turn off events handling
*/ */