Mirror of gitea.com/fargeiw/morning-digest
  • HTML 50.3%
  • JavaScript 49.7%
Find a file
P e5311b7c13 docs: point links to askmeaiva.com and gitea (drop GitLab/GitHub refs)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 20:42:10 +04:00
api Switch translate to Google's free public endpoint 2026-05-13 08:20:10 +04:00
lib Include outgoing messages in digest 2026-05-13 08:34:39 +04:00
scripts Refactor login to non-interactive two-step flow 2026-05-12 14:56:40 +09:00
.env.example Scaffold morning-digest — daily 8am Tbilisi Telegram summary 2026-05-12 14:37:38 +09:00
.gitignore Add per-sender colors and Thai→English translate button 2026-05-13 08:16:10 +04:00
index.html Add per-sender colors and Thai→English translate button 2026-05-13 08:16:10 +04:00
middleware.js Add Basic Auth gate (admin/admin) via Vercel Edge Middleware 2026-05-12 14:49:16 +09:00
package-lock.json Step 3 — cron handler, API endpoints, and full UI (no AI) 2026-05-12 15:13:36 +09:00
package.json Step 3 — cron handler, API endpoints, and full UI (no AI) 2026-05-12 15:13:36 +09:00
README.md docs: point links to askmeaiva.com and gitea (drop GitLab/GitHub refs) 2026-05-13 20:42:10 +04:00
vercel.json Add per-sender colors and Thai→English translate button 2026-05-13 08:16:10 +04:00

morning-digest

A Vercel-hosted personal page that, each morning at 08:00 Asia/Tbilisi, shows every Telegram message you received overnight — grouped by chat, raw, no summarization. Open it from bed; skim what arrived while you slept.

Status: All build-plan steps shipped. Live page renders, cron is scheduled, manual Refresh works, per-sender colors + on-demand Thai→English translation are in.

Architecture

  • Source: Telegram user API via gramjs (telegram npm package), authenticated as the user (not a bot)
  • Storage: Vercel Blob — one JSON file per date (digests/YYYY-MM-DD.json)
  • Schedule: Vercel Cron, 0 4 * * * UTC = 08:00 Asia/Tbilisi
  • Display: Static index.html + /api/today + /api/history, all behind HTTP Basic Auth via middleware.js
  • Color coding: each sender gets a deterministic color (hash of senderId → 12-color palette, dark/light-mode aware), applied to the sender name and a left border on each message
  • Translation: Thai messages get a per-message Translate link → POST /api/translate → Google Translate's free public endpoint (translate.googleapis.com/translate_a/single, no API key) → cached in localStorage by chatId:msgId. Other languages render verbatim.

Auth

middleware.js gates every path except /api/cron/* behind HTTP Basic Auth. Defaults to admin / admin; override via DIGEST_USERNAME / DIGEST_PASSWORD env vars on Vercel.

The cron endpoint stays open at the middleware layer but is gated inside the handler by a Bearer ${CRON_SECRET} check, so only Vercel's scheduler (or you with the secret) can trigger it.

Layout

api/
├── today.mjs           GET — today's digest (or ?date=YYYY-MM-DD)
├── history.mjs         GET — list of available dates
├── refresh.mjs         POST — manual re-run of the digest job
├── translate.mjs       POST — Thai→English via Google Translate free endpoint
└── cron/digest.mjs     Cron: fetch last 24h, store JSON to Vercel Blob

scripts/
└── login.mjs           Two-step non-interactive Telegram login

middleware.js           Basic Auth gate
index.html              Web UI
vercel.json             Cron schedule + function config

Setup

  1. npm install
  2. Telegram API credentials at https://my.telegram.org → set TELEGRAM_API_ID and TELEGRAM_API_HASH in .env.local
  3. npm run login -- request +<phone> → triggers Telegram to send a login code
  4. npm run login -- verify <code> [2fa-pass] → completes sign-in, writes TELEGRAM_SESSION to .env.local
  5. vercel link (already done) and vercel blob create-store morning-digest-blob --access private --yes
  6. Push secrets to Vercel: vercel env add <NAME> production --value <VAL> --yes for each of TELEGRAM_API_ID, TELEGRAM_API_HASH, TELEGRAM_SESSION, DIGEST_TIMEZONE, CRON_SECRET. (Translate uses Google's free endpoint — no API key needed.)
  7. Deploy: vercel --prod --yes

Build plan

  1. Scaffold + GitLab + Vercel link + first prod deploy
  2. Telegram login (non-interactive two-step CLI)
  3. Cron handler — fetches last 24h of DMs + groups, writes to Vercel Blob; /api/today, /api/history, /api/refresh endpoints; collapsible chat UI, DMs sorted above groups
  4. Basic Auth gate via middleware.js
  5. Env wiring (Telegram creds, CRON_SECRET, DIGEST_TIMEZONE, Blob token all set in Vercel)
  6. Per-sender colors + on-demand Thai→English translation (Google free endpoint, no API key)