← Back to PRs

#7751: Telegram: persist inbound history (SQLite) + add read action

by welttowelt open 2026-02-03 05:25 View on GitHub →
channel: telegram stale
### 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