mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-12-22 08:37:18 +00:00
reverted CustomBot body
This commit is contained in:
parent
7964dc4eea
commit
358f2d27d3
@ -3,19 +3,14 @@ import dev.inmo.kslog.common.LogLevel
|
||||
import dev.inmo.kslog.common.defaultMessageFormatter
|
||||
import dev.inmo.kslog.common.setDefaultKSLog
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||
import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.from
|
||||
import dev.inmo.tgbotapi.utils.PreviewFeature
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
/**
|
||||
* The main purpose of this bot is just to answer "Oh, hi, " and add user mention here.
|
||||
* Also, this place can be the playground for your code.
|
||||
* This place can be the playground for your code.
|
||||
*/
|
||||
@OptIn(PreviewFeature::class)
|
||||
suspend fun main(vararg args: String) {
|
||||
val botToken = args.first()
|
||||
|
||||
@ -30,14 +25,10 @@ suspend fun main(vararg args: String) {
|
||||
}
|
||||
|
||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { update ->
|
||||
update.asMessageUpdate()?.let { safeMessageUpdate ->
|
||||
val user = safeMessageUpdate.data.from
|
||||
val replyMessage = if (user != null) {
|
||||
"Oh, hi, ${user.username ?: user.firstName}!"
|
||||
} else "Oh, hi!"
|
||||
reply(to = safeMessageUpdate.data, text = replyMessage)
|
||||
}
|
||||
}
|
||||
// start here!!
|
||||
val me = getMe()
|
||||
println(me)
|
||||
|
||||
allUpdatesFlow.subscribeSafelyWithoutExceptions(this) { println(it) }
|
||||
}.second.join()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user