Updated - #2
Updated#2
Conversation
Updated configuration for compatibility and observability settings.
…uide-xr5rjj6wxv7xfvj66 Initial commit
…r-duper-guide-xr5rjj6wxv7xfvj66 Revert "Initial commit"
Add deployment guide and update CI workflow for TeamMarySy Bot
|
Telegram-Native Event-Driven Automation System — v1.0 Architecture, Implementation Path & Operational Source of Truth
This document is the authoritative implementation path for the Telegram-native automation system. The system runs as a Cloudflare Worker and uses Telegram as its exclusive operational interface. The architecture enforces: Telegram-First Production execution is provided by Cloudflare Workers. Docker and GHCR are development and CI tooling only.
1.1 Webhook Execution Telegram 1.2 Scheduled Execution Cron Trigger Cloudflare Cron Triggers invoke the Worker "scheduled()" handler and execute according to UTC schedules. Multiple cron expressions can be identified through the scheduled controller, including "controller.cron".
Implementation must proceed in the following order: 01 Foundation A later stage must not bypass an earlier architectural dependency.
Required files: / Tasks:
Completion condition: Repository installs successfully
Implement: src/index.ts Required handlers: fetch() Tasks:
Runtime boundary: fetch() scheduled() No feature logic belongs in either handler. Cloudflare defines "scheduled()" as the Worker handler for Cron Trigger events.
Create a single configuration service. Responsibilities:
Configuration must be validated before use. Critical invariant: Admin Configuration An empty or corrupted administrative configuration must never silently disable all administrative recovery. Required recovery rule: Owner
Create the only persistence interface available to features. Required operations: get() State responsibilities:
Allowed key families: config:* Forbidden: Full Telegram message history Consistency Rule Workers KV is eventually consistent and must not be treated as transactional storage. read → modify → write must not be assumed atomic. Cloudflare explicitly notes that KV is eventually consistent and is not ideal where atomic operations or transactional read/write behavior are required. Durable Objects should be used where stronger consistency is necessary.
Create the single Telegram Bot API gateway. Required methods: sendMessage Responsibilities:
Mandatory rule: Feature Forbidden: Feature
Implement security before feature routing. Execution order: Authentication Tasks:
Security failures must terminate safely.
Transport is the HTTP ingress boundary. Tasks:
Required flow: HTTP Request Forbidden: Transport
The router performs dispatch only. Supported update types: message Required behavior: Update Forbidden: Router The router must not directly modify KV or call Telegram APIs.
Before implementing feature modules, implement shared application services. Required services: Authorization Service This prevents duplicated infrastructure logic inside feature modules.
12.1 Current v1.0 Modules Panel 12.2 Future Modules Buttons Future modules must not be represented as implemented until code, tests, and operational behavior exist.
Content responsibilities: Create All publication paths must converge on: Content.publish() Execution paths: Manual Scheduled This guarantees that manual and scheduled publishing share the same delivery behavior.
Community functionality handles: chat_join_request Authorized operators receive: Approve The implementation relies on Telegram's native pending-request state. No independent join-request archive is required.
Support provides ticket workflows. State: ticket:* Workflow: User Request Invalid or empty input must not create malformed records.
Temporary workflows may contain: workflow_id Requirements:
Example: state:: Workflow state must never become a substitute for message history.
Sequential identifiers may be required for: Ticket Every identifier class must explicitly declare its consistency model. Non-critical identifiers KV may be used when concurrent allocation does not require strict uniqueness. Concurrency-sensitive identifiers Use Durable Objects when allocation requires serialization or strict uniqueness. Concurrent Requests Cloudflare documents Durable Objects as stateful, strongly consistent coordination primitives, in contrast to KV's eventual consistency. Binding rule: Concurrency-sensitive ID A KV counter must not be described as atomic.
The Cron Trigger is the wake-up mechanism. The scheduler is the application execution engine. Cron Trigger Job state: attempts Cleanup: Expired Workflows
Retry behavior is a system invariant. Required strategy: Exponential Backoff Example: delay = Required configuration: base_delay Forbidden: Infinite retries
Multi-Admin Notifications Use failure isolation: Promise.allSettled([ One failed notification must not abort the remaining notifications. Administrative Lockout Protection At startup and before privileged configuration changes: Load Admin Configuration Forbidden: Empty Admin List
Logging Allowed: update type Forbidden: Bot Token Error Classes AuthenticationError Internal errors must be sanitized before reaching Telegram users.
Unit Routing Integration Webhook Feature Feature Cron Negative Invalid Secret
Docker is a development and CI environment. It is not the production Worker runtime. Preferred toolchain: GHCR Image Pinned image: ghcr.io//wrangler:1.0.423 The exact image reference must be defined by CI. Secrets must never be baked into the image.
FROM ghcr.io//wrangler:1.0.423 WORKDIR /app ENV NODE_ENV=development COPY package*.json ./ RUN npm ci COPY . . RUN npm run typecheck CMD ["npm", "run", "dev"] Required secret rule: TELEGRAM_BOT_TOKEN must not exist in the image filesystem or Dockerfile. If the pinned GHCR image does not contain the required Node/npm toolchain, use an appropriate Node base image and install the required Wrangler version explicitly.
Canonical: npx wrangler dev Docker: docker build -t telegram-worker-dev . docker run --rm -it Scheduled execution can be tested locally through the scheduled-event endpoint supported by Wrangler/Workers.
Because the repository uses GitHub, GitHub Actions is the authoritative CI system. Pipeline: validate GitHub Actions supports explicit job dependencies through "needs", container-based jobs, and environment-scoped secrets. Required controls:
Production flow: GitHub Cloudflare resources: Worker Docker terminates at the CI/toolchain boundary. It does not become the production runtime.
Deployment sequence: Deploy Worker Verification must confirm: Webhook URL
Production must not be considered ready until every required control passes. [ ] Worker deployed
Completed Webhook processing In Progress / Stubbed Content creation UX No architectural target may be reported as implemented until code, tests, and operational behavior are present.
Required Webhook Security Router Features State Layer Telegram Client Scheduler Docker / GHCR Cloudflare Worker Mandatory Safety Rules Admin configuration Retry system Concurrency-sensitive IDs Forbidden Business logic in webhook
The architecture is considered complete when:
Runtime Scheduler Cron Trigger Engineering GitHub This is the authoritative implementation path for v1.0. |
No description provided.