Files
co-lite/docs/superpowers/specs/2026-12-02-lead-notifications-design.md
T

6.2 KiB

Lead notifications (bell) — design

Date: 2026-12-02. Status: draft for owner approval.

Intent

Sales staff need to know about new work without refreshing lists: a lead assigned to them, a new sign-up from a landing page, an incoming WhatsApp message, and follow-ups due. This is feature-list item 12, needed before go-live on 2027-01-15. On 2026-12-02 the owner chose the in-app bell only (no email, no WhatsApp alerts) and approved the recommended approach and recipient rules.

Goals

  • A bell in the portal header with an unread badge, a drop-down of recent notifications and a full notifications page.
  • Each notification links straight to the lead, or to the WhatsApp chat.
  • Read state is stored on the server, so it survives a reload and follows the user to another device.
  • Four triggers:
    • lead assigned to me;
    • new landing-page sign-up;
    • incoming WhatsApp message on a chat I own;
    • follow-ups due today.
  • English and Chinese text, following the user's language.
  • Company scoping: a user only ever receives notifications about their own company's leads.

Non-goals

  • Email, WhatsApp or browser push alerts.
  • Per-user notification settings (mute a type). Add when staff ask for it.
  • Admin broadcast messages (babyboo has them; Co-Lite has no need yet).
  • Purging old notifications. Rows are small; add a purge when the table grows.

Anti-goals

  • A notification that reveals another company's lead, or a lead to someone who may not see it.
  • A noisy bell: one alert per WhatsApp message during a busy chat would train staff to ignore it.
  • A notification failure that breaks the action behind it. A sign-up, an assignment or an inbound message must succeed even when the notification cannot be written.

Approaches

  1. Port babyboo's bell (chosen). Each trigger writes one notification row per recipient in service-system.notification. Babyboo extended that table and built the admin inbox API and the header bell (add-admin-internal-notifications, 2026-10-07); the flow is proven.
  2. Counts only. The bell shows numbers computed from existing data (new leads, unread chats, follow-ups due). Cheaper, but no list, no link to the item, and no record of the moment a lead was assigned. Not chosen.

Design

Storage (service-system)

Extend the existing, unused notification table the way babyboo did, plus a company id:

  • recipient_type (A for staff; only A is used now), title, type, link, seen, read_at, company_id.
  • Index (recipient_type, receiver, seen, create_date_time).
  • receiver holds the staff user id.
  • title and message hold message codes and parameters (JSON), not text, so the bell renders in the reader's language (babyboo's renderNotice pattern). Parameters hold only what the bell shows: the lead's name and the event name. No phone numbers or email addresses.

Endpoints in service-system: create (one or many rows), list mine (newest first, paged), unread count, mark one read, mark all read. The mark-read endpoints only touch rows whose receiver is the caller.

Admin API and portal

  • mobile-api: GET /api/admin/notifications, GET /api/admin/notifications/unread-count, POST /api/admin/notifications/{id}/read, POST /api/admin/notifications/read-all. The caller is always the signed-in user; no user id is taken from the request.
  • Portal: babyboo's NotificationsBell in the header (polls the unread count every 30 seconds while the tab is visible) and a /notifications page. Opening the drop-down marks the shown items read; clicking an item opens its link.
  • Every signed-in staff user has the bell. No new module permission: a user only ever sees their own notifications.

Triggers and recipients

Trigger Where Who gets it
Lead assigned services-counter, wherever the salesperson of an event lead changes to someone (manual assignment, assignment at capture, re-assignment) The new salesperson. Not the person who made the change, when they assigned it to themselves.
New landing-page sign-up services-counter, registration with source WEB The assigned salesperson when there is one. Otherwise everyone on the event's sales team (event_salesperson). Nobody when the event has no sales team.
Incoming WhatsApp message services-whatsapp, inbound message on a conversation The chat owner. Nobody when the chat has no owner (the shared inbox already shows it). One unread notification per chat: while the owner has an unread notification for that chat, a new message updates its time instead of adding another.
Follow-ups due services-counter, a daily job at 08:00 Malaysia time Each salesperson with event leads whose next_follow_up_date is today or earlier and whose status is still open. One summary notification per salesperson per day ("3 follow-ups due, 1 overdue"), linking to their event leads list.

A new sign-up that is also assigned at capture sends one notification to the salesperson (the sign-up), not two.

Delivery

  • Senders call service-system's create endpoint over REST, after their transaction commits, with a 2-second timeout. A failure is logged with ids only and never fails the action. This copies WhatsappNotifier.
  • ponytail: no retry or queue. A lost notification is an inconvenience, not lost data: the lead, the chat and the follow-up date are all still there. Add a Pub/Sub topic if losses show up.
  • The daily job must not send twice when the service runs more than one copy, or restarts: it records the day it last ran for each company (or uses the existing scheduler lock pattern, if the codebase has one).

Labels

New labels in English and Chinese, shipped as SQL in the change folder, the same way as earlier changes.

Constraints

  • New and changed tables carry a company id.
  • Logs never contain lead names, phone numbers or email addresses.
  • The notification store is written only through service-system; other services never write its table directly.

Left to the builder

  • The exact link targets (lead detail page, chat page, event leads list with a follow-up filter if one exists).
  • Whether the daily job lives in services-counter or service-system, as long as it runs once per day per company.
  • Page size of the notifications list and how many items the drop-down shows.