TDLightTelegramBots/telegrambots-chat-session-bot
Andrea Cavalli 9b8c41dab1 Merge remote-tracking branch 'github/master' 2023-11-02 10:54:50 +01:00
..
src/main/java Merge remote-tracking branch 'github/master' 2023-11-02 10:54:50 +01:00
README.md API Version 6.8 2023-08-19 18:40:14 +01:00
pom.xml Merge remote-tracking branch 'github/master' 2023-11-02 10:54:50 +01:00

README.md

Build Status Jitpack Telegram

Usage

Maven

    <dependency>
        <groupId>org.telegram</groupId>
        <artifactId>telegrambots-chat-session-bot</artifactId>
        <version>6.8.0</version>
    </dependency>

Gradle

    implementation 'org.telegram:telegrambots-chat-session-bot:6.8.0'

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

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