Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
5.4 KiB
5.4 KiB
Design
The full design is docs/superpowers/specs/2026-12-02-lead-notifications-design.md (approved 2026-12-02). This file records the technical decisions.
Context
service-system.notificationexists from Tastefully (id, receiver, message, create_date_time,utf8mb3) and is empty. services-system has a thinNotificationController(save, find by receiver).- Babyboo extended the same table and built the admin inbox API and bell (
add-admin-internal-notifications, 2026-10-07). Its files are the porting source: services-systemNotification/NotificationService/NotificationController, mobile-apiAdminNotificationController/AdminNotificationService, portalNotificationsBell.tsx,app/notifications/page.tsx,app/api/notifications/**,app/lib/services/notifications.ts. - services-counter already calls another service best-effort after commit:
WhatsappNotifier(2-second timeout, never throws,TransactionSynchronization.afterCommit). - Assignment points in services-counter:
EventLeadServicecapture and update (salespersonChanged),RegistrationServicenew capture andalreadyCaptured(assign). The event's sales team isevent_salesperson. - Inbound WhatsApp:
WebhookIngestServicecallsWaConversationRepository.recordInbound. The chat owner iswa_conversation.owner_user_id. - Leads due:
event_lead.next_follow_up_date,status,salesperson_user_id. The lead dashboard already counts overdue follow-ups. - The portal has
usePolling(babyboo useduseVisiblePolling).
Goals / Non-Goals
Goals: the bell, the four triggers, server read state, both languages, company scoping.
Non-Goals: email, WhatsApp or push alerts; per-user settings; broadcasts; purging.
Decisions
- One row per recipient in
notification,recipient_type = 'A',receiver= user id as text (the column isvarchar(45)),company_idset. Babyboo's model; read state is a column. - Codes, not text.
typeisLEAD_ASSIGNED,WEB_SIGNUP,WHATSAPP_MESSAGEorFOLLOW_UP_DUE.titleandmessagehold a label code and a JSON parameter object (lead name, event name, counts). The bell renders them witht(). No phone numbers or emails in parameters. - Collapse key. An optional
collapse_keyon create: when the receiver already has an unread row with that key, the create updates that row's message and time and marks nothing else; otherwise it inserts. WhatsApp usesWA:<conversation uuid>; the follow-up summary usesFOLLOW_UP:<date>, so a second run of the job on the same day before the user reads it does not duplicate.- ponytail: a job rerun after the user read the summary adds a second one that day. Add a run record if that happens in practice.
- Delivery is a REST call after commit, copying
WhatsappNotifier: 2-second timeout, no retry, failures logged with ids only. Counter and WhatsApp each get one smallStaffNotifierposting to services-system's create endpoint.- ponytail: no queue; a lost notification leaves the lead, chat and follow-up date in place. Move to Pub/Sub if losses show up.
- Recipients are resolved by the sender, which already has the data: counter knows the salesperson and the event's sales team; WhatsApp knows the chat owner. services-system only stores and serves rows.
- Self-assignment is silent. When the staff user making the change is the new salesperson, no "lead assigned" notification is sent. The counter compares the request's acting user with the new salesperson.
- A web sign-up assigned at capture sends one notification, of type
WEB_SIGNUP, to the salesperson. A web sign-up without a salesperson goes to every user inevent_salespersonfor that event; none when the team is empty. - Follow-up job in services-counter,
@Scheduled(cron = "${leads.follow-up-notice.cron:0 0 8 * * *}", zone = "Asia/Kuala_Lumpur"). It groups open event leads withnext_follow_up_date <= todayby company and salesperson, and sends one summary each (due today count, overdue count) linking to the event leads list. Leads without a salesperson are skipped. - Admin API in mobile-api reads the user id and company from the session, never from the request. Mark-read endpoints change only the caller's rows; another user's id returns 404.
- Bell ported from babyboo: polls the unread count every 30 seconds while visible, the drop-down shows the newest 10, opening it marks the shown items read, clicking navigates to
link./notificationslists 20 per page with "Mark all read". Every signed-in user gets it; no module permission. - Charset. The DDL converts the table to
utf8mb4(it is empty), so names with any characters are stored.
Risks / Trade-offs
- [Lost notifications on a services-system outage] → the underlying data is unaffected; logs show the failures.
- [Noisy bell for busy salespeople] → the WhatsApp collapse and the daily summary limit it; per-user settings come later if asked.
- [Leaking another company's lead] → recipients come from the same company's data; the API filters by the session user; tests cover a second company.
- [Links that the reader may not open] → links point to pages that still check access; a notification only names a lead its recipient is assigned to or on the team for.
Migration Plan
Run sql/01 (additive columns on an empty table) before deploying the services, then sql/02 labels. Rollback: sql/99-rollback.sql drops the columns and labels; the old services ignore them.
Open Questions
None.