helper — Utility helpers
Module of auxiliary tools to simplify development and debugging.
ContextHelper
Universal extractor of identifiers from any type of events (Telegram or Redis).
ContextHelper
Utility class for polymorphic context extraction.
Standardizes the retrieval of identity and routing information across
different interaction models. It ensures that business logic receives
a consistent BaseBotContext regardless of the upstream event source.
Capabilities
- Parsing
aiogram.Messageandaiogram.CallbackQuery. - Normalizing raw dictionaries (Redis Stream / Direct API).
- Handling fallback logic for user/chat identity resolution.
Source code in src/codex_bot/helper/context_helper.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
Functions
extract_base_context(event)
staticmethod
Analyze an event source and extract its routing metadata.
Coordinates the extraction of User ID, Chat ID, and Thread IDs, applying normalization rules to ensure session consistency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
TelegramObject | dict[str, Any]
|
A native Telegram object or a dictionary representing an incoming event payload. |
required |
Returns:
| Type | Description |
|---|---|
BaseBotContext
|
An immutable |
Source code in src/codex_bot/helper/context_helper.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
ID Inspector
Ready-to-use handler for obtaining technical information about chat and user.
inspect_ids_handler(message)
async
Ready-to-use aiogram handler for inspecting IDs.
Returns User ID, Chat ID, Chat Type, and Thread ID. Supports forwarded messages from channels to find Channel IDs.
Usage
from codex_bot.helper.id_inspector import inspect_ids_handler
router.message(Command("id"))(inspect_ids_handler)
Source code in src/codex_bot/helper/id_inspector.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |