feat(alerts): add user-defined alert rules with scheduled evaluation and webhook/WhatsApp delivery - #298
Merged
Merged
Conversation
Add user-defined alert rules that notify on portfolio/market conditions (protocol APY, portfolio value, position drawdown) over webhook/WhatsApp. - AlertRule model + migration; nullable unique User.phone for WhatsApp delivery - CRUD API with owner-scoped access (POST/GET/PATCH/DELETE /api/alerts) - Scheduled evaluator with atomic cooldown fire-claim (guards delete-mid-tick, concurrent runners, and threshold-sitting spam) - Delisted PROTOCOL_APY protocols auto-deactivate rather than eval stale data - Reuses HMAC-signed dispatchWebhookEvent (new alert_rule.triggered event) and WhatsApp formatter; no separate failed-delivery sweep (documented decision) - NLP intents + WhatsApp CRUD for conversational rule management - POSITION_DRAWDOWN measured against rolling 30-day portfolio peak - Unit tests for evaluator logic and job behavior; docs/ALERTS.md; openapi.yaml
feat(alerts): custom price & yield alert rules (Neurowealth#289)
… gate The "Merge branch 'main' into main" (d9fabff) dropped code while keeping its usages, failing every CI check. Restore what the merge clobbered: - schema.prisma: re-add PriceSource (Neurowealth#284) and GoalStatus (Neurowealth#281) enums, which the merge replaced with Neurowealth#289's alert enums instead of keeping both. Their usages (User.priceSource, SavingsGoal.status) remained, so `prisma generate` failed P1012 and blocked ci, build, and contract/migration smoke jobs. - nlp/parser.ts: restore the 'goal' member of the Intent action union, dropped by the same merge while parser.ts and handler.ts still emit/switch on it, breaking `tsc` (TS2322/TS2678) and the production build. - add rollback.sql for the Neurowealth#289 alert_rules migration so the rollback gate (scripts/check-migration-rollback.sh) passes.
The Neurowealth#289 alerts merge landed 11 files that Prettier had not been run over, so `format:check` fails on main and blocks build/test for every PR branched from it. Formatting only — no behaviour change.
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
Summary
This PR introduces user-defined alert rules that allow users to receive proactive notifications when portfolio or protocol conditions they care about are met.
Unlike the existing Prometheus/Grafana monitoring—which is intended for platform operators, this feature enables end users to define custom thresholds
closes #289