π§° Helper
The helper module provides utility helpers for extracting context and normalizing data from Telegram events in the codex-bot framework.
π§ The Why
Context Normalization
In aiogram, different event types (e.g., Message, CallbackQuery) have different structures for accessing the user ID, chat ID, and message ID. ContextHelper provides a unified way to extract this data into an immutable BaseBotContext. This ensures that your business logic doesn't need to know the specific type of event it's handling.
Channel & Group Support
In some cases (e.g., posts in a channel), the from_user field might be missing. ContextHelper handles these edge cases by providing a fallback (e.g., using chat_id as the user_id), ensuring that the bot's session management remains consistent across all chat types.
π The Flow
- Extraction: A handler receives a
MessageorCallbackQueryand callsContextHelper.extract_base_context(event). - Normalization: The helper identifies the event type and extracts the
user_id,chat_id,message_id, andthread_id. - Fallback: If
from_useris missing, thechat_idis used as theuser_idfor session uniqueness. - Creation: An immutable
BaseBotContextis returned, ready to be used by theDirectoror Orchestrator.
πΊοΈ Module Map
| Component | Description |
|---|---|
| π API Reference | Technical details for ContextHelper. |
| π Context Helper | Extraction of BaseBotContext from Telegram events. |
Last Updated: 2025-02-07