mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2025-06-30 14:07:30 +00:00
start migration onto 25.0.0
This commit is contained in:
InlineQueriesBot
KeyboardsBot/KeyboardsBotLib/src/commonMain/kotlin
RandomFileSenderBot
ResenderBot/ResenderBotLib/src/commonMain/kotlin
StickerInfoBot/StickerInfoBotLib/src/commonMain/kotlin
WebApp
gradle.properties@ -12,14 +12,16 @@ plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
}
|
||||
|
||||
apply plugin: 'application'
|
||||
|
||||
mainClassName="InlineQueriesBotKt"
|
||||
|
||||
apply from: "$nativePartTemplate"
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm {
|
||||
binaries {
|
||||
executable {
|
||||
mainClass.set("InlineQueriesBotKt")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
@ -27,12 +29,9 @@ kotlin {
|
||||
implementation kotlin('stdlib')
|
||||
|
||||
api "dev.inmo:tgbotapi:$telegram_bot_api_version"
|
||||
api "io.ktor:ktor-client-logging:$ktor_version"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'io.ktor:ktor-client-logging-jvm:3.1.0'
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.coroutines.subscribeLoggingDropExceptions
|
||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||
@ -59,7 +59,7 @@ suspend fun doInlineQueriesBot(token: String) {
|
||||
reply(message, deepLink)
|
||||
}
|
||||
|
||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||
allUpdatesFlow.subscribeLoggingDropExceptions(scope = this) {
|
||||
println(it)
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.coroutines.subscribeLoggingDropExceptions
|
||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||
@ -89,7 +89,7 @@ suspend fun activateKeyboardsBot(
|
||||
onCommandWithArgs("inline") { message, args ->
|
||||
val numberArgs = args.mapNotNull { it.toIntOrNull() }
|
||||
val numberOfPages = numberArgs.getOrNull(1) ?: numberArgs.firstOrNull() ?: 10
|
||||
val page = numberArgs.firstOrNull() ?.takeIf { numberArgs.size > 1 } ?.coerceAtLeast(1) ?: 1
|
||||
val page = numberArgs.firstOrNull()?.takeIf { numberArgs.size > 1 }?.coerceAtLeast(1) ?: 1
|
||||
reply(
|
||||
message,
|
||||
replyMarkup = inlineKeyboard {
|
||||
@ -138,7 +138,8 @@ suspend fun activateKeyboardsBot(
|
||||
|
||||
onBaseInlineQuery {
|
||||
val page = it.query.takeWhile { it.isDigit() }.toIntOrNull() ?: return@onBaseInlineQuery
|
||||
val count = it.query.removePrefix(page.toString()).dropWhile { !it.isDigit() }.takeWhile { it.isDigit() }.toIntOrNull() ?: return@onBaseInlineQuery
|
||||
val count = it.query.removePrefix(page.toString()).dropWhile { !it.isDigit() }.takeWhile { it.isDigit() }
|
||||
.toIntOrNull() ?: return@onBaseInlineQuery
|
||||
|
||||
answer(
|
||||
it,
|
||||
@ -170,7 +171,7 @@ suspend fun activateKeyboardsBot(
|
||||
|
||||
setMyCommands(BotCommand("inline", "Creates message with pagination inline keyboard"))
|
||||
|
||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||
allUpdatesFlow.subscribeLoggingDropExceptions(scope = this) {
|
||||
println(it)
|
||||
}
|
||||
}.join()
|
||||
|
@ -12,12 +12,14 @@ plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
}
|
||||
|
||||
apply plugin: 'application'
|
||||
|
||||
mainClassName="RandomFileSenderBotKt"
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm {
|
||||
binaries {
|
||||
executable {
|
||||
mainClass.set("RandomFileSenderBotKt")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.coroutines.subscribeLoggingDropExceptions
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||
import dev.inmo.tgbotapi.extensions.api.send.withTypingAction
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.filters.MessageFilterByChat
|
||||
@ -31,15 +31,15 @@ suspend fun activateResenderBot(
|
||||
it.content.createResend(
|
||||
chat.id,
|
||||
messageThreadId = it.threadIdOrNull,
|
||||
replyParameters = it.replyInfo ?.messageMeta ?.let { meta ->
|
||||
val quote = it.withContentOrNull<TextContent>() ?.content ?.quote
|
||||
replyParameters = it.replyInfo?.messageMeta?.let { meta ->
|
||||
val quote = it.withContentOrNull<TextContent>()?.content?.quote
|
||||
ReplyParameters(
|
||||
meta,
|
||||
entities = quote ?.textSources ?: emptyList(),
|
||||
quotePosition = quote ?.position
|
||||
entities = quote?.textSources ?: emptyList(),
|
||||
quotePosition = quote?.position
|
||||
)
|
||||
},
|
||||
effectId = it.possiblyWithEffectMessageOrNull() ?.effectId
|
||||
effectId = it.possiblyWithEffectMessageOrNull()?.effectId
|
||||
)
|
||||
) {
|
||||
it.forEach(print)
|
||||
@ -49,7 +49,7 @@ suspend fun activateResenderBot(
|
||||
println("Answer info: $answer")
|
||||
}
|
||||
|
||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||
allUpdatesFlow.subscribeLoggingDropExceptions(scope = this) {
|
||||
println(it)
|
||||
}
|
||||
print(bot.getMe())
|
||||
|
@ -1,5 +1,5 @@
|
||||
import dev.inmo.micro_utils.coroutines.defaultSafelyWithoutExceptionHandler
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.coroutines.subscribeLoggingDropExceptions
|
||||
import dev.inmo.tgbotapi.bot.ktor.telegramBot
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||
import dev.inmo.tgbotapi.extensions.api.get.getCustomEmojiStickerOrNull
|
||||
@ -55,7 +55,7 @@ suspend fun activateStickerInfoBot(
|
||||
withTypingAction(it.chat) {
|
||||
it.content.textSources.mapNotNull {
|
||||
if (it is CustomEmojiTextSource) {
|
||||
getCustomEmojiStickerOrNull(it.customEmojiId) ?.stickerSetName
|
||||
getCustomEmojiStickerOrNull(it.customEmojiId)?.stickerSetName
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@ -76,7 +76,7 @@ suspend fun activateStickerInfoBot(
|
||||
)
|
||||
}
|
||||
|
||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||
allUpdatesFlow.subscribeLoggingDropExceptions(scope = this) {
|
||||
println(it)
|
||||
}
|
||||
}.join()
|
||||
|
@ -16,10 +16,14 @@ plugins {
|
||||
id "org.jetbrains.compose" version "$compose_version"
|
||||
}
|
||||
|
||||
apply plugin: 'application'
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm {
|
||||
binaries {
|
||||
executable {
|
||||
mainClass.set("WebAppServerKt")
|
||||
}
|
||||
}
|
||||
}
|
||||
js(IR) {
|
||||
browser()
|
||||
binaries.executable()
|
||||
@ -53,10 +57,6 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = "WebAppServerKt"
|
||||
}
|
||||
|
||||
tasks.getByName("compileKotlinJvm")
|
||||
.dependsOn(jsBrowserDistribution)
|
||||
tasks.getByName("compileKotlinJvm").configure {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import androidx.compose.runtime.*
|
||||
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||
import dev.inmo.tgbotapi.types.CustomEmojiId
|
||||
import dev.inmo.tgbotapi.types.userIdField
|
||||
@ -110,7 +111,7 @@ fun main() {
|
||||
userId ?.let { userId ->
|
||||
Button({
|
||||
onClick {
|
||||
scope.launchSafelyWithoutExceptions {
|
||||
scope.launchLoggingDropExceptions {
|
||||
client.post("$baseUrl/setCustomEmoji") {
|
||||
parameter(userIdField, userId.long)
|
||||
setBody(
|
||||
@ -130,7 +131,7 @@ fun main() {
|
||||
|
||||
Button({
|
||||
onClick {
|
||||
scope.launchSafelyWithoutExceptions {
|
||||
scope.launchLoggingDropExceptions {
|
||||
handleResult({ "Clicked" }) {
|
||||
client.post("${window.location.origin.removeSuffix("/")}/inline") {
|
||||
parameter(webAppQueryIdField, it)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import dev.inmo.kslog.common.*
|
||||
import dev.inmo.micro_utils.coroutines.subscribeLoggingDropExceptions
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
||||
import dev.inmo.tgbotapi.extensions.api.answers.answerInlineQuery
|
||||
@ -195,7 +196,7 @@ suspend fun main(vararg args: String) {
|
||||
BotCommand("reply_markup", "Use to get reply markup keyboard with web app trigger"),
|
||||
BotCommand("inline", "Use to get inline keyboard with web app trigger"),
|
||||
)
|
||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) {
|
||||
allUpdatesFlow.subscribeLoggingDropExceptions(this) {
|
||||
println(it)
|
||||
}
|
||||
println(getMe())
|
||||
|
@ -5,9 +5,9 @@ org.gradle.jvmargs=-Xmx3148m
|
||||
kotlin.daemon.jvmargs=-Xmx3g -Xms500m
|
||||
|
||||
|
||||
kotlin_version=2.1.10
|
||||
telegram_bot_api_version=23.2.0
|
||||
micro_utils_version=0.24.6
|
||||
kotlin_version=2.1.20
|
||||
telegram_bot_api_version=25.0.0-rc
|
||||
micro_utils_version=0.25.3
|
||||
serialization_version=1.8.0
|
||||
ktor_version=3.1.0
|
||||
ktor_version=3.1.1
|
||||
compose_version=1.7.3
|
||||
|
Reference in New Issue
Block a user