DEV Community

Cover image for I gave my Claude Code Telegram bot a memory — and found inbound messages skip every hook
張峰豪
張峰豪

Posted on

I gave my Claude Code Telegram bot a memory — and found inbound messages skip every hook

LoreRoom recalling a Telegram conversation

I run Claude Code from my phone through its official Telegram plugin. It's great — until the session restarts and the bot forgets the entire conversation. Ask "what did we decide yesterday?" and it has no idea.

The surprising part: inbound messages don't trigger any hook

My first instinct was a UserPromptSubmit hook to log every message. It never fired for Telegram messages.

Inbound Telegram messages are delivered to Claude through an internal channel push — not through any of Claude Code's hooks. Worse, when the bot is busy they queue invisibly, and if it never replies they can be lost. So the two "obvious" approaches — hooks and scraping the transcript — both silently drop messages.

The only reliable capture point is inside the plugin itself, the moment a message arrives.

What I built: LoreRoom

It patches the Telegram plugin at its source to capture both directions the instant each message arrives — even if the bot is busy, crashed, or never replies — into a whole-file-encrypted SQLite DB (SQLCipher). Recall is handed back to Claude as two MCP tools:

  • get_recent_context(hours) — the last N hours
  • search_tg_history(keyword) — full-text search over everything (FTS5 trigram, works for CJK too)

Local-only; never touches your bot token.

You <-> Telegram ──(patched plugin)──> spool ──> encrypted SQLite ──(MCP)──> Claude recalls
Enter fullscreen mode Exit fullscreen mode

Now I can ask my bot "what did I send you last night?" and it actually answers.

On encryption

This is at-rest encryption of the local DB, not Telegram E2E. It protects the DB file if it's copied off the machine; the key lives in a git-ignored, chmod 600 config and is never given to Claude or sent over a network.

Try it

MIT-licensed: https://github.com/fenghaochang/LoreRoom
Stack: TypeScript, better-sqlite3 (SQLCipher), MCP SDK, FTS5. My first open-source release — feedback very welcome.

Top comments (0)