1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-23 02:28:45 +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
external class MainButton {
external class BottomButton {
val text: String
fun setText(text: String): MainButton
fun setText(text: String): BottomButton
var color: String
var textColor: String
val isVisible: Boolean
fun show(): MainButton
fun hide(): MainButton
fun show(): BottomButton
fun hide(): BottomButton
val isActive: Boolean
fun enable(): MainButton
fun disable(): MainButton
fun enable(): BottomButton
fun disable(): BottomButton
val isProgressVisible: Boolean
fun showProgress(leaveActive: Boolean = definedExternally): MainButton
fun hideProgress(): MainButton
fun showProgress(leaveActive: Boolean = definedExternally): BottomButton
fun hideProgress(): BottomButton
/**
* **This method argument do not accept `this` [WebApp] object**
*/
fun onClick(eventHandler: () -> Unit): MainButton
fun offClick(eventHandler: () -> Unit): MainButton
fun onClick(eventHandler: () -> Unit): BottomButton
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 color: String? = null,
val textColor: String? = null,
@ -39,7 +39,7 @@ data class MainButtonParams(
val isVisible: Boolean? = null
)
fun MainButton.setParams(params: MainButtonParams) = setParams(
fun BottomButton.setParams(params: BottomButtonParams) = setParams(
json(
*listOfNotNull(
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
import dev.inmo.micro_utils.common.Warning
import kotlinx.serialization.Serializable
sealed interface Color {
val value: String
@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
value class Hex(override val value: String) : Color {
@ -15,6 +16,7 @@ sealed interface Color {
companion object {
val BackgroundColor = BackgroundColor("bg_color")
val SecondaryBackgroundColor = BackgroundColor("secondary_bg_color")
val BottomBarBackgroundColor = BackgroundColor("bottom_bar_bg_color")
@Suppress("NOTHING_TO_INLINE")
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 ViewportChanged : EventType("viewportChanged")
data object MainButtonClicked : EventType("mainButtonClicked")
data object SecondaryButtonClicked : EventType("secondaryButtonClicked")
data object BackButtonClicked : EventType("backButtonClicked")
data object SettingsButtonClicked : EventType("settingsButtonClicked")
data object InvoiceClosed : EventType("invoiceClosed")

View File

@ -19,10 +19,15 @@ external class WebApp {
val headerColor: HEXColor?
fun setHeaderColor(color: Color.BackgroundColor)
fun setHeaderColor(color: Color.Hex)
val backgroundColor: HEXColor?
fun setBackgroundColor(color: Color.Hex)
fun setBackgroundColor(color: Color.BackgroundColor)
val bottomBarColor: HEXColor?
fun setBottomBarColor(color: Color.Hex)
fun setBottomBarColor(color: Color.BackgroundColor)
@JsName("colorScheme")
val colorSchemeRaw: String
val themeParams: ThemeParams
@ -48,7 +53,9 @@ external class WebApp {
fun readTextFromClipboard(callback: TextReceivedCallback? = definedExternally)
@JsName("MainButton")
val mainButton: MainButton
val mainButton: BottomButton
@JsName("SecondaryButton")
val secondaryButton: BottomButton
@JsName("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
*/
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
*/