mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-12-21 13:45:39 +00:00
Compare commits
10 Commits
acd602d6fa
...
2.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 0217f97014 | |||
| 4ae700b58a | |||
|
|
804fb1e5ee | ||
| d443c39813 | |||
|
|
cd96547d15 | ||
| f107b4144d | |||
| 39f4196b76 | |||
|
|
22b9776c26 | ||
| 2f8f6f3169 | |||
| f2b6a50cb5 |
@@ -20,11 +20,9 @@ suspend fun main(args: Array<String>) {
|
|||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onMedia(initialFilter = null) {
|
onMedia(initialFilter = null) {
|
||||||
val pathedFile = bot.getFileAdditionalInfo(it.content.media)
|
val pathedFile = bot.getFileAdditionalInfo(it.content.media)
|
||||||
val file = File(directoryOrFile, pathedFile.filePath.filenameFromUrl).apply {
|
val outFile = File(directoryOrFile, pathedFile.filePath.filenameFromUrl)
|
||||||
createNewFile()
|
bot.downloadFile(it.content.media, outFile)
|
||||||
writeBytes(bot.downloadFile(pathedFile))
|
reply(it, "Saved to ${outFile.absolutePath}")
|
||||||
}
|
|
||||||
reply(it, "Saved to ${file.absolutePath}")
|
|
||||||
}
|
}
|
||||||
onContentMessage { println(it) }
|
onContentMessage { println(it) }
|
||||||
}.second.join()
|
}.second.join()
|
||||||
|
|||||||
@@ -26,7 +26,13 @@ suspend fun main(vararg args: String) {
|
|||||||
is UserForwardInfo -> {
|
is UserForwardInfo -> {
|
||||||
val user = forwardInfo.from
|
val user = forwardInfo.from
|
||||||
when (user) {
|
when (user) {
|
||||||
is CommonUser -> regular("User ")
|
is CommonUser -> {
|
||||||
|
if (user.isPremium) {
|
||||||
|
regular("Premium user ")
|
||||||
|
} else {
|
||||||
|
regular("User ")
|
||||||
|
}
|
||||||
|
}
|
||||||
is CommonBot,
|
is CommonBot,
|
||||||
is ExtendedBot -> regular("Bot ")
|
is ExtendedBot -> regular("Bot ")
|
||||||
} + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username ?.username ?: "Without username"})"
|
} + code(user.id.chatId.toString()) + " (${user.firstName} ${user.lastName}: ${user.username ?.username ?: "Without username"})"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
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 dev.inmo.tgbotapi.webapps.haptic.HapticFeedbackStyle
|
||||||
|
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedbackType
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.bodyAsText
|
import io.ktor.client.statement.bodyAsText
|
||||||
@@ -15,8 +17,8 @@ import kotlinx.serialization.json.Json
|
|||||||
import org.w3c.dom.HTMLElement
|
import org.w3c.dom.HTMLElement
|
||||||
|
|
||||||
fun HTMLElement.log(text: String) {
|
fun HTMLElement.log(text: String) {
|
||||||
appendElement("p", {})
|
|
||||||
appendText(text)
|
appendText(text)
|
||||||
|
appendElement("p", {})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
@@ -39,13 +41,17 @@ fun main() {
|
|||||||
}
|
}
|
||||||
val dataIsSafe = response.bodyAsText().toBoolean()
|
val dataIsSafe = response.bodyAsText().toBoolean()
|
||||||
|
|
||||||
document.body ?.appendElement("div") {
|
document.body ?.log(
|
||||||
textContent = if (dataIsSafe) {
|
if (dataIsSafe) {
|
||||||
"Data is safe"
|
"Data is safe"
|
||||||
} else {
|
} else {
|
||||||
"Data is unsafe"
|
"Data is unsafe"
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
|
|
||||||
|
document.body ?.log(
|
||||||
|
webApp.initDataUnsafe.chat.toString()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body ?.appendElement("button") {
|
document.body ?.appendElement("button") {
|
||||||
@@ -69,6 +75,28 @@ fun main() {
|
|||||||
onViewportChanged {
|
onViewportChanged {
|
||||||
document.body ?.log("Viewport changed: ${it.isStateStable}")
|
document.body ?.log("Viewport changed: ${it.isStateStable}")
|
||||||
}
|
}
|
||||||
|
backButton.apply {
|
||||||
|
onClick {
|
||||||
|
document.body ?.log("Back button clicked")
|
||||||
|
hapticFeedback.impactOccurred(
|
||||||
|
HapticFeedbackStyle.Heavy
|
||||||
|
)
|
||||||
|
}
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
mainButton.apply {
|
||||||
|
setText("Main button")
|
||||||
|
onClick {
|
||||||
|
document.body ?.log("Main button clicked")
|
||||||
|
hapticFeedback.notificationOccurred(
|
||||||
|
HapticFeedbackType.Success
|
||||||
|
)
|
||||||
|
}
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
onSettingsButtonClicked {
|
||||||
|
document.body ?.log("Settings button clicked")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
webApp.ready()
|
webApp.ready()
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="format-detection" content="telephone=no"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
||||||
|
<meta name="HandheldFriendly" content="True"/>
|
||||||
|
<meta name="robots" content="noindex,nofollow"/>
|
||||||
|
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
|
||||||
<title>Web App Example</title>
|
<title>Web App Example</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx768m
|
|||||||
|
|
||||||
|
|
||||||
kotlin_version=1.6.21
|
kotlin_version=1.6.21
|
||||||
telegram_bot_api_version=2.0.1
|
telegram_bot_api_version=2.1.0
|
||||||
micro_utils_version=0.10.8
|
micro_utils_version=0.11.3
|
||||||
serialization_version=1.3.3
|
serialization_version=1.3.3
|
||||||
ktor_version=2.0.2
|
ktor_version=2.0.2
|
||||||
|
|||||||
Reference in New Issue
Block a user