← All tests

M3 Telegram Integration (local)

NIX-OS-73 — per-tenant Telegram bot integration for NIX Cafe. Admin UI to manage bot token + groups, inbound webhook for slash commands (/report, /chatid, /help), and a scheduled daily report push endpoint.

7/7 local checks passed.

What's new — code surface

Migration:
  migrations/20260421500000_cafe_telegram_integration.ts
  migrate.js (prod runner entry)

Cafe app:
  lib/telegram/client.ts              — getMe, sendMessage, setWebhook, deleteWebhook
  lib/db/telegram.ts                  — DAO: tokens, groups CRUD, send log
  lib/actions/telegram.ts             — 6 server actions (save token, CRUD groups, test send, re-register webhook)
  app/(authed)/telegram/page.tsx      — admin page server component
  app/(authed)/telegram/telegram-client.tsx — admin UI (token, groups, send log)
  app/api/telegram/webhook/[tenantCode]/route.ts — inbound handler
  app/api/telegram/cron/daily/route.ts          — scheduled push endpoint
  middleware.ts                       — bypass session auth for webhook + cron
  lib/db/schema.ts                    — drizzle schema additions

cafe.telegram_groups — schema

Loading…

cafe.telegram_send_log — schema

Loading…

Known follow-ups (not blocking this deploy)

• Cron wiring: CAFE_CRON_SECRET needs to be set on the CF Pages env + a Cloudflare Cron Trigger bound to POST /cafe/api/telegram/cron/daily.
  Without that binding the endpoint exists but never fires.
• NIX_COMMERCE_HOST env: used to build the absolute webhook URL. Default is https://nixtech.app; set explicitly for any env where that's not right.
• Telegram MarkdownV2 escaping: sendMessage attempts MarkdownV2 and falls back to plain on error. Watch the send-log for patterns of fallback use — may need to add proper escaping later.
• Authenticated UI screenshot: skipped locally (Commerce SSO isn't running on localhost). Gate 2 will capture it on prod.