How emresavas/forms-to-ms-teams-worker works
Project Type and Purpose
• This is a serverless, backend‐only Cloudflare Worker whose sole purpose is to accept authenticated form submissions (JSON or form data) from allowed origins and forward them into Microsoft Teams channels via webhooks. There is no persistent data store or frontend code in this repo—clients are entirely external (e.g., any HTML page or script).
Main Components
a. Client (Web Browser or Other HTTP Client)
• Hosts/form page or any HTTP‐capable client that issues a POST to the Worker endpoint
• Supplies JSON or form‐encoded payload + x-api-key header
b. Cloudflare Edge (Worker)
• src/index.js: main request handler
• API Key Authentication logic (compares header vs. API_KEY secret)
• Domain Whitelisting logic (compares request’s Origin or Referer header vs. ALLOWED_DOMAINS var)
• Formatting logic (transforms incoming payload into Teams message card or simple JSON)
• Outbound HTTP POST to Teams webhook
c. Configuration/Secrets
• wrangler.toml: Cloudflare account ID, zone, route
• Environment vars: ALLOWED_DOMAINS, TEAMS_WEBHOOK_URL under [vars]
• Secret: API_KEY (via wrangler secret put)
d. External Service
• Microsoft Teams incoming webhook endpoint
Relationships & Data Flow
1. Client → Worker Endpoint (HTTPS POST)
• Sends payload + x-api-key
2. Worker:
• Validate API key → If invalid, return 401
• Check Origin/Referrer against allowed domains → If invalid, 403
• Normalize/format payload into Teams message structure
3. Worker → Microsoft Teams Webhook (HTTPS POST)
• Forward formatted message
4. Worker → Client (Response)
• HTTP 200 on success or appropriate error code
Architectural Patterns & Principles
• Serverless function (FaaS) for maximal simplicity and zero server management
• API Gateway-style authentication at edge
• Single responsibility: capture, validate, transform, forward
• Configuration via environment (12-factor app)
• No persistent data storage—stateless design
Technologies & Libraries
• Node.js runtime inside Cloudflare Workers (service worker style)
• wrangler for build/deploy
• Native Fetch API in Workers for outbound calls
• dotenv-style config via wrangler.toml and secrets
Essential Details to Capture
• How requests are authenticated and authorized
• Environment vars vs. secrets management
• The synchronous, stateless path from client to Teams
• Clear error vs. success flow