# Tasks: add-whatsapp-inbox Design: `design.md` and `docs/superpowers/specs/2026-12-02-whatsapp-inbox-design.md`. Every task is TDD, followed by the review gate (an Opus reviewer). At most 2 workers run at once (owner, 2026-12-01). Waves list tasks that may run in parallel in separate worktrees. Everything else runs serially in order. Verify commands: - **Backend:** `mvn -T 1C -q -pl verify` (`-T 0.5C` while a wave builds at the same time). - **Portal:** `cd solvway-admin-portal && npx vitest run; echo VITEST=$? && npx tsc --noEmit && npm run lint` (check the vitest exit code). ## Wave 1 (serial: contracts and hotspots) - [x] 1.1 Schema and modules: `sql/01-whatsapp-schema.sql`, `sql/02-whatsapp-modules.sql` and `sql/99-rollback.sql` in this change folder, mirrored into `local/seed/`. - Depends on: none - Scope: `openspec/changes/add-whatsapp-inbox/sql/**`, `local/seed/**` - Verify: load the seed into a fresh local MySQL volume (compose `down -v` on a throwaway project name, then `up mysql`) and list the tables. - [x] 1.2 Service skeleton: `solvway-services-whatsapp` module (pom, Dockerfile, `application.yml`, settings binding, health), root pom module entry, the gateway route `Path=/whatsapp/**`, and compose entries for the service and `whatsapp-mock`. The mock is a skeleton that answers health. - Depends on: 1.1 - Scope: `solvway-services-whatsapp/**`, `pom.xml`, `solvway-api-gateway/src/main/resources/application.yml`, `local/docker-compose.yml`, `local/whatsapp-mock/**`, `local/.env.example` - Verify: `mvn -T 1C -q -pl solvway-services-whatsapp,solvway-api-gateway verify` - [x] 1.3 Shared DTOs and API constants: the webhook ingest body, conversation and message views, and `RestApiWhatsappServiceConstants` in mobile-api. - Depends on: 1.2 - Scope: `solvway-services-whatsapp/src/main/java/**/dto/**`, `solvway-mobile-api/src/main/java/**/constant/api/RestApiWhatsappServiceConstants.java`, `solvway-mobile-api/src/main/java/**/dto/whatsapp/**` - Verify: `mvn -T 1C -q -pl solvway-services-whatsapp,solvway-mobile-api verify` ## Wave 2 (parallel: 2.1 and 2.2) - [x] 2.1 Service ingest: - number-to-company routing restricted to the matched companies; - conversation upsert and the message insert, idempotent on `wamid`; - the status ranking; - `last_inbound_at`. - Depends on: 1.3 - Scope: `solvway-services-whatsapp/src/main/java/**` except `meta/**` and `dto/**`, `solvway-services-whatsapp/src/test/**` - Verify: `mvn -T 0.5C -q -pl solvway-services-whatsapp verify` - [x] 2.2 Counter lead lookup: `GET /counter/lead/whatsappContact` (newest lead by mobile, its latest salesperson), and the best-effort `leadChanged` notify on the event lead save paths (capture, salesperson change). - Depends on: 1.3 - Scope: `solvway-services-counter/**` - Verify: `mvn -T 0.5C -q -pl solvway-services-counter verify` ## Wave 3 (parallel: 3.1 and 3.2) - [x] 3.1 mobile-api webhook: the GET handshake, the POST raw-body HMAC against each company secret, forwarding to ingest, the per-IP limit, the public-route exemptions, and `LogRedactor` masking for the webhook query. - Depends on: 2.1 - Scope: `solvway-mobile-api/src/main/java/**/whatsapp/**`, `solvway-mobile-api/src/main/java/**/controller/PublicWhatsApp*`, `solvway-mobile-api/src/test/**/whatsapp/**`, `solvway-api-gateway/src/main/java/**/LogRedactor.java`, `solvway-api-gateway/src/test/**/LogRedactorTest.java`, and the public-path exemption config (security code: also read the whole diff in the controller check) - Verify: `mvn -T 0.5C -q -pl solvway-mobile-api,solvway-api-gateway verify` - [x] 3.2 Service ownership: `OwnershipService.recompute`, the user access check, the `leadChanged` and `userChanged` endpoints, manual assign and automatic return, and the nightly job. - Depends on: 2.1, 2.2 - Scope: `solvway-services-whatsapp/src/main/java/**/ownership/**`, `solvway-services-whatsapp/src/main/java/**/job/**`, `solvway-services-whatsapp/src/test/**/ownership/**` - Verify: `mvn -T 0.5C -q -pl solvway-services-whatsapp verify` ## Wave 4 (serial) - [x] 4.1 Meta client and sending: text inside the window, templates with parameter validation, template sync per company, the media proxy, error mapping to failed, and "not configured". The mock gains the Graph endpoints and `/simulate/inbound`. - Depends on: 3.2 - Scope: `solvway-services-whatsapp/**`, `local/whatsapp-mock/**` - Verify: `mvn -T 1C -q -pl solvway-services-whatsapp verify` - [x] 4.2 mobile-api admin API: every endpoint in design decision 9, module checks, company scoping (fail closed), audit, and the `userChanged` call from the user save path. - Depends on: 4.1 - Scope: `solvway-mobile-api/**` (security code: also read the whole diff in the controller check) - Verify: `mvn -T 1C -q -pl solvway-mobile-api verify` ## Wave 5 (parallel: 5.1 and 5.2) - [ ] 5.1 Portal inbox: - the `/whatsapp` page, with list tabs, search, thread, bubbles and ticks, the window state, the composer and template picker, media rendering, and assign controls for admins; - polling; - proxies under `app/api/admin/whatsapp/**`; - `routeModules`. - Depends on: 4.2 - Scope: `solvway-admin-portal/app/whatsapp/**`, `solvway-admin-portal/app/api/admin/whatsapp/**`, `solvway-admin-portal/app/components/whatsapp/**`, `solvway-admin-portal/app/lib/services/whatsapp*`, `solvway-admin-portal/app/lib/routeModules*` - Verify: portal verify - [ ] 5.2 Portal sidebar and buttons: - `BO_WHATSAPP` in the Leads section with `MessageCircle` and the unread badge; - WhatsApp buttons on leads and event leads rows and phone cards (start chat; told who owns it when someone else does). - Depends on: 4.2 - Scope: `solvway-admin-portal/app/lib/aclSidebar*`, `solvway-admin-portal/app/components/app/**`, `solvway-admin-portal/app/leads/**`, `solvway-admin-portal/app/event-leads/**`, `solvway-admin-portal/app/lib/i18n/defaultMessages.ts` - Verify: portal verify (5.1 adds its keys to `defaultMessages.ts` after 5.2 is integrated, to avoid a hotspot clash) ## Wave 6 (serial: release) - [ ] 6.1 `docs/deployment.md`: the environment per company, the SQL order, the Meta setup steps (webhook URL, verify token, `messages` subscription, templates), and granting the modules. - [ ] 6.2 Live check on the local stack with the mock: - inbound for INS and CV, kept apart; - an unknown sender; - automatic owner, and manual reassign that sticks; - a disabled owner going to unassigned; - a text reply inside the window and refused outside; - template send with a missing parameter refused; - start a chat from an event lead; - media viewed; - a failed send shown; - the unread badge. Use Playwright at 1280 and 360 px. - [ ] 6.3 The owner's manual click-every-button e2e on a production build covers the inbox too (record the result here).