π§ FSM
The fsm module provides advanced state management and automatic UI cleanup (Garbage Collector) for the codex-bot framework.
π§ The Why
Data Isolation (Namespacing)
In a complex bot, multiple features might need to store temporary data (drafts) in the user's FSM storage. Without isolation, one feature could accidentally overwrite another's data. BaseStateManager solves this by using namespaced keys (e.g., draft:booking), ensuring each feature has its own private storage area within the global FSM session.
Chat Cleanliness (Garbage Collector)
When a bot uses an inline-button-based UI, users often send accidental text messages that clutter the chat and break the flow. The GarbageCollector automatically deletes these unwanted messages in specific states, keeping the interface clean and focused on the buttons.
π The Flow
- State Management: A feature's Orchestrator uses
BaseStateManagertoupdate()orget_payload()from its isolated FSM namespace. - Registration: During startup,
FeatureDiscoveryServiceregisters "garbage states" from each feature into theGarbageStateRegistry. - Filtering: When a user sends a text message, the
IsGarbageStateFilterchecks if the current FSM state is registered as "garbage". - Cleanup: If it is, the
common_fsm_routercatches the message and deletes it from the Telegram chat.
πΊοΈ Module Map
| Component | Description |
|---|---|
| π API Reference | Technical details for BaseStateManager and GarbageStateRegistry. |
| π State Manager | Isolated feature data storage within FSM. |
| π Garbage Collector | Automatic deletion of unwanted text messages. |
Last Updated: 2025-02-07