Rememberbox Reader
A small, self-hosted reading library fed by a Telegram channel. Drop links into your channel; a webhook receives them, extracts clean article text in the background, and publishes quiet server-rendered pages — light enough to read comfortably in a Kindle browser.
How it works
- You post links to a Telegram channel your bot is a member of.
- Telegram delivers each post to the service via webhook (verified with a secret token).
- A race-safe background processor fetches each page, extracts readable content with Readability, sanitizes it, and stores it in SQLite.
- Articles are served immediately as minimal, text-first HTML — no client-side JavaScript.
The whole service is a single Node.js process with no external database: it uses the built-in node:sqlite module (Node.js ≥ 22.5).
Features
- Zero-friction capture — saving an article is just posting a link to Telegram.
- Clean reading pages — Readability extraction, allow-list sanitized HTML, restrictive CSP,
?text=1 mode to suppress images.
- Search and browse — by day, by source domain, or full-text search.
- Historical backfill — import older posts from a public channel's
t.me/s/ archive.
- AI insights (optional) — each article is pre-digested by an LLM: a short summary, key takeaways, the single passage to read first, a read-priority rating, and topic tags that link related saved articles. Works with any model on OpenRouter (or any OpenAI-compatible endpoint).
- SSRF-hardened fetching — rejects private, loopback, link-local, reserved, authenticated, and non-HTTP(S) destinations, re-checking every redirect.
- Simple operations — one container, one SQLite file, one-command consistent backups.
Deploy
Requirements: Docker Compose, a public HTTPS hostname, and a reverse proxy forwarding that hostname to 127.0.0.1:3000.
Create a bot with @BotFather and add it to your channel. Membership is enough — administrator rights are not required for this read-only use.
Run the setup wizard — it validates the bot token and channel against the Telegram API, generates the webhook secret, writes .env, and registers the webhook:
npm install
npm run cli -- setup
(Or copy .env.example to .env by hand and run webhook:set after starting. Keep .env private.)
Start the service and verify:
docker compose up -d --build
docker compose exec reader node dist/src/cli.js webhook:info
docker compose exec reader node dist/src/cli.js channel:validate
Telegram must be able to POST to https://your-host/telegram/webhook. The reverse proxy should preserve the X-Telegram-Bot-Api-Secret-Token header.
Operations
# Extract and publish a date manually (safe to repeat)
docker compose exec reader node dist/src/cli.js batch:run 2026-07-11
# Import links from the public Telegram archive for the previous 21 days
# (requires TELEGRAM_CHANNEL_USERNAME and a public channel)
docker compose exec reader node dist/src/cli.js backfill 21
# Or import every accessible post from the current calendar year
docker compose exec reader node dist/src/cli.js backfill year
# Requeue all failed extractions, or only one date
docker compose exec reader node dist/src/cli.js retry:failed
docker compose exec reader node dist/src/cli.js retry:failed 2026-07-11
# Create a consistent SQLite backup in the mounted backups directory
docker compose exec reader node dist/src/cli.js backup /backups/reader-$(date +%F).db
Automate the backup command daily from the host and apply your normal retention policy. Restore by stopping the service, retaining a copy of the current volume, replacing /data/reader.db with the chosen backup, and starting the service again.
The webhook acknowledges Telegram before extraction begins. The background processor publishes links immediately, drains posts received during an active extraction, and checks every minute plus at startup so a restart or transient failure cannot strand queued links. Set PUBLISH_IMMEDIATELY=false to switch to a daily batch published at PUBLISH_TIME in TZ.
AI insights
Set OPENROUTER_API_KEY to have every published article processed in the background before you read it. For each article the model produces:
- a 2–3 sentence summary and 3–5 key takeaways, shown above the article and on library cards;
- a "start here" passage — the most important paragraph quoted verbatim, with a one-line reason, so you can decide in seconds whether to read the whole thing;
- a read priority (must-read / worthwhile / skim / reference) surfaced as a badge in the library;
- topic tags that power a "Related in your library" section on each article and are searchable.
The model is fully configurable via INSIGHTS_MODEL (any OpenRouter model ID, e.g. anthropic/claude-sonnet-4.5, openai/gpt-4o, google/gemini-2.5-pro), and OPENROUTER_BASE_URL can point at any OpenAI-compatible endpoint, including a local one. Insights run automatically after publication (INSIGHTS_PER_CYCLE per minute-cycle); backfill an existing library manually:
docker compose exec reader node dist/src/cli.js insights:run 100
Without the key, the reader works exactly as before — insights are purely additive.
Configuration
| Variable |
Required |
Description |
BASE_URL |
yes |
Public HTTPS URL of the site (used for webhook registration and links) |
TELEGRAM_BOT_TOKEN |
yes |
Bot token from @BotFather |
TELEGRAM_WEBHOOK_SECRET |
yes |
Long random value verified on every webhook request |
TELEGRAM_CHANNEL_ID |
yes |
Numeric ID of the channel (e.g. -1001234567890) |
TELEGRAM_CHANNEL_USERNAME |
no |
Public username of the channel, only needed for backfill |
TZ |
no |
IANA timezone for daily batching (default Asia/Kolkata) |
PUBLISH_TIME |
no |
HH:MM daily publish time when not publishing immediately (default 22:00) |
PUBLISH_IMMEDIATELY |
no |
Publish as links arrive instead of daily batches (default true) |
DATABASE_PATH |
no |
SQLite file location (default ./data/reader.db) |
PORT |
no |
HTTP port (default 3000) |
EXTRACTION_CONCURRENCY |
no |
Parallel extractions, 1–8 (default 3) |
OPENROUTER_API_KEY |
no |
Enables AI insights; without it the feature is off |
INSIGHTS_MODEL |
no |
Model ID for insights (default anthropic/claude-sonnet-4.5) |
OPENROUTER_BASE_URL |
no |
Any OpenAI-compatible endpoint (default https://openrouter.ai/api/v1) |
INSIGHTS_PER_CYCLE |
no |
Max articles analyzed per background cycle, 1–50 (default 5) |
Architecture
One Node.js process, no framework, no external services besides Telegram and (optionally) an LLM endpoint. State lives in a single SQLite file accessed through the built-in node:sqlite module.
Telegram channel ──webhook──▶ server.ts ──▶ ingest.ts ──▶ SQLite (queued articles)
│
processor.ts (every 60s + on demand)
│ │
├─▶ extract.ts fetch → Readability → sanitize → publish
└─▶ insights.ts published → LLM → summary/focus/priority/topics
│
Browser ◀────────────── web.ts (server-rendered HTML) ◀───────┘
| File |
Responsibility |
src/server.ts |
HTTP server, webhook auth (timing-safe secret check), request routing, JSON logging |
src/ingest.ts |
Turns Telegram updates into queued articles; idempotent, reconciles edited posts |
src/processor.ts |
WorkCoordinator — race-safe background loop that drains pending work without overlap |
src/extract.ts |
SSRF-guarded fetching, Readability extraction, HTML sanitization, atomic publication |
src/insights.ts |
LLM analysis of published articles, topic storage, related-article queries |
src/web.ts |
All public pages, rendered server-side with inline CSS; no client JavaScript. Visual language follows The Monospace Web — a character/line grid, 2px rules, bordered tables, system monospace only (the CSP forbids web fonts), light and dark via prefers-color-scheme |
src/urls.ts / src/dates.ts |
Link extraction/normalization; collection-date and publish-time math |
src/config.ts |
Environment validation — fails fast on missing or malformed variables |
src/db.ts / src/schema.sql |
Database bootstrap; idempotent schema applied on every start |
src/cli.ts |
Operational commands (see below) |
Data model
articles — one row per unique normalized URL; lifecycle queued → extracting → ready/fallback → published. A fallback article is published as a link-only card when extraction fails.
channel_posts / post_articles / telegram_updates — provenance and idempotency for Telegram ingestion.
publication_runs — one row per collection date; makes batch:run safe to repeat.
article_insights — one row per analyzed article: summary, key points (JSON), verbatim focus passage with reason, read priority, generating model.
article_topics — normalized topic tags; related articles are ranked by shared-topic count.
The schema is applied with CREATE TABLE IF NOT EXISTS on startup, so upgrades that add tables need no migration step.
CLI reference
Run with docker compose exec reader node dist/src/cli.js <command> (or npm run cli -- <command> in development).
| Command |
Purpose |
setup |
Interactive wizard: validates the bot token and channel against the Telegram API, generates the webhook secret, writes .env, and registers the webhook |
migrate |
Open the database and apply the schema, then exit |
webhook:set / webhook:info |
Register the Telegram webhook with the secret token / inspect its status |
channel:validate |
Confirm the bot can see the configured channel |
backfill [DAYS|year] |
Import links from the public t.me/s/ archive (needs TELEGRAM_CHANNEL_USERNAME) |
batch:run YYYY-MM-DD |
Extract and publish one date now; safe to repeat |
retry:failed [YYYY-MM-DD] |
Requeue failed extractions, optionally for one date |
insights:run [LIMIT] |
Generate AI insights for published articles that lack them (default 25) |
backup [PATH] |
WAL-checkpoint and copy the SQLite file to a consistent backup |
Routes
| Route |
Description |
/ |
Library, newest first, grouped by day |
/day/YYYY-MM-DD |
All articles saved on one date |
/article/:slug |
Reading page — insights panel, extracted content, related articles; ?text=1 hides images |
/search?q=… |
Matches title, author, host, full text, and topic tags |
/source/:id |
Redirect to the original URL (no referrer) |
/telegram/webhook |
POST endpoint for Telegram (secret-token verified) |
/healthz |
Liveness check used by the Docker healthcheck |
Development
Node.js 22.5 or newer is required because the service uses the built-in SQLite module.
npm install
npm run cli -- setup # or: cp .env.example .env and edit by hand
npm test
npm run typecheck
npm run dev
npm test runs the suite with Node's built-in test runner against in-memory SQLite databases — no network or fixtures required.
Security and limitations
- Source requests reject private, loopback, link-local, reserved, authenticated, and non-HTTP(S) destinations; every redirect is checked again.
- Responses are limited to HTML and 5 MiB. Extraction does not execute JavaScript or bypass logins, paywalls, CAPTCHAs, or anti-bot controls.
- Extracted HTML is allow-list sanitized and served with a restrictive CSP. Images remain remote HTTPS resources and are never copied.
- The Bot API does not report deleted channel posts and cannot backfill channel history (the
backfill command uses the public t.me/s/ archive instead). Edited posts reconcile links only while affected articles remain unpublished.
- The public archive is marked
noindex,nofollow, but that is not access control.
License
MIT