mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-09-06 00:29:59 +00:00
start migration onto 0.38.20
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
||||
import dev.inmo.tgbotapi.webapps.*
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.client.statement.readText
|
||||
import io.ktor.http.encodeURLPath
|
||||
import io.ktor.http.*
|
||||
import io.ktor.http.content.TextContent
|
||||
import kotlinx.browser.document
|
||||
import kotlinx.browser.window
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.dom.appendElement
|
||||
import kotlinx.dom.appendText
|
||||
import org.w3c.dom.HTMLElement
|
||||
|
||||
fun main() {
|
||||
console.log("Web app started")
|
||||
@@ -16,12 +20,25 @@ fun main() {
|
||||
val scope = CoroutineScope(Dispatchers.Default)
|
||||
runCatching {
|
||||
document.body ?.appendElement("button") {
|
||||
addEventListener(
|
||||
"click",
|
||||
{
|
||||
webApp.sendData("Clicked")
|
||||
(this as HTMLElement).onclick = {
|
||||
scope.launchSafelyWithoutExceptions {
|
||||
HttpClient().post<HttpResponse>("${window.location.origin.removeSuffix("/")}/inline") {
|
||||
parameter(webAppQueryIdField, webApp.initDataUnsafe.queryId)
|
||||
body = "Clicked"
|
||||
contentType(ContentType.Text.Plain)
|
||||
}
|
||||
handleResult(
|
||||
{ "Clicked" }
|
||||
) {
|
||||
HttpClient().post<HttpResponse>(
|
||||
"${window.location.origin}/inline"
|
||||
) {
|
||||
parameter(webAppQueryIdField, it)
|
||||
body = "Clicked"
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
appendText("Example button")
|
||||
} ?: window.alert("Unable to load body")
|
||||
webApp.apply {
|
||||
|
Reference in New Issue
Block a user