start migration onto 0.38.20

This commit is contained in:
2022-05-04 12:22:49 +06:00
parent bf0c6497fe
commit df778b4e93
3 changed files with 66 additions and 13 deletions

View File

@@ -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 {