← Back to PRs

#6581: feat(telegram): add topic names to session keys for better readability

by BrennerSpear open 2026-02-01 20:43 View on GitHub →
channel: telegram
## Summary Makes Telegram forum topic session keys more human-readable by appending slugified topic names. **Before:** ``` agent:main:telegram:group:-1003856094222:topic:49 ``` **After:** ``` agent:main:telegram:group:-1003856094222:topic:49-telegram-ops ``` ## Implementation 1. **New file: `src/telegram/topic-cache.ts`** - In-memory cache for topic ID → name mapping - `cacheTopicName(chatId, topicId, name)` - store a topic name - `getCachedTopicName(chatId, topicId)` - retrieve cached name - `slugifyTopicName(name)` - convert to URL-safe slug (lowercase, dashes, max 50 chars) 2. **Updated `src/telegram/bot-handlers.ts`** - Captures `forum_topic_created` service messages - Captures `forum_topic_edited` service messages - Caches topic names when these events occur 3. **Updated `src/telegram/bot/helpers.ts`** - `buildTelegramGroupPeerId()` now accepts optional `topicName` parameter - Appends slugified name to topic ID when available - Falls back to ID-only format if no cached name exists (backward compatible) 4. **Tests** - Added `src/telegram/topic-cache.test.ts` with comprehensive tests - Added tests for `buildTelegramGroupPeerId` with topic names ## Key Design Decisions - **Topic ID remains canonical** - the ID is always present and is the primary identifier - **Names are cosmetic** - stale/outdated names don't break anything - **Backward compatible** - if no name is cached, falls back to current format - **Slugified names** - max 50 chars, lowercase, spaces → dashes, special chars removed ## Testing All new tests pass. Existing tests unaffected.

Most Similar PRs