#7751: Telegram: persist inbound history (SQLite) + add read action
channel: telegram
stale
Cluster:
Telegram History and Features
### What
- Persist inbound Telegram messages locally (SQLite) to enable basic history retrieval.
- Add Telegram plugin action `read` behind config gate `channels.telegram.actions.readHistory`.
- Add config `channels.telegram.history.enabled` + `channels.telegram.history.maxMessagesPerChat`.
### Why
Telegram Bot API cannot fetch arbitrary historical messages. The reliable approach is to persist inbound updates as they arrive and provide a local query path. This unblocks resolving `t.me/c/.../<msgId>` references once messages have been observed by the bot.
### How
- New `src/telegram/history-store.ts` using sqlite in `${resolveStateDir(...)}/telegram/history.sqlite`
- `bot-message-context` records inbound updates (both mention-skip and accepted paths).
- `src/channels/plugins/actions/telegram.ts`: add `readTelegramHistoryMessages` behind action gate.
### Config
```yaml
channels:
telegram:
history:
enabled: true
maxMessagesPerChat: 5000
actions:
readHistory: true
```
### Tests
- Added `src/telegram/history-store.test.ts` (uses `OPENCLAW_STATE_DIR` temp dir)
- `pnpm test -- src/telegram/history-store.test.ts`
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a local Telegram inbound history store backed by SQLite and wires it into the Telegram inbound processing path so messages can be retrieved later. It also introduces a new Telegram plugin action (`read`) intended to read that locally persisted history behind a config gate (`channels.telegram.actions.readHistory`), plus config/schema entries for enabling history and setting a per-chat retention cap.
The overall approach fits the repo’s channel/provider architecture: Telegram inbound context building persists updates, and plugin actions expose an agent-facing API for reading. The main concern is a retention/pruning SQL bug that can delete history for unrelated chats, plus a couple of smaller gating/pagination correctness edges.
<h3>Confidence Score: 2/5</h3>
- This PR has a high-impact data retention bug that can delete unrelated Telegram history when pruning is enabled.
- Core functionality is reasonable, but the current pruning SQL can remove rows outside the target chat/thread, which is likely to surface quickly in real usage. Secondary concerns include enforcing the readHistory action gate in the handler and tightening pagination semantics.
- src/telegram/history-store.ts; src/channels/plugins/actions/telegram.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#14367: feat(telegram): add message read via inbound message store
by michaelquinlan88 · 2026-02-12
89.2%
#19800: fix(telegram): add INFO-level logging at inbound message drop paths
by katalabut · 2026-02-18
79.5%
#6457: fix(telegram): register commands for group scope + preserve topic t...
by dae-sun · 2026-02-01
78.9%
#11920: Telegram: create forum topics via message tool (thread-create)
by larsderidder · 2026-02-08
78.6%
#7058: feat(telegram): add channel_post handler for broadcast channels
by waifu7498173 · 2026-02-02
77.9%
#15975: feat(telegram): add Business Mode for personal chat access
by scomma · 2026-02-14
77.4%
#13540: feat: persist channel histories to disk
by carrotRakko · 2026-02-10
77.3%
#15493: feat(telegram): session state memory for diagnostic continuity
by tangcruz · 2026-02-13
76.5%
#19213: Telegram: preserve DM topic thread in direct replies
by Kemalau · 2026-02-17
76.4%
#14224: feat(telegram): add member-info action to get chat administrators
by ivan-andreyev · 2026-02-11
76.4%