Repository navigation
feat: add WhatsApp message templates, automated rules, and safety controls - #1315
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@greptileai review this at apex |
[Medium impact] The changes extend WhatsApp messaging across one merchant workflow, including automated customer outreach. Fix the stopped scheduler, blocked recipient batches, missed feedback, duplicate milestones, and settings overwrite before merging. Findings
|
…d loyalty threshold checks
… fixes and simplifications
…yout-integrity.spec.ts` (`drains multiple cursor pages, deduplicates overlapping orders, removes completed orders, and clears on follow-up page 401`) that caused `Playwright E2E (Shard 2/4)`, `End-to-End Playwright Tests`, and `Required Checks Gate` to fail: - **Invariant:** Whenever an E2E test navigates to `/customer-display` with a paused Playwright fake clock (`clock.pauseAt`), the test must advance the paused clock across both sequential mount `setTimeout(..., 0)` ticks - first until the token-resolution timer has committed the `<header>` render and registered the post-token `useEffect`, and second to fire the initial feed `setTimeout(refresh, 0)`. - **Root cause & fix (`frontend/e2e/layout-integrity.spec.ts`):** `budgetPage.clock.pauseAt` was called before `budgetPage.goto`, so a single `budgetPage.clock.runFor(1)` only fired the token-resolution `setTimeout(..., 0)` and left the subsequent `setTimeout(refresh, 0)` frozen on the paused clock, causing `await slowPage1Arrived` to time out after 30s. Closed `displayPage` after its assertions complete, installed the `budgetPage` clock at `initialClockMs - 60_000` before pausing at `initialClockMs`, and polled `clock.runFor(1)` until `<header>` is rendered before advancing `clock.runFor(1)` to trigger the initial feed fetch at both pre-`goto` `clock.pauseAt` sites in `frontend/e2e/layout-integrity.spec.ts`. - **Verification:** Ran `npm run build`, `npm run build:frontend`, `npx playwright test --config=playwright.config.ts --project=chromium e2e/layout-integrity.spec.ts -g "customer display wraps full receipt numbers and pages on TV"` (12 passed), `npm run test:whatsapp-service`, `npm run lint`, `node scripts/ci/check-changed-format.cjs --base 8a0c272`, `npm run docs:check`, `npm run i18n:check`, and `git diff --check`
7452e67 to
29671a8
Compare
|
@greptileai review this at apex |
Intent
Implement WhatsApp message templates, automated sending rules, and anti-ban safety controls for Issue #1239
What Changed
shared/whatsapp-automation.ts) for customizable templates (receipt,feedback,loyalty_milestone,visit_milestone,winback), five trigger rules (after_payment,feedback_delay,winback,points_threshold,nth_visit), and safety settings stored underwhatsapp_automation_config.main/services/whatsapp.ts,main/routes/whatsapp.ts, andmain/routes/bills.tswith post-payment rule evaluation, a 5-minute scheduled sweep (POST /api/whatsapp/automation/run-sweep), filtered segment broadcasts (POST /api/whatsapp/automation/broadcast), inboundSTOP/UNSUBSCRIBEauto-opt-out blocklisting, store-timezone quiet hours, per-customer weekly caps, andtrigger_rulemessage attribution.Templates & Rulesmanagement tab on the WhatsApp dashboard (frontend/src/app/(dashboard)/whatsapp/page.tsxand 25 locale bundles), expandedtests/whatsapp-service.test.tscoverage, and updated API and cloud-integration documentation.Risk Assessment
✅ Low: All 32 changed files across shared automation contracts, backend WhatsApp service and routes, bill payment hooks, frontend WhatsApp automation UI, i18n locale bundles, documentation, and unit tests were inspected. Prior review findings and Greptile feedback (quiet-hours timezone resolution, split-bill item scoping and nth-visit order deduplication, sweep lookback window and recipient cooldowns, failed-row retry caps, blocklist re-verification after typing delay, and frontend load-error save protection) are cleanly resolved with comprehensive test coverage.
Testing
Built the backend and static desktop frontend, ran focused WhatsApp and translation test suites (test:whatsapp-service, test:whatsapp-middleware, test:whatsapp-schema, test:translations), and drove 5 live end-to-end browser and API scenarios against the running FloCafe server and headless Chromium with 6 UI screenshots and structured API/DB evidence captured under ~/.no-mistakes/evidence/01M5K0G1CQ8TVDHJGAN05GW6X5.
Evidence: Live WhatsApp automation E2E API and database evidence JSON
{ "scenario1_template_and_rule_configuration": { "savedSafety": { "autoOptOutEnabled": true, "quietHoursEnabled": false, "quietHoursStart": "22:00", "quietHoursEnd": "09:00", "maxPerCustomerPerWeek": 5, "feedbackLink": "https://flocafe.example.com/feedback" } }, "scenario2_post_payment_automation": { "billId": 503, "billNumber": "INV-20261023-0001", "loyaltyPointsEarned": 150, "rulesTriggered": ["after_payment", "points_threshold", "nth_visit"] }, "scenario3_sweep_and_broadcast": { "outboundCount": 6, "rulesObserved": ["feedback_delay", "winback", "broadcast", "after_payment", "points_threshold", "nth_visit"] }, "scenario4_inbound_stop_auto_opt_out": { "blockedPhone": "+14089961099", "blockedSendResponse": { "status": 400, "data": { "error": "This number asked to stop receiving messages.", "reason": "blocked" } } }, "scenario5_adversarial_safety_guards": { "quietAutoSend": { "ok": false, "reason": "quiet_hours" }, "quietManualReply": { "ok": true }, "weeklyAuto2": { "ok": false, "reason": "weekly_cap" }, "weeklyManualReply": { "ok": true }, "shortenerRejected": { "status": 400, "data": { "reason": "content_blocked" } } } }Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
npm run buildnpm run build:frontendnpm run test:whatsapp-servicenpm run test:whatsapp-middlewarenpm run test:whatsapp-schemanpm run test:translationsnode tests/_tmp-live-whatsapp-validation.cjs (live Playwright + Express/SQLite E2E validation across 5 scenarios)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.