mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-04-17 15:20:58 +00:00
grammY-based bot with a module plugin system loaded from the MODULES env var. Three command visibility levels (public/protected/private) share a unified command namespace with conflict detection at registry build. - 4 initial modules (util, wordle, loldle, misc); util fully implemented, others are stubs proving the plugin system end-to-end - util: /info (chat/thread/sender ids) + /help (pure renderer over the registry, HTML parse mode, escapes user-influenced strings) - KVStore interface with CFKVStore and a per-module prefixing factory; getJSON/putJSON convenience helpers; other backends drop in via one file - Webhook at POST /webhook with secret-token validation via grammY's webhookCallback; no admin HTTP surface - Post-deploy register script (npm run deploy = wrangler deploy && node --env-file=.env.deploy scripts/register.js) for setWebhook and setMyCommands; --dry-run flag for preview - 56 vitest unit tests across 7 suites covering registry, db wrapper, dispatcher, help renderer, validators, and HTML escaper - biome for lint + format; phased implementation plan under plans/
4.7 KiB
4.7 KiB
Phase 01 — Scaffold project
Context Links
- Plan: plan.md
- Reports: wrangler + secrets
Overview
- Priority: P1 (blocker for everything)
- Status: pending
- Description: bootstrap repo structure, package.json, wrangler.toml template, biome, vitest, .gitignore, .dev.vars.example. No runtime code yet.
Key Insights
nodejs_compatflag NOT needed — grammY + our code uses Web APIs only. Keeps bundle small.MODULESmust be declared as a comma-separated string in[vars](wrangler does not accept top-level TOML arrays in[vars])..dev.varsis a dotenv-format file for local secrets — gitignore it. Commit.dev.vars.example.- biome handles lint + format in one binary. Single config file (
biome.json). No eslint/prettier.
Requirements
Functional
npm installproduces a working dev environment.npm run devstartswrangler devon localhost.npm run lint/npm run formatwork via biome.npm testruns vitest (zero tests initially — exit 0).wrangler deploypushes to CF (will fail without real KV ID — expected).
Non-functional
- No TypeScript.
.js+ JSDoc. - Zero extra dev deps beyond:
wrangler,grammy,@biomejs/biome,vitest.
Architecture
miti99bot/
├── src/
│ └── (empty — filled by later phases)
├── scripts/
│ └── (empty — register.js added in phase-07)
├── tests/
│ └── (empty)
├── package.json
├── wrangler.toml
├── biome.json
├── vitest.config.js
├── .dev.vars.example
├── .env.deploy.example
├── .gitignore # add: node_modules, .dev.vars, .env.deploy, .wrangler, dist
├── README.md # (already exists — updated in phase-09)
└── LICENSE # (already exists)
Related Code Files
Create
package.jsonwrangler.tomlbiome.jsonvitest.config.js.dev.vars.example.env.deploy.example
Modify
.gitignore(addnode_modules/,.dev.vars,.env.deploy,.wrangler/,dist/,coverage/)
Delete
- none
Implementation Steps
npm init -y, then editpackage.json:"type": "module"- scripts:
dev→wrangler devdeploy→wrangler deploy && npm run registerregister→node --env-file=.env.deploy scripts/register.js(auto-runssetWebhook+setMyCommands— see phase-07)lint→biome check src tests scriptsformat→biome format --write src tests scriptstest→vitest run
npm install grammynpm install -D wrangler @biomejs/biome vitest- Pin versions by checking
npm view <pkg> versionand recording exact versions. - Create
wrangler.tomlfrom template in research report — leave KV IDs asREPLACE_ME. - Create
biome.jsonwith defaults + 2-space indent, double quotes, semicolons. - Create
vitest.config.jswithenvironment: "node"(pure logic tests only, no workerd pool). - Create
.dev.vars.example(local dev secrets used bywrangler dev):TELEGRAM_BOT_TOKEN= TELEGRAM_WEBHOOK_SECRET= - Create
.env.deploy.example(consumed byscripts/register.jsin phase-07; loaded vianode --env-file):TELEGRAM_BOT_TOKEN= TELEGRAM_WEBHOOK_SECRET= WORKER_URL=https://<worker-subdomain>.workers.dev - Append
.gitignoreentries. npm run lint+npm test+wrangler --version— all succeed.
Todo List
npm init, settype: module, scripts- Install runtime + dev deps
wrangler.tomltemplatebiome.jsonvitest.config.js.dev.vars.example- Update
.gitignore - Smoke-run
npm run lint/npm test
Success Criteria
npm installexits 0.npm run lintexits 0 (nothing to lint yet — biome treats this as pass).npm testexits 0.npx wrangler --versionprints a version.git statusshows no tracked.dev.vars, nonode_modules.
Risk Assessment
| Risk | Likelihood | Impact | Mitigation |
|---|---|---|---|
| wrangler version pins conflict with Node version | Low | Med | Require Node ≥ 20 in engines field |
| biome default rules too strict | Med | Low | Start with recommended; relax only if blocking |
type: module trips vitest |
Low | Low | vitest supports ESM natively |
Security Considerations
.dev.varsMUST be gitignored. Double-check before first commit.wrangler.tomlMUST NOT contain any secret values — only[vars]for non-sensitiveMODULES.
Next Steps
- Phase 02 needs the fetch handler skeleton in
src/index.js. - Phase 03 needs the KV binding wired in
wrangler.toml(already scaffolded here).