Unverified Commit 6388e1b1 authored by seykron's avatar seykron

Adds documentation

parent 89713504
......@@ -2,3 +2,91 @@
![Tehanu](tehanu.png)
Tehanu allows you to easily build Telegram bots. It has the following features:
* Manages different kind of messages
* Commands
* Persistent storage
* User input
* Roles and permissions
## Dependencies
Tehanu is available in maven central. There are two artifacts:
*tehanu-core*: it is the core artifact and it contains all components. It can be
used alone in order to embed Tehanu into an existing project.
*tehanu-spring*: it has support for Spring's IoC container. It is convenient to build
standalone applications since it provides a full lifecycle configuration.
```xml
<dependency>
<groupId>be.rlab</groupId>
<artifactId>tehanu-core</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>be.rlab</groupId>
<artifactId>tehanu-spring</artifactId>
<version>2.2.0</version>
</dependency>
```
### Releases policy
Breaking changes will change the major version. New releases for the same mainline will
change the minor version. Bug fixes will change the revision.
We'll be careful to avoid breaking changes, but if it happens, we'll still deliver bug fixes
to the previous version. New features will not be available in previous versions. Every time
a new major version is released, we'll drop support for older versions and the previous version
is kept as deprecated in maintenance mode.
## Getting started
The easier way to set up a new application is by using the *tehanu-spring* artifact.
You will find a *hello-world* project in the examples directory. The following sections
will discuss the project's structure.
### Message listeners
[MessageListener](https://git.rlab.be/seykron/tehanu/blob/master/tehanu-core/src/main/kotlin/be/rlab/tehanu/domain/MessageListener.kt)
is the interface that must be implemented in order to handle Telegram messages.
Tehanu will automatically discover all beans in the application context that implement
this interface. The [SayHello](https://git.rlab.be/seykron/tehanu/blob/master/examples/hello-world/src/main/kotlin/be/rlab/hellobot/SayHello.kt)
message listener answers a user message when they mentions the bot's name.
```kotlin
class SayHello(
override val name: String,
private val botName: String
) : MessageListener {
override fun applies(
chat: Chat,
user: User?,
message: Message
): Boolean {
return message is TextMessage && message.text.startsWith(botName)
}
override fun handle(
context: MessageContext,
message: Message
): MessageContext {
return context.answer("hello!")
}
}
```
The lifecycle of a message listener consist of two phases:
*applies*: this is the first phase and it determines whether a message should be
handled by the message listener. If it returns true, the message listener is
selected and it goes to the next phase.
*handle*: this phase allows to handle the message. In this phase you can analyze the message
in order to either reply or ask for user input. We'll discuss the user input in the next
sections.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment