2018-06-07 20:43:41 +03:00
|
|
|
<div align="center">
|
|
|
|
|
|
|
|
[](https://travis-ci.org/rubenlagus/TelegramBots)
|
|
|
|
[](https://jitpack.io/#rubenlagus/TelegramBots)
|
|
|
|
[](https://telegram.me/JavaBotsApi)
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
|
|
|
**Maven**
|
|
|
|
|
|
|
|
```xml
|
|
|
|
<dependency>
|
|
|
|
<groupId>org.telegram</groupId>
|
|
|
|
<artifactId>telegrambots-chat-session-bot</artifactId>
|
2019-01-27 23:37:46 +00:00
|
|
|
<version>4.1.2</version>
|
2018-06-07 20:43:41 +03:00
|
|
|
</dependency>
|
|
|
|
```
|
|
|
|
|
|
|
|
Motivation
|
|
|
|
----------
|
|
|
|
Implementation of bot dialogs require saving some data about current state of conversation.
|
|
|
|
That brings us to idea of chat session management.
|
|
|
|
|
|
|
|
How to use
|
|
|
|
----------
|
|
|
|
`Chat session bot` was implemented by using [`Shiro Apache`](https://shiro.apache.org/) session manager.
|
|
|
|
That allow to manage and store sessions.
|
|
|
|
|
|
|
|
|
|
|
|
To create default Long Polling Session Bot with in-memory store,
|
|
|
|
you need simply implement `TelegramLongPollingSessionBot`
|
|
|
|
```java
|
|
|
|
public class ExampleBotWithSession extends TelegramLongPollingSessionBot {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdateReceived(Update update, Optional<Session> optionalSession) {
|
|
|
|
//Do some action with update and session
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBotUsername() {
|
|
|
|
return "ExampleBotWithSessionBot";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBotToken() {
|
|
|
|
return "1234";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Where session is implementation of `org.apache.shiro.session.Session`
|