update tgbotapi version up to 0.30.12, update of readme

This commit is contained in:
InsanusMokrassar 2021-01-06 00:01:41 +06:00
parent 79cc1a7c9a
commit 6f182c774c
4 changed files with 37 additions and 9 deletions

View File

@ -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"

View File

@ -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)

View File

@ -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))

View File

@ -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