Skip to content

Quest system add weekly summary email via resend (follows pr #173 issue)#415

Open
clintjeff2 wants to merge 2 commits into
Bitcoindefi:mainfrom
clintjeff2:Quest-system-add-weekly-summary-email-via-Resend-(follows-PR-#173-issue)-#207
Open

Quest system add weekly summary email via resend (follows pr #173 issue)#415
clintjeff2 wants to merge 2 commits into
Bitcoindefi:mainfrom
clintjeff2:Quest-system-add-weekly-summary-email-via-Resend-(follows-PR-#173-issue)-#207

Conversation

@clintjeff2

Copy link
Copy Markdown
Contributor

Motivation

  • Send weekly summaries to registered agents with email addresses summarizing quests completed, XP earned/level changes, leaderboard movement, and top badge.
  • Respect per-agent opt-out and provide a cron/admin-triggered endpoint to call the job.
  • Use Resend (sandbox key in tests) and ensure templates render both plain-text and HTML for 0-quest and multi-quest scenarios.

Description

  • Add an admin-gated endpoint POST /api/admin/send-weekly-summary that enumerates registered agents, skips missing-email or opted-out agents, builds a weekly summary, and calls Resend to send the email (app/api/admin/send-weekly-summary/route.ts).
  • Extend agent registry with optional email and emailOptOut fields and validate/normalize email on registration (lib/agent-registry.ts).
  • Implement weekly summary aggregation and rendering (previous Sunday–Sunday window) producing plain-text and HTML templates with quests, XP, level changes, leaderboard rank movement, and top badge (lib/email/weekly-summary.ts).
  • Add sendRawEmail helper using the RESEND_API_KEY env var and reuse existing Resend/react email flow (lib/email/resend.ts).
  • Capture published system events in-memory so aggregation can inspect recent quest/xp/badge events and add helpers to list/reset events for tests (lib/events/system-events.ts).
  • Add tests that mock the Resend client and verify send behavior, opt-out handling, authorization, and template rendering for 0-quest and 5+-quest scenarios (__tests__/api/weekly-summary.test.ts).

Testing

  • Ran npm test -- __tests__/api/weekly-summary.test.ts and all tests in that file passed (4 tests passed).
  • Ran npm test -- __tests__/api/weekly-summary.test.ts __tests__/api/registry/registry.test.ts and both test files passed (total tests passed).
  • Type-checking with npx tsc --noEmit surfaced unrelated missing dependency errors (lru-cache, @wagmi/connectors) present in the repo and not introduced by this change, so full typecheck was not completed.
  • Lint (npm run lint) reported existing unrelated lint issues elsewhere in the repo and did not block this change.

Closes #207

@sonarqubecloud

Copy link
Copy Markdown

@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, review and merge. Loved this task.

@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, review and merge.

2 similar comments
@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, review and merge.

@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, review and merge.

@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, please review and merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quest system: add weekly summary email via Resend (follows PR #173 issue)

1 participant