Files
co-lite/openspec/changes/add-whatsapp-inbox/tasks.md
T

8.9 KiB

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 <modules> 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)

  • 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.
  • 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
  • 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)

  • 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
  • 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)

  • 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
  • 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)

  • 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
  • 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)
    • 5.1 and 5.2 done 2026-12-02, inline (owner: no workers), self-reviewed. The proxy lives at app/api/whatsapp (codebase convention). The WhatsApp button sits in the Mobile cell, so the leads table keeps its column order.
    • Live check on the local stack with the mock, as super admin at 1280 and 360 px: unread badge and clearing it, the tabs, the thread header and lead link, the window countdown, text send with sent then read ticks, template sync, an unsupported template disabled, a filled template sent, image, document, location and expired media, start chat from Leads. It found five bugs, each fixed test-first: the list stuck on its skeleton under StrictMode, a sent message kept a stale tick, a super admin got no templates, a super admin owner could not be shown in the owner select, and the thread overflowed at 360 px.
    • It also found that the webhook answered 200 when the service could not store the event, losing it. Owner decision: answer 503 so Meta redelivers (design D3, spec scenario "Inbox not ready"), verified live by stopping service-system.

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.

    • Also: the webhook's own Traefik route, the role pairing, the go-live limits, the 503 behaviour, and the client-address note for rate limits.
  • 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.

    • Done 2026-12-02 as super admin, with BO_WHATSAPP granted to a test role for the check and revoked after. All items passed:
      • INS and CV lists apart under the company picker;
      • an unknown sender with no lead link;
      • the automatic owner through the counter notify; a salesperson without BO_WHATSAPP leaves the chat unassigned;
      • a manual owner that stays when the salesperson changes;
      • disabling that owner sends the chat to Unassigned and clears the manual flag;
      • window closed (last inbound aged in the DB): template-only footer;
      • the template picker keeps Send disabled while a parameter is empty;
      • start from an event lead row opens the new chat;
      • a failed send shows "Not delivered: Message undeliverable (131026)" with Retry;
      • the unread badge.
    • Earlier in 5.1: media, ticks and the 360 px layout. The staff-only view (Mine only, no owner select) is covered by tests only: no staff password was available, and staff passwords were not reset for it. The test rows were removed.
  • 6.3 The owner's manual click-every-button e2e on a production build covers the inbox too (record the result here).