diff --git a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt index 843fa8e..5e97f6b 100644 --- a/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt +++ b/ForwardInfoSenderBot/src/main/kotlin/ForwardInfoSenderBot.kt @@ -1,9 +1,8 @@ import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage import dev.inmo.tgbotapi.extensions.api.telegramBot -import dev.inmo.tgbotapi.extensions.utils.flatMap +import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.formatting.codeMarkdownV2 import dev.inmo.tgbotapi.extensions.utils.formatting.regularMarkdownV2 -import dev.inmo.tgbotapi.extensions.utils.safely import dev.inmo.tgbotapi.extensions.utils.shortcuts.mediaGroupMessages import dev.inmo.tgbotapi.extensions.utils.updates.asContentMessagesFlow import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling @@ -25,7 +24,7 @@ suspend fun main(vararg args: String) { val scope = CoroutineScope(Dispatchers.Default) bot.startGettingFlowsUpdatesByLongPolling(scope = scope) { - (merge(messageFlow.asContentMessagesFlow(), mediaGroupMessages(scope).flatMap())).mapNotNull { it as? PossiblyForwardedMessage }.onEach { message -> + (merge(messageFlow.asContentMessagesFlow(), mediaGroupMessages(scope).flatMap())).mapNotNull { it.asPossiblyForwardedMessage() }.onEach { message -> safely({ it.printStackTrace() }) { val toAnswer = when (val forwardInfo = message.forwardInfo) { null -> "There is no forward info" diff --git a/HelloBot/src/main/kotlin/HelloBot.kt b/HelloBot/src/main/kotlin/HelloBot.kt index fe04dba..2c34453 100644 --- a/HelloBot/src/main/kotlin/HelloBot.kt +++ b/HelloBot/src/main/kotlin/HelloBot.kt @@ -1,16 +1,15 @@ +import dev.inmo.micro_utils.coroutines.safely import dev.inmo.tgbotapi.extensions.api.chat.get.getChat -import dev.inmo.tgbotapi.extensions.api.chat.get.getChatAdministrators import dev.inmo.tgbotapi.extensions.api.send.reply import dev.inmo.tgbotapi.extensions.api.send.sendTextMessage -import dev.inmo.tgbotapi.extensions.api.telegramBot +import dev.inmo.tgbotapi.bot.Ktor.telegramBot +import dev.inmo.tgbotapi.extensions.utils.asChannelChat import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2 import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2 -import dev.inmo.tgbotapi.extensions.utils.safely import dev.inmo.tgbotapi.extensions.utils.updates.retrieving.startGettingFlowsUpdatesByLongPolling import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2 import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.chat.abstracts.* -import dev.inmo.tgbotapi.types.toChatId import dev.inmo.tgbotapi.utils.extensions.escapeMarkdownV2Common import kotlinx.coroutines.* import kotlinx.coroutines.flow.launchIn @@ -52,7 +51,7 @@ suspend fun main(vararg args: String) { channelPostFlow.onEach { safely { val chat = it.data.chat - val message = "Hi everybody in this channel \"${(chat as ChannelChat).title}\"" + val message = "Hi everybody in this channel \"${(chat.asChannelChat()) ?.title}\"" bot.sendTextMessage(chat, message, MarkdownV2) } }.launchIn(scope) diff --git a/README.md b/README.md index c9cbbf7..7256736 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ # TelegramBotAPI-examples + This repository contains several examples of simple bots which are using TelegramBotAPI + +## How to use this repository + +This repository contains several important things: + +* Example subprojects +* Commits +* Structure + +### Example subproject + +Each example subproject contains information about how to run this example and what is it +doing. Usually, it is some simple thing like sending "hello" message to the user which +wrote to the bot. + +### Commits + +Commits can contains some things like migration onto new version (especially it is actual +for major version changes), updates according to the new features in versions and +different other things which usually more important in context of history or changes +between library version + +### Structure + +Structure of this repository fully representative (it is the reason why this repo +contains multiplatform subprojects) and you can use it as some template (but I am strongly +recommend you to use my +[TelegramBot template](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template) or +[Multiplatform Project template](https://github.com/InsanusMokrassar/KotlinMultiplatformProjectTemplate)) diff --git a/gradle.properties b/gradle.properties index 40e582c..5837477 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ kotlin.code.style=official org.gradle.parallel=true kotlin_version=1.4.21 -telegram_bot_api_version=0.30.10 +telegram_bot_api_version=0.30.12