Skip to content
Back to skills

Telegram Chat History Persistence

ASecurity

Design and implement context continuity for a Telegram → Claude gateway. Use when the bot loses cross-session context or when choosing between transcript injection, SQLite buffering, RAG, and the memweave corpus for chat history.

  • 4 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added October 1, 2026
ai-agentsgoshellsqlgitsecurity

Works with

  • cli
  • mcp

Security analysis

A100/100

Scanned October 1, 2026

npx -y skills add williamblair333/Uncle-J-s-Refinery --skill telegram-chat-history-persistence --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Telegram Chat History Persistence?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Telegram Chat History Persistence
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/williamblair333-telegram-chat-history-persistence/badge)](https://www.skillsdirectory.com/skills/williamblair333-telegram-chat-history-persistence)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: telegram-chat-history-persistence
description: Design and implement context continuity for a Telegram → Claude gateway. Use when the bot loses cross-session context or when choosing between transcript injection, SQLite buffering, RAG, and the memweave corpus for chat history.
metadata:
  type: project
---

## When to Use

Invoke when:
- The Telegram bot fails to recall a message from a prior session
- Designing or revisiting how chat history is persisted and injected
- Evaluating trade-offs between history storage approaches

## Approaches (Evaluated)

| # | Approach | Pros | Cons |
|---|----------|------|------|
| 1 | Full transcript injection | Lossless, zero deps | Context window explodes |
| 2 | Sliding window / rolling buffer | Bounded tokens | Fails for anything outside the window |
| 3 | **LLM-summarized history** ✓ | Bounded, captures gist, handles long gaps | Slight losiness; one async LLM call per session |
| 4 | SQLite store | Queryable, durable, no external deps | Still needs retrieval strategy on top |
| 5 | RAG over chat history | Solves "10 hours ago" references | Needs embedding model (e.g. local ollama) |
| 6 | memweave corpus (mw_search.py) | Zero new infra, shell-callable CLI (no MCP glue) | Summaries only; not a turn-by-turn buffer |
| 7 | Mem0 / Zep managed | Production-ready | Data leaves machine, external cost |
| 8 | Long-context model injection | No retrieval logic | Expensive, slow, still has a ceiling |

## Recommended Approach: LLM Summary + SQLite + Last-N Raw Turns

**Implementation steps:**

1. **Log every exchange** to a local JSONL file: `{timestamp, sender, text, session_id}`
2. **On session close**, run an async Claude call to summarize the session and write it to SQLite (`session_summaries` table: `session_id`, `closed_at`, `summary_text`)
3. **On session start**, the gateway shell script:
   - Queries SQLite for the last 2–3 session summaries
   - Appends the last N raw turns (e.g. 20 turns or 2 hours)
   - Injects both into the system prompt as "Recent Telegram context"
4. **The memweave corpus** receives only session summaries (not raw transcripts) — which is what it's actually good at

## Key Constraints

**Avoid storing raw transcripts in the memweave corpus** — circular disclosure risk: if the bot disclosed something it shouldn't have (commit hashes, tool names), storing it verbatim lets the bot retrieve and repeat the mistake with false confidence.

**Sanitize before injection** — strip or redact sensitive content (commit hashes, file paths, MCP tool names) from the last-N raw turns before they enter the system prompt. See [[feedback_telegram_disclosure]].

**Write path must be non-blocking** — if the JSONL write or SQLite insert hangs, it must not block the Telegram response. Run writes in a background thread or after-response hook.

## Related Skills and Memories

- `telegram-gateway-security-audit` — covers dedup bugs and disclosure-restriction prompt injection
- [[feedback_telegram_disclosure]] — never reveal OS/kernel/paths/git/email/MCP stack over Telegram
- [[project_telegram_purpose]] — approval channel, not a chat assistant; each message must be self-describing

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.