From d882cf9c97539372758e52101da01fa511768315 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Feb 2021 12:06:34 +0600 Subject: [PATCH] update readme --- README.md | 212 ++++++++++++++++++++++-------------------------------- 1 file changed, 85 insertions(+), 127 deletions(-) diff --git a/README.md b/README.md index d56dfdb052..9b2152468c 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,7 @@ # TelegramBotAPI -
-I do not wanna read a lot, just give me my bot - -You can simply use this template (and button -Use template) to get your copy of bot and start to code. -

-P.S. Do not forget to look into our minidocs and -kdocs - -
+Hello! This is a set of libraries for working with Telegram Bot API. | Common info | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://github.com/InsanusMokrassar/TelegramBotAPI/workflows/Build/badge.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [Small survey](https://forms.gle/2Hex2ynbHWHhi1KY7)| | -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | @@ -22,134 +13,101 @@ You can simply use +In this example you will see information about this bot at the moment of starting and answer with `Hi:)` every time it +gets message `/start` -## Ok, where should I start? +### Handling only last messages -![Libraries hierarchy](resources/TelegramBotAPI-libraries-hierarchy.svg) +```kotlin +suspend fun main() { + val bot = telegramBot(TOKEN) -In most cases, the most simple way will be to implement [TelegramBotAPI](tgbotapi/README.md) - it contains -all necessary tools for comfort usage of this library. If you want to exclude some libraries, you can implement just -[TelegramBotAPI BehaviourBuilder Extensions](tgbotapi.extensions.behaviour_builder/README.md), -[TelegramBotAPI API Extensions](tgbotapi.extensions.api/README.md), -[TelegramBotAPI Util Extensions](tgbotapi.extensions.utils/README.md) or even -[TelegramBotAPI Core](tgbotapi.core/README.md). + val flowsUpdatesFilter = FlowsUpdatesFilter() + bot.buildBehaviour(flowUpdatesFilter = flowsUpdatesFilter) { + println(getMe()) + + onCommand("start") { + reply(it, "Hi:)") + } -If you want to dive deeper in the core of library or develop something for it - welcome to learn more from -[TelegramBotAPI Core](tgbotapi.core/README.md) and our [Telegram Chat](https://teleg.one/InMoTelegramBotAPIChat). - -Anyway, all libraries are very typical inside of them. Examples: - -* In `TelegramBotAPI` common request look like `requestsExecutor.execute(SomeRequest())` -* `tgbotapi.extensions.api` typical syntax look like `requestsExecutor.someRequest()` (in most cases it would be -better to use `bot` name instead of `requestsExecutor`) -* `tgbotapi.extensions.utils` will look like `filter.filterBaseMessageUpdates(chatId).filterExactCommands(Regex("^.*$"))...` - -## Build instruction - -If you want to build this project or to contribute, there are several recommendations: - -### Build - -In case if you want to just build project, run next command: - -```bash -./gradlew clean build -``` - -On windows: - -``` -gradlew.bat clean build -``` - -### Publishing for work with your version locally - -In case, if you want to work in your other projects using your modification (or some state) of this library, -you can use next code: - -```bash -./gradlew clean build publishToMavenLocal -``` - -On windows: - -``` -gradlew.bat clean build publishToMavenLocal -``` - -But you must remember, that in this case your local maven repo must be the first one from -your project retrieving libraries: - -```groovy -repositories { - mavenLocal() // that must be the first one - jcenter() - mavenCentral() + retrieveAccumulatedUpdates( + allowedUpdates, + asUpdatesReceiver + ) + }.join() } ``` -Besides, for your own version you can change variable `library_version` in the file [gradle.properties](./gradle.properties). +The main difference with the previous example is that bot will get only last updates (accumulated before bot launch +and maybe some updates it got after launch) + +### Build a little bit more complex behaviour + +```kotlin +suspend fun main() { + val bot = telegramBot(TOKEN) + + bot.buildBehaviour { + println(getMe()) + + val nameReplyMarkup = ReplyKeyboardMarkup( + matrix { + row { + +SimpleKeyboardButton("nope") + } + } + ) + onCommand("start") { + val photo = waitPhoto( + SendTextMessage(it.chat.id, "Send me your photo please") + ).first() + + val name = waitText( + SendTextMessage( + it.chat.id, + "Send me your name or choose \"nope\"", + replyMarkup = ReplyKeyboardMarkup( + matrix { + row { + +SimpleKeyboardButton("nope") + } + } + ) + ) + ).first().text.takeIf { it != "nope" } + + sendPhoto( + it.chat, + photo.mediaCollection, + entities = buildEntities { + if (name != null) regular(name) // may be collapsed up to name ?.let(::regular) + } + ) + } + }.join() +} +``` + +### More examples + +You may find examples in [this project](https://github.com/InsanusMokrassar/TelegramBotAPI-examples). Besides, you are +always welcome in our [wiki](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/About-this-project) and +[chat](https://t.me/InMoTelegramBotAPIChat).