mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-12-19 04:35:55 +00:00
Compare commits
18 Commits
1.1.1
...
2f8f6f3169
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f8f6f3169 | |||
| f2b6a50cb5 | |||
| acd602d6fa | |||
| fdb80bf471 | |||
|
|
78c58db4b7 | ||
| edd6399bcc | |||
|
|
9513e77ba3 | ||
|
|
ac75f6487e | ||
| 07750a71c0 | |||
| 0bf7e33df3 | |||
| 7fb308ea4b | |||
|
|
75b403ac98 | ||
| 5976e37046 | |||
|
|
c8a94496c7 | ||
| f6550bd401 | |||
| 389d96f323 | |||
| 803c5fd664 | |||
| b6eb4fe134 |
@@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.types.ChatId
|
|||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
||||||
sealed interface BotState : State
|
sealed interface BotState : State
|
||||||
data class ExpectContentOrStopState(override val context: ChatId, val sourceMessage: CommonMessage<TextContent>) : BotState
|
data class ExpectContentOrStopState(override val context: ChatId, val sourceMessage: CommonMessage<TextContent>) : BotState
|
||||||
@@ -18,7 +19,22 @@ data class StopState(override val context: ChatId) : BotState
|
|||||||
suspend fun main(args: Array<String>) {
|
suspend fun main(args: Array<String>) {
|
||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
telegramBotWithBehaviourAndFSMAndStartLongPolling<BotState>(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndFSMAndStartLongPolling<BotState>(
|
||||||
|
botToken,
|
||||||
|
CoroutineScope(Dispatchers.IO),
|
||||||
|
onStateHandlingErrorHandler = { state, e ->
|
||||||
|
when (state) {
|
||||||
|
is ExpectContentOrStopState -> {
|
||||||
|
println("Thrown error on ExpectContentOrStopState")
|
||||||
|
}
|
||||||
|
is StopState -> {
|
||||||
|
println("Thrown error on StopState")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.printStackTrace()
|
||||||
|
state
|
||||||
|
}
|
||||||
|
) {
|
||||||
strictlyOn<ExpectContentOrStopState> {
|
strictlyOn<ExpectContentOrStopState> {
|
||||||
sendMessage(
|
sendMessage(
|
||||||
it.context,
|
it.context,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import dev.inmo.micro_utils.common.filesize
|
||||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
@@ -64,9 +65,9 @@ suspend fun main(args: Array<String>) {
|
|||||||
val chosen = mutableListOf<File>()
|
val chosen = mutableListOf<File>()
|
||||||
|
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
left--
|
val picked = pickFile() ?.takeIf { it.filesize > 0 } ?: continue
|
||||||
val picked = pickFile() ?: continue
|
|
||||||
chosen.add(picked)
|
chosen.add(picked)
|
||||||
|
left--
|
||||||
if (chosen.size >= mediaCountInMediaGroup.last) {
|
if (chosen.size >= mediaCountInMediaGroup.last) {
|
||||||
sendFiles(message.chat, chosen)
|
sendFiles(message.chat, chosen)
|
||||||
chosen.clear()
|
chosen.clear()
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ suspend fun main(vararg args: String) {
|
|||||||
val requestBody = call.receiveText()
|
val requestBody = call.receiveText()
|
||||||
val webAppCheckData = Json { }.decodeFromString(WebAppDataWrapper.serializer(), requestBody)
|
val webAppCheckData = Json { }.decodeFromString(WebAppDataWrapper.serializer(), requestBody)
|
||||||
|
|
||||||
val isSafe = telegramBotAPIUrlsKeeper.checkWebAppLink(webAppCheckData.data, webAppCheckData.hash)
|
val isSafe = telegramBotAPIUrlsKeeper.checkWebAppData(webAppCheckData.data, webAppCheckData.hash)
|
||||||
|
|
||||||
call.respond(HttpStatusCode.OK, isSafe.toString())
|
call.respond(HttpStatusCode.OK, isSafe.toString())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx768m
|
|||||||
|
|
||||||
|
|
||||||
kotlin_version=1.6.21
|
kotlin_version=1.6.21
|
||||||
telegram_bot_api_version=1.1.1
|
telegram_bot_api_version=2.0.1
|
||||||
micro_utils_version=0.10.4
|
micro_utils_version=0.10.8
|
||||||
serialization_version=1.3.3
|
serialization_version=1.3.3
|
||||||
ktor_version=2.0.1
|
ktor_version=2.0.2
|
||||||
|
|||||||
Reference in New Issue
Block a user