From c7d08df3bfaecabddb2cd8a7611459f6de0b2388 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Dec 2024 16:07:46 +0600 Subject: [PATCH] continue adding support of webapps updates --- .../requests/set/SetUserEmojiStatus.kt | 28 +++++++++++++++++++ .../tgbotapi/webapps/DownloadFileParams.kt | 16 +++++++++++ .../tgbotapi/webapps/EmojiStatusParams.kt | 13 +++++++++ .../dev/inmo/tgbotapi/webapps/WebApp.kt | 10 +++++-- 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/set/SetUserEmojiStatus.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/DownloadFileParams.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EmojiStatusParams.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/set/SetUserEmojiStatus.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/set/SetUserEmojiStatus.kt new file mode 100644 index 0000000000..60af40bdee --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/set/SetUserEmojiStatus.kt @@ -0,0 +1,28 @@ +package dev.inmo.tgbotapi.requests.set + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.builtins.serializer + +@Serializable +data class SetUserEmojiStatus( + @SerialName(userIdField) + val userId: UserId, + @SerialName(emojiStatusCustomEmojiIdField) + val customEmojiId: CustomEmojiId, + @Serializable(TelegramDateSerializer::class) + @SerialName(emojiStatusExpirationDateField) + val expirationDate: TelegramDate? = null +) : SimpleRequest { + override fun method(): String = "setUserEmojiStatus" + + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() +} \ No newline at end of file diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/DownloadFileParams.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/DownloadFileParams.kt new file mode 100644 index 0000000000..2bf289f140 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/DownloadFileParams.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.webapps + +import kotlin.js.json + +external interface DownloadFileParams { + val url: String + @JsName("file_name") + val fileName: String +} +fun DownloadFileParams( + url: String, + fileName: String +) = json( + "url" to url, + "file_name" to fileName +).unsafeCast() \ No newline at end of file diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EmojiStatusParams.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EmojiStatusParams.kt new file mode 100644 index 0000000000..7770bd96bc --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EmojiStatusParams.kt @@ -0,0 +1,13 @@ +package dev.inmo.tgbotapi.webapps + +import dev.inmo.tgbotapi.types.Seconds +import kotlin.js.json + +external interface EmojiStatusParams { + val duration: Seconds? +} +fun EmojiStatusParams( + duration: Seconds +): EmojiStatusParams = json( + "duration" to duration +).unsafeCast() diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt index 4d6c659b0f..a79909b8ec 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.webapps +import dev.inmo.tgbotapi.types.CustomEmojiId import dev.inmo.tgbotapi.types.PreparedMessageId import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper import dev.inmo.tgbotapi.webapps.accelerometer.Accelerometer @@ -71,8 +72,6 @@ external class WebApp { fun addToHomeScreen() fun checkHomeScreenStatus(callback: (HomeScreenStatus) -> Unit = definedExternally) - fun shareMessage(messageId: PreparedMessageId, callback: (Boolean) -> Unit = definedExternally) - @JsName("MainButton") val mainButton: BottomButton @JsName("SecondaryButton") @@ -144,6 +143,13 @@ external class WebApp { fun shareToStory(mediaUrl: String, params: StoryShareParams? = definedExternally) + fun shareMessage(messageId: PreparedMessageId, callback: (Boolean) -> Unit = definedExternally) + + fun setEmojiStatus(customEmojiId: CustomEmojiId, params: EmojiStatusParams = definedExternally, callback: (Boolean) -> Unit = definedExternally) + fun requestEmojiStatusAccess(callback: (Boolean) -> Unit = definedExternally) + + fun downloadFile(params: DownloadFileParams, callback: (Boolean) -> Unit = definedExternally) + fun requestWriteAccess(callback: ((Boolean) -> Unit)? = definedExternally) fun requestContact(callback: ((Boolean) -> Unit)? = definedExternally) }