This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run dev — Start local dev server (Wrangler)npm run deploy — Deploy to Cloudflare Workers (wrangler deploy)npm test — Run tests with Vitest (Cloudflare Workers pool)npm run cf-typegen — Regenerate TypeScript types from Wrangler configTelegram bot for the CosMoe photography platform (https://cos.cx/api/v1), deployed as a Cloudflare Worker with a 1-minute cron trigger.
src/index.ts)Bot, registers commands via setupCommands(), delegates to webhookCallback.src/command/index.ts)setupCommands() wires grammy commands, conversation plugins, regex-based hears handlers, and callbackQuery handlers. The conversations plugin uses KV-backed storage for multi-step flows (login).
Bot commands: start, login, events, history, logout
Pattern handlers: /event_{id}, /book_{eventId}_{slotIndex}, /cancel_{bookingId}
Callback queries: cancel confirmation, coupon selection
src/command/handlers/)Each is a standalone async function. Most follow the pattern: authenticate user from KV → call CosMoe API → format and reply.
src/client/cosmoe.ts)CosmoeClient wraps the CosMoe REST API. Auth uses user_id + token passed as URL params (GET) or FormData (POST). Credentials are stored per-user in COSMOE_CREDENTIALS KV keyed by Telegram user ID.
src/scheduler/index.ts)Tracks notified event IDs in COSMOE_STORAGE KV to avoid duplicate notifications. Iterates all credential keys to broadcast to every registered user.
COSMOE_CREDENTIALS — Per-user auth tokens (keyed by Telegram user ID)COSMOE_STORAGE — Conversation state and scheduler dataEnv interface is defined separately in src/command/index.ts; handlers receive env as an untyped any parameter.@cloudflare/vitest-pool-workers for the Workers runtime.