How miketester10/aztec-bot works
Project type and purpose
• This is a TypeScript–based Telegram bot (“Aztec Bot”) that fetches and delivers real-time stats on validators and epochs from the gAztec network.
• It runs as a backend service, exposes a webhook endpoint (via ngrok or a public host), processes Telegram updates, queries the Aztec network APIs, and caches or persists state in Redis.
File structure
• Top-level:
• docker-compose.yml + redis/docker-compose.yml → orchestrate the bot service and Redis.
• generate_ngrok_url.sh → script for obtaining a public URL to expose the local webhook server.
• proxies.json → configuration for HTTP/HTTPS proxies (likely for API calls).
• src/ → application code.
• src subdirs:
• handlers/ → core logic modules:
– server-handler.ts routes incoming HTTP/webhook requests;
– commands-handler.ts processes Telegram commands;
– proxy-handler.ts applies proxy logic for outbound calls;
– aztec-handler.ts fetches data from the Aztec network.
• interfaces/ → TypeScript interfaces for request/response payloads.
• logger/ → centralized logging.
• main.ts → entry point (bootstraps server, connects Redis, sets up routes).
• Config: package.json/tsconfig.json manage dependencies/build; .env.example holds environment variables (bot token, Redis URL, webhook secret, etc.).
README for additional insights
• Confirms it’s a “bot” with a webhook and real-time stats.
• Points to official Aztec docs for deeper API details.
• Mentions a working Telegram bot URL, implying Telegram Bot API integration.
Main components and interactions
a. Components
• Telegram Bot API (external)
• Ngrok (or public HTTPS endpoint)
• Bot Service (Docker container)
– HTTP server (Express/Koa)
– Handlers: server, commands, proxy, aztec
– Consts, Interfaces, Logger
• Redis (Docker container)
• Aztec Network API (external)
• Proxy Service or Layer (config in proxies.json)
b. Relationships / Data flow
1. Telegram → (HTTPS webhook) → Ngrok/Public endpoint → Bot Service HTTP Server
2. server-handler routes to commands-handler or proxy-handler
3. Handlers call aztec-handler to fetch stats from Aztec API (optionally via proxy)
4. Bot Service writes/reads cache or session data in Redis
5. Bot Service posts responses back to Telegram Bot API
c. Architectural patterns / design principles
• Layered architecture: presentation (HTTP/webhook), application (handlers), infrastructure (Redis, external APIs)
• Single responsibility per handler
• Configuration-driven proxies
• Docker-based isolation and orchestration for repeatable deployments
d. Key technologies
• Node.js + TypeScript
• Express or similar HTTP framework
• Redis for caching/state
• Ngrok for local development webhook exposure
• Docker & Docker Compose
• Telegram Bot API
• Aztec Network REST API