How dan3612812/btsnotify works
Project type and purpose
• This is a Node.js/TypeScript backend tool (a “BOT”) that periodically crawls Apple’s “back-to-school” (BTS) web pages, detects when a BTS campaign is live for different regions, and pushes notifications via a Telegram bot.
File structure
• Top-level:
• example.env, tsconfig.json, package.json (configuration & dependencies)
• reference/… (static screenshots for testing/documentation)
• src/ – main codebase
• src/crawler: HTML-scraping logic
• src/service: orchestration & BTS-detection rules
• src/notify: Telegram‐bot client & message dispatch
• src/lib: shared utilities (HTTP, HTML parsing, retry, logging)
• src/env: configuration loader (API tokens, URLs)
• src/index.ts: entry point that wires everything together
README for additional insights
• The README describes four heuristics for detecting BTS availability (URL patterns, sitemap inspection, redirect behavior, page‐rel links).
• It references a Telegram BOT and channel to send updates.
a. Main components
1. Scheduler/Executor (src/index.ts)
2. Crawler Module (src/crawler/*)
3. Business‐Logic Service (src/service/*)
4. Notification Module (src/notify/*)
5. Configuration Loader (src/env/*)
6. Utility Library (src/lib/*)
7. External Systems:
• Apple Web (various URLs, sitemap)
• Telegram Bot API
b. Relationships & interactions
• The Scheduler triggers the Crawler at configured intervals.
• The Crawler issues HTTP requests (via lib/http) to Apple URLs, retrieves HTML.
• Retrieved HTML is handed to the Service, which applies detection rules.
• If a BTS campaign is found, Service invokes the Notify module.
• Notify constructs and sends messages to Telegram via Telegram API.
• Env module provides API keys, region lists, and schedule settings to all modules.
c. Architectural patterns & design principles
• Modular layering: crawler, business logic, notification are decoupled.
• Single responsibility per module.
• Configuration‐as‐code (env loader centralizes secrets and URLs).
• Reusable utilities in lib to avoid duplication (HTTP, parsing, logging).
d. Key technologies & libraries
• Node.js + TypeScript
• Axios or node-fetch (HTTP requests)
• Cheerio (HTML parsing)
• dotenv (env configuration)
• Telegram Bot API client
Essential elements
• Module names and boundaries
• Config flows (Env → all modules)
• Data flows and triggers (interval or cron)
• External endpoints (Apple URLs, Telegram API)
• Error/Retry path (optionally annotate lib’s retry logic)