π€ Sender
The sender module provides a stateless service for sending and synchronizing the Telegram bot's UI in the codex-bot framework.
π§ The Why
UI Persistence
In a typical bot, every interaction sends a new message, creating a long and messy chat history. ViewSender solves this by managing two persistent messages (Menu and Content). Instead of sending new messages, it edits existing ones whenever possible, keeping the chat clean and focused.
Stateless Delivery
Since ViewSender is a Stateless Singleton, it doesn't store any user-specific data in self. It uses a SenderManager to retrieve the current message IDs (coordinates) from a persistent storage (e.g., Redis) for each request. This ensures that the UI remains consistent even across multiple bot instances.
π The Flow
- Input: The
Directorcalls the Orchestrator, which returns aUnifiedViewDTO. - Coordination: The
ViewSenderreceives theUnifiedViewDTOand retrieves the currentmenu_msg_idandcontent_msg_idfrom theSenderManager. - Synchronization:
- Deletion: If
trigger_message_idis present (e.g.,/start), it is deleted. - Editing: If the messages exist,
ViewSenderedits them with the new content and keyboard. - Creation: If they don't exist, new messages are sent.
- Deletion: If
- Persistence: The
SenderManagerupdates the message IDs in the storage for the next request.
πΊοΈ Module Map
| Component | Description |
|---|---|
| π API Reference | Technical details for ViewSender and SenderManager. |
| π Sender Keys | Key factory for UI coordinate storage. |
| π Protocols | SenderStateStorageProtocol for UI coordinate storage. |
Last Updated: 2025-02-07