Skip to content

Latest commit

 

History

History
68 lines (50 loc) · 3.07 KB

File metadata and controls

68 lines (50 loc) · 3.07 KB

TODO — Avalanche Canada SMS Service

Phase 1: Project Setup

  • Initialize npm project with TypeScript
  • Install dependencies: hono, vitest, wrangler
  • Configure tsconfig.json for Cloudflare Workers
  • Configure wrangler.toml
  • Set up Vitest config
  • Create src/index.ts with Hono app skeleton and route registration

Phase 2: Coordinate Parsing

  • Implement raw coordinate parsing (decimal degrees, comma-separated, cardinal directions)
  • Implement Apple Maps URL parsing (extract ll / q params from maps.apple.com URLs)
  • Implement Google Maps URL parsing (extract coords from google.com/maps path and query params)
  • Implement shortened URL resolution for maps.app.goo.gl and goo.gl/maps (follow redirect, then parse)
  • Implement Canadian bounds validation (lat 40-70, lng -145 to -50)
  • Write unit tests for all coordinate formats, edge cases, and invalid input

Phase 3: Avalanche Canada API Client

  • Implement forecast fetch via api.avalanche.ca/forecasts/en/products/point?lat=&long=
  • Define TypeScript types for the API response (danger ratings, problems, highlights, dates)
  • Handle API errors (network failure, 404 no region, unexpected response shape)
  • Write unit tests with mocked API responses (success, no region, error)

Phase 4: Forecast Formatting

  • Implement template formatter producing <=160 character SMS reply
  • Handle danger rating enum-to-string mapping (low through extreme)
  • Handle truncation of problem list and region name to stay within 160 chars
  • Write unit tests with various forecast fixtures (short name, long name, many problems, no problems)

Phase 5: SMS Webhook Endpoint

  • Implement POST /sms/incoming route
  • Parse Twilio webhook body (form-encoded: Body, From, MessageSid)
  • Wire together: parse coordinates -> fetch forecast -> format -> TwiML response
  • Implement Twilio request signature validation (with env var to disable in dev)
  • Implement error reply messages for each failure case
  • Write integration tests with mocked Twilio requests and Avalanche.ca responses

Phase 6: Health Endpoint

  • Implement GET /health returning { "status": "ok" }

Phase 7: In-Memory Stats

  • Implement stats store (circular buffer, counters, region map, uptime)
  • Instrument SMS handler to record each request
  • Implement phone number masking (+1******7890)

Phase 8: Admin Dashboard

  • Implement GET /admin/stats JSON endpoint
  • Build admin HTML page (inline CSS, vanilla JS, no framework)
  • Display uptime, total requests, error count, recent requests table, requests-by-region list
  • Poll /admin/stats every 30 seconds
  • Implement GET /admin serving the HTML page

Phase 9: Deploy & Configure Twilio

  • Deploy to Cloudflare Workers (or Lambda)
  • Set environment variables / secrets (TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
  • Acquire Twilio phone number
  • Configure Twilio incoming message webhook URL to point to deployed /sms/incoming
  • End-to-end test: send SMS, receive forecast reply