#15975: feat(telegram): add Business Mode for personal chat access
channel: telegram
agents
stale
size: L
Cluster:
Telegram History and Features
## Summary
- Adds Telegram Business Mode integration — passive ingestion of the operator's personal Telegram chats via the Business API
- Messages stored locally in JSONL (`{stateDir}/telegram-business/{accountId}/chats/{chatId}/messages.jsonl`)
- New `telegram_business` agent tool with `list_chats`, `get_messages`, `search`, and `send` actions
- Handles `business_connection`, `business_message`, `edited_business_message`, and `deleted_business_messages` update types
- Config: `channels.telegram.business.enabled: true` to activate
This is a data-source integration (like gog for Gmail), not a real-time channel. Messages are passively stored and queried on demand. The agent is NOT woken on incoming business messages.
## Test plan
- [x] Enable Business Mode in @BotFather
- [x] Connect bot in Telegram app → Settings → Telegram Business → Chatbots
- [x] Verify `business_connection` stored to `connections.json`
- [x] Send messages in personal chat → verify JSONL ingestion with correct direction detection
- [x] Test `telegram_business action=list_chats` via agent
- [x] Test `telegram_business action=get_messages` via agent
- [x] Test `telegram_business action=search` via agent
- [x] Test incoming message direction detection (contact sends to operator)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Adds Telegram Business Mode integration allowing passive ingestion of operator's personal Telegram chats via the Business API. Messages are stored locally in JSONL format under `{stateDir}/telegram-business/{accountId}/chats/{chatId}/messages.jsonl` and accessed on-demand through a new `telegram_business` agent tool.
**Key changes:**
- Created new business integration module in `src/telegram/business/` with connection store, message store, and event handlers
- Handles `business_connection`, `business_message`, `edited_business_message`, and `deleted_business_messages` update types
- New agent tool supports `list_chats`, `get_messages`, `search`, and `send` actions
- Config: enable with `channels.telegram.business.enabled: true`
- Includes pre-reset hook feature from merged branch (allows agent wrap-up before session reset)
**Implementation quality:**
- Direction detection logic correctly identifies incoming vs outgoing messages by comparing `from.id` with `chat.id`
- Message deduplication properly handles edits and deletions
- Error handling uses try-catch with graceful fallbacks
- Sequential processing ensured via `getTelegramSequentialKey` updates
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with minor considerations around testing and potential file system growth
- The implementation is well-structured with proper error handling, sequential processing guarantees, and clean separation of concerns. Message deduplication and direction detection logic are sound. The code follows project conventions (TypeScript strict typing, proper error handling). However, the score is not a perfect 5 due to: (1) no test coverage for the new business integration, (2) no built-in limits on JSONL file growth despite config options for `maxMessagesPerChat` and `maxAgeDays` being defined but unused, and (3) the feature merges pre-reset hook changes that were already in main, making the diff slightly larger than the feature alone.
- Pay attention to `src/telegram/business/message-store.ts` regarding potential file growth - the config defines retention limits but they're not enforced in the append operations
<sub>Last reviewed commit: e93ccd3</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#14367: feat(telegram): add message read via inbound message store
by michaelquinlan88 · 2026-02-12
80.3%
#7751: Telegram: persist inbound history (SQLite) + add read action
by welttowelt · 2026-02-03
77.4%
#16501: feat(telegram): add inbound subagent queue with prefork progress
by cometjc · 2026-02-14
76.9%
#7058: feat(telegram): add channel_post handler for broadcast channels
by waifu7498173 · 2026-02-02
76.5%
#6084: Add dynamic Telegram agent routing for DM and groups
by Alfonsxh · 2026-02-01
76.1%
#11920: Telegram: create forum topics via message tool (thread-create)
by larsderidder · 2026-02-08
75.9%
#21029: Feature/telegram bot avatar clean
by aleonnet · 2026-02-19
75.8%
#8166: fix(telegram): lifecycle fixes for duplicate messages and auto-reco...
by cheenu1092-oss · 2026-02-03
75.7%
#14224: feat(telegram): add member-info action to get chat administrators
by ivan-andreyev · 2026-02-11
75.1%
#12936: fix(telegram): omit message_thread_id for private DM chats
by omair445 · 2026-02-09
75.1%