mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-22 16:23:54 +00:00
fixes
This commit is contained in:
parent
df778b4e93
commit
831b558724
@ -38,7 +38,7 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
implementation "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||||
implementation "dev.inmo:micro_utils.ktor.server:$micro_utils_version"
|
implementation "dev.inmo:micro_utils.ktor.server:$micro_utils_version"
|
||||||
implementation "io.ktor:ktor-server-tomcat:$ktor_version"
|
implementation "io.ktor:ktor-server-cio:$ktor_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
|||||||
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
||||||
import dev.inmo.tgbotapi.webapps.*
|
import dev.inmo.tgbotapi.webapps.*
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.client.call.receive
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.HttpResponse
|
import io.ktor.client.statement.HttpResponse
|
||||||
import io.ktor.client.statement.readText
|
import io.ktor.client.statement.readText
|
||||||
@ -14,41 +15,36 @@ import kotlinx.dom.appendElement
|
|||||||
import kotlinx.dom.appendText
|
import kotlinx.dom.appendText
|
||||||
import org.w3c.dom.HTMLElement
|
import org.w3c.dom.HTMLElement
|
||||||
|
|
||||||
|
fun HTMLElement.log(text: String) {
|
||||||
|
appendElement("p", {})
|
||||||
|
appendText(text)
|
||||||
|
}
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
console.log("Web app started")
|
console.log("Web app started")
|
||||||
window.onload = {
|
window.onload = {
|
||||||
val scope = CoroutineScope(Dispatchers.Default)
|
val scope = CoroutineScope(Dispatchers.Default)
|
||||||
runCatching {
|
runCatching {
|
||||||
document.body ?.appendElement("button") {
|
document.body ?.appendElement("button") {
|
||||||
(this as HTMLElement).onclick = {
|
addEventListener("click", {
|
||||||
scope.launchSafelyWithoutExceptions {
|
scope.launchSafelyWithoutExceptions {
|
||||||
|
handleResult({ "Clicked" }) {
|
||||||
HttpClient().post<HttpResponse>("${window.location.origin.removeSuffix("/")}/inline") {
|
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)
|
parameter(webAppQueryIdField, it)
|
||||||
body = "Clicked"
|
body = TextContent("Clicked", ContentType.Text.Plain)
|
||||||
}
|
document.body ?.log(url.build().toString())
|
||||||
}
|
}.coroutineContext.job.join()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
appendText("Example button")
|
appendText("Example button")
|
||||||
} ?: window.alert("Unable to load body")
|
} ?: window.alert("Unable to load body")
|
||||||
webApp.apply {
|
webApp.apply {
|
||||||
onThemeChanged {
|
onThemeChanged {
|
||||||
document.body ?.appendText("Theme changed: ${webApp.themeParams}")
|
document.body ?.log("Theme changed: ${webApp.themeParams}")
|
||||||
document.body ?.appendElement("p", {})
|
|
||||||
}
|
}
|
||||||
onViewportChanged {
|
onViewportChanged {
|
||||||
document.body ?.appendText("Viewport changed: ${it.isStateStable}")
|
document.body ?.log("Viewport changed: ${it.isStateStable}")
|
||||||
document.body ?.appendElement("p", {})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
webApp.ready()
|
webApp.ready()
|
||||||
|
@ -19,8 +19,6 @@ import io.ktor.http.content.*
|
|||||||
import io.ktor.request.receiveText
|
import io.ktor.request.receiveText
|
||||||
import io.ktor.response.respond
|
import io.ktor.response.respond
|
||||||
import io.ktor.routing.*
|
import io.ktor.routing.*
|
||||||
import io.ktor.server.tomcat.Tomcat
|
|
||||||
import io.ktor.utils.io.readRemaining
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -35,7 +33,6 @@ import java.io.File
|
|||||||
suspend fun main(vararg args: String) {
|
suspend fun main(vararg args: String) {
|
||||||
val bot = telegramBot(args.first(), testServer = args.any { it == "testServer" })
|
val bot = telegramBot(args.first(), testServer = args.any { it == "testServer" })
|
||||||
createKtorServer(
|
createKtorServer(
|
||||||
Tomcat,
|
|
||||||
"0.0.0.0",
|
"0.0.0.0",
|
||||||
8080,
|
8080,
|
||||||
additionalEngineEnvironmentConfigurator = {
|
additionalEngineEnvironmentConfigurator = {
|
||||||
|
@ -3,6 +3,6 @@ org.gradle.parallel=true
|
|||||||
|
|
||||||
|
|
||||||
kotlin_version=1.6.10
|
kotlin_version=1.6.10
|
||||||
telegram_bot_api_version=0.38.20
|
telegram_bot_api_version=0.38.21
|
||||||
micro_utils_version=0.9.24
|
micro_utils_version=0.9.24
|
||||||
ktor_version=1.6.8
|
ktor_version=1.6.8
|
||||||
|
Loading…
Reference in New Issue
Block a user