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