Interface BotChatStateService
public interface BotChatStateService
Service interface for managing per-chat conversational state.
Implementations persist and retrieve a string-based state token for each chat,
enabling multi-step conversation flows that are conditionally activated via
BotChatState.
Enum-friendly overloads are provided so callers can pass enum constants directly and receive IDE autocompletion, instead of writing raw strings:
// Instead of: chatStateService.setState(chatId, "WAITING_FOR_NAME")
chatStateService.setState(chatId, MyState.WAITING_FOR_NAME);
// Instead of: MyState.valueOf(chatStateService.getState(chatId))
MyState state = chatStateService.getStateAs(chatId, MyState.class);
- Since:
- 0.0.1
- Author:
- Islom Mirsaburov
-
Method Summary
Modifier and TypeMethodDescriptionRetrieves the current state for the specified chat.default <T extends Enum<T>>
TgetStateAs(Long chatId, Class<T> type) Retrieves the current state for the specified chat and parses it as an enum constant of the given type.default voidStores the enum constant'sEnum.name()as the state for the specified chat.voidStores or updates the state for the specified chat.
-
Method Details
-
getState
-
setState
-
setState
Stores the enum constant'sEnum.name()as the state for the specified chat. This overload enables IDE autocompletion when callers work with enum-defined states.- Parameters:
chatId- the unique Telegram chat identifier; must not benullstate- the enum constant whose name is persisted; must not benull
-
getStateAs
Retrieves the current state for the specified chat and parses it as an enum constant of the given type. Returnsnullif no state is set.MyState current = chatStateService.getStateAs(chatId, MyState.class);- Type Parameters:
T- the enum type- Parameters:
chatId- the unique Telegram chat identifier; must not benulltype- the enum class to parse the stored string into; must not benull- Returns:
- the matching enum constant, or
nullif no state has been set - Throws:
IllegalArgumentException- if the stored string does not match any constant oftype
-