mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-25 19:48:49 +00:00
upgrade of hello bot
This commit is contained in:
parent
6350581739
commit
323c21f415
@ -1,8 +1,10 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMentionWithAnyContent
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sender_chat
|
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sender_chat
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
||||||
@ -25,24 +27,25 @@ suspend fun main(vararg args: String) {
|
|||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onContentMessage { message ->
|
val me = getMe()
|
||||||
|
onMentionWithAnyContent(me.username) { message ->
|
||||||
val chat = message.chat
|
val chat = message.chat
|
||||||
|
|
||||||
val answerText = when (val chat = message.chat) {
|
val answerText = when (val chat = message.chat) {
|
||||||
is ChannelChat -> {
|
is ChannelChat -> {
|
||||||
val answer = "Hi everybody in this channel \"${chat.title}\""
|
val answer = "Hi everybody in this channel \"${chat.title}\""
|
||||||
reply(message, answer, MarkdownV2)
|
reply(message, answer, MarkdownV2)
|
||||||
return@onContentMessage
|
return@onMentionWithAnyContent
|
||||||
}
|
}
|
||||||
is PrivateChat -> {
|
is PrivateChat -> {
|
||||||
reply(message, "Hi, " + "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id), MarkdownV2)
|
reply(message, "Hi, " + "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id), MarkdownV2)
|
||||||
return@onContentMessage
|
return@onMentionWithAnyContent
|
||||||
}
|
}
|
||||||
is GroupChat -> {
|
is GroupChat -> {
|
||||||
message.ifFromChannelGroupContentMessage {
|
message.ifFromChannelGroupContentMessage {
|
||||||
val answer = "Hi, ${it.senderChat.title}"
|
val answer = "Hi, ${it.senderChat.title}"
|
||||||
reply(message, answer, MarkdownV2)
|
reply(message, answer, MarkdownV2)
|
||||||
return@onContentMessage
|
return@onMentionWithAnyContent
|
||||||
}
|
}
|
||||||
"Oh, hi, " + when (chat) {
|
"Oh, hi, " + when (chat) {
|
||||||
is SupergroupChat -> (chat.username ?.username ?: getChat(chat).inviteLink) ?.let {
|
is SupergroupChat -> (chat.username ?.username ?: getChat(chat).inviteLink) ?.let {
|
||||||
|
@ -5,7 +5,7 @@ org.gradle.jvmargs=-Xmx2g
|
|||||||
|
|
||||||
|
|
||||||
kotlin_version=1.8.21
|
kotlin_version=1.8.21
|
||||||
telegram_bot_api_version=7.1.2
|
telegram_bot_api_version=7.1.3-branch_7.1.3-build1645
|
||||||
micro_utils_version=0.18.1
|
micro_utils_version=0.18.4
|
||||||
serialization_version=1.5.0
|
serialization_version=1.5.1
|
||||||
ktor_version=2.3.0
|
ktor_version=2.3.0
|
||||||
|
Loading…
Reference in New Issue
Block a user