Repository navigation
Server: API Routes & Infrastructure #11
Copy link
Copy link
Open
Labels
Description
Summary
Implement the Next.js server with all API routes — the actual HTTP surface of OpenThreads. This includes the core sending endpoint, channel webhook receivers, management CRUD API, and server infrastructure.
Tasks
Recipient Inbound (core sending endpoint)
-
POST /send/channel/:channelId/target/:groupOrUser/thread/:threadIdOrMessageId- Auth: ephemeral token (
?token=) OR channel API key (Authorization: Bearer) - Body:
{ message: object | array } - Creates thread if
:threadIdOrMessageIdabsent - Returns: synchronous response for A2H blocking intents, 202 for fire-and-forget
- Auth: ephemeral token (
-
POST /send/channel/:channelId/target/:groupOrUser— new thread variant
Channel Inbound Webhooks
-
POST /webhook/:channelId— generic webhook receiver per channel- Verify platform-specific signatures (Slack signing secret, Telegram token hash, etc.)
- Parse platform event → normalized inbound message
- Run through Router → fan out to matched recipients
Management API (CRUD)
-
GET/POST /api/channels— list / create channels -
GET/PUT/DELETE /api/channels/:id— channel detail / update / delete -
GET/POST /api/recipients— list / create recipients -
GET/PUT/DELETE /api/recipients/:id -
GET/POST /api/routes— list / create routes -
GET/PUT/DELETE /api/routes/:id -
GET /api/threads— list threads (filterable by channel, target) -
GET /api/threads/:threadId— thread detail -
GET /api/threads/:threadId/turns— list turns in thread
Auth
- Management API authentication (API key or session-based for dashboard)
- Ephemeral token validation middleware
- Channel API key validation middleware
Infrastructure
- Request logging and error handling middleware
- Rate limiting on public endpoints (webhook inbound, form submission)
- Health check endpoint (
GET /health) - Graceful shutdown (close channel subscriptions, drain pending requests)
Acceptance Criteria
- Recipient can POST to
/send/...with token and receive response - Recipient can POST to
/send/...with API key and send proactively - Channel webhooks receive and correctly route inbound messages
- Management CRUD works for all entities
- Invalid tokens/keys return 401
- Rate limiting prevents abuse on public endpoints
- Health check returns 200 with status
Dependencies
- Core: Router Implementation #3 (Core: Router) — webhook handler invokes the router
- Core: Reply Engine #4 (Core: Reply Engine) — send endpoint invokes the reply engine
- Core: Token & Thread/Turn Management #5 (Core: Token & Thread Management) — auth middleware and thread creation
- Storage: MongoDB Adapter #6 (Storage: MongoDB Adapter) — persistence for all entities
- Channel: Slack Adapter #7 (Channel: Slack Adapter) — at least one adapter needed for E2E validation
Activity
claude commentedon Apr 10, 2026
@claude Implement this issue.
meta/17meta/17fixes #11in the PR bodyThis is P0 — auto-merge is enabled.
claude commentedon Apr 10, 2026
Claude finished @claude[bot]'s task in 14m 59s —— View job •
claude/17-issue-11-20260410-2220• Create PR ➔Implementing Issue #11: Server API Routes & Infrastructure
Todo List
mongodbdependency to server packagelib/db.ts— MongoDB singleton + typed CRUD helperslib/auth.ts— token/API key validation middlewarelib/rate-limit.ts— in-memory sliding-window rate limiterlib/logger.ts— structured request logginglib/fanout.ts— concurrent recipient deliveryGET /healthandGET /api/healthPOST /send/channel/:channelId/target/:groupOrUser— new thread sendPOST /send/.../thread/:threadId— existing thread sendPOST /webhook/:channelId— channel webhook receiver (Slack + Telegram sig verification)instrumentation.ts— graceful shutdown on SIGTERM/SIGINTWhat was implemented
23 files, 2036 insertions across the
packages/server/package:/send/channel/[channelId]/target/[groupOrUser]/route.ts(new thread) and.../thread/[threadId]/route.ts(existing thread)/webhook/[channelId]/route.ts— Slack HMAC + Telegram token verification, event normalization, router fan-out/api/channels,/api/recipients,/api/routes,/api/threads+ detail/turns routes — all with management API key auth/health+/api/health— MongoDB ping + uptimelib/auth.ts— ephemeral token, channel API key, management keylib/rate-limit.ts— 60 req/min for webhooks, 30/min for sendlib/db.ts— MongoDB singleton, typed CRUD helpers, index setuplib/fanout.ts— concurrent delivery to matched recipients via fetch()src/instrumentation.ts— SIGTERM/SIGINT → MongoDB close| Branch