fill readme + rename fallback state handler

This commit is contained in:
InsanusMokrassar 2022-08-13 20:37:17 +06:00
parent 7dad3581f1
commit 6f74e6b4cb
4 changed files with 29 additions and 4 deletions

View File

@ -16,3 +16,28 @@ You can create your bot using
That is a set of libraries for plagubots. Look at the
[PlaguBot Plugin template](https://insanusmokrassar.github.io/PlaguBotPluginTemplate/) to find how to create your bot.
### Technical help
In this bot has been used variant with FSM. That means that you may use all the [Behaviour Builder with FSM](https://bookstack.inmo.dev/books/telegrambotapi/page/behaviour-builder-with-fsm) functionality. In case you wish to setup states repo, you should use the next code in the `setupDI` of your plugin:
```kotlin
single<StatesManager<State>> {
// setup your manager and return here
// Default is:
DefaultStatesManager(
InMemoryDefaultStatesManagerRepo()
)
}
```
Besides, you may setup handling errors lambda in the same function:
```kotlin
single<StateHandlingErrorHandler<State>> {
{ state, e ->
logger.eS(e) { "Unable to handle state $state" } // logging by default
null // you should return new state or null, default callback will return null
}
}
```

View File

@ -104,7 +104,7 @@ data class PlaguBot(
statesManager = koinApp.koin.getOrNull<StatesManager<State>>() ?: DefaultStatesManager(
InMemoryDefaultStatesManagerRepo<State>()
),
onStateHandlingErrorHandler = koinApp.koin.getOrNull<FallbackStateHandler<State>>() ?: { state, e ->
onStateHandlingErrorHandler = koinApp.koin.getOrNull<StateHandlingErrorHandler<State>>() ?: { state, e ->
logger.eS(e) { "Unable to handle state $state" }
null
}

View File

@ -1,3 +0,0 @@
package dev.inmo.plagubot.config
typealias FallbackStateHandler<T> = suspend (T, Throwable) -> T?

View File

@ -0,0 +1,3 @@
package dev.inmo.plagubot.config
typealias StateHandlingErrorHandler<T> = suspend (T, Throwable) -> T?