From 010c52adebe5ffea138e30afb8b733852c5d3b43 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 1 Aug 2024 17:26:18 +0600 Subject: [PATCH] add shareToStory in WebApp --- .../kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt | 3 +++ .../webapps/stories/StoryShareParams.kt | 7 +++++++ .../webapps/stories/StoryWidgetLink.kt | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/stories/StoryShareParams.kt create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/stories/StoryWidgetLink.kt 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 47465ef96b..f205ae37e9 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 @@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.webapps.cloud.CloudStorage import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo import dev.inmo.tgbotapi.webapps.popup.* +import dev.inmo.tgbotapi.webapps.stories.StoryShareParams external class WebApp { val version: String @@ -101,6 +102,8 @@ external class WebApp { fun openTelegramLink(url: String) fun openInvoice(url: String, callback: (InvoiceClosedInfo) -> Unit = definedExternally) + fun shareToStory(mediaUrl: String, params: StoryShareParams?) + fun requestWriteAccess(callback: ((Boolean) -> Unit)? = definedExternally) fun requestContact(callback: ((Boolean) -> Unit)? = definedExternally) } diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/stories/StoryShareParams.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/stories/StoryShareParams.kt new file mode 100644 index 0000000000..2ecb275909 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/stories/StoryShareParams.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.webapps.stories + +external interface StoryShareParams { + val text: String + @JsName("widget_link") + val widgetLink: StoryWidgetLink? +} \ No newline at end of file diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/stories/StoryWidgetLink.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/stories/StoryWidgetLink.kt new file mode 100644 index 0000000000..61ee95a034 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/stories/StoryWidgetLink.kt @@ -0,0 +1,18 @@ +package dev.inmo.tgbotapi.webapps.stories + +import kotlin.js.json + +external interface StoryWidgetLink { + val url: String + val name: String? +} + +fun StoryWidgetLink( + url: String, + name: String? +): StoryWidgetLink { + val result: dynamic = js("{}") + result["url"] = url + name ?.let { result["name"] = it } + return result.unsafeCast() +}