#6581: feat(telegram): add topic names to session keys for better readability
channel: telegram
Cluster:
Messaging Platform Improvements
## 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
#7407: feat(telegram): human-readable topic names in session dropdown
by Diaspar4u · 2026-02-02
78.8%
#10686: fix(slack): use thread-level sessions for channels to prevent conte...
by pablohrcarvalho · 2026-02-06
66.8%
#14243: fix: fire session-memory hook on auto-resets + topic-aware memory p...
by TheDude135 · 2026-02-11
66.3%
#3368: fix: sessions navigation, DM thread display, and DM thread delivery...
by Lukavyi · 2026-01-28
66.2%
#6457: fix(telegram): register commands for group scope + preserve topic t...
by dae-sun · 2026-02-01
65.3%
#7224: feat(telegram): inherit forum topic bindings from parent group
by Buywatermelon · 2026-02-02
65.1%
#14443: fix(telegram): skip General topic thread ID for all chat types (#14...
by lailoo · 2026-02-12
64.8%
#6192: Telegram: fix DM Topics thread routing
by ViffyGwaanl · 2026-02-01
64.4%
#11920: Telegram: create forum topics via message tool (thread-create)
by larsderidder · 2026-02-08
64.4%
#19203: telegram: convert hyphens to underscores in command names
by janckerchen · 2026-02-17
63.8%