Naalya Handbook
School featuresNotifications

Channels

The three ways a notification reaches someone, which types use which, what every failure code means, and the school's WhatsApp wording and Teams alerts.

A channel is one way of reaching a person. Each NotificationType lists its channels in NOTIFICATION_CHANNELS. Listing a channel does not guarantee a send: the recipient still needs an address.

How a notification fans out to the bell, email and WhatsApp

In-app (the bell)EmailWhatsApp
ReachesStaff in the HubAnyone with an emailGuardians, guests and staff with a valid number. Students are never looked up
AddressNone neededThe user's emailwhatsapp_number on guardian and staff profiles, phone on guest profiles
SentAt once, over the websocketHanded to the email queueA background job
Delivery rowNoYesYes
RetriesNoNo3 attempts, backing off from 5 seconds

Which types use which channels

From notification-channels.ts:

ChannelsTypes
WhatsApp onlyGUARDIAN_WELCOME, ADMISSION_STARTED
In-app onlyRECORD_OF_WORK_APPROVED, RECORD_OF_WORK_RETURNED, SCHOOL_PAY_UNMATCHED, TIMETABLE_CHANGED
In-app and emailSCHEME_GROUP_INVITE, CLASS_TEACHER_ASSIGNED, NOTICE_BOARD_PUBLISHED, GUARDIAN_CHILD_VERIFIED, ACADEMIC_REPORT_APPROVED, SCHEME_OF_WORK_APPROVED, SCHEME_OF_WORK_RETURNED, LESSON_PLAN_APPROVED, SCHOOL_REPORT_READY, PAYMENT_AWAITING_APPROVAL, TIMETABLE_RELEASED
Email and WhatsAppYEAR_ENROLMENT_OPENED, every ADMISSION_* except started, ENQUIRY_REPLIED, every PAYMENT_* aimed at payers, CHARGES_RAISED, CHARGE_ADJUSTED, FEE_DUE_SOON, FEE_OVERDUE, ADMISSION_FEE_REMINDER
All threeACADEMIC_REPORT_RELEASED, TERM_REPORTS_RELEASED, every LIBRARY_*

ACADEMIC_REPORT_RETURNED has no row, so it sends nothing. Who receives each type and where it opens in the Hub are on Where a notification opens.

In-app

The notification row is the bell, so nothing needs delivering. After saving, the API pushes the full title and body to the user's personal channel so a toast appears at once. That channel is locked to one user, so sending the text is safe. If the push fails, the bell still shows it next time it loads. See How realtime works.

Email

Look up addresses for all recipients in one query. No email gives NO_ADDRESS.

Build the message from the type's own EMAILS builder (subject, template, Hub link), not the shared title and body. No builder gives NO_EMAIL_TEMPLATE.

Queue it with EmailService. The email worker sends through Resend.

'sent' means queued

An email delivery is marked sent when it is handed to the queue, not when Resend accepts it or it lands in an inbox.

WhatsApp

Finding the number. Guardian, then guest, then staff rows for the recipients; a later row wins for the same user. A guardian's calling number is deliberately not used. normalizePhoneE164 turns local Ugandan numbers into E.164 (0772123456 becomes +256772123456) and returns null for anything invalid.

Sending:

Queue one job per delivery on whatsapp, with the delivery id as the job id so it can't be queued twice.

Pace it. The worker sends at most 30 a minute, to keep the number from being banned.

Pick the line. The recipient's campus line (from their student, staff, or single-campus guardian profile), else the school's default campus line, else the school's only connected line.

Send the title and body joined by a blank line, with links shortened. That is why WhatsApp-only bodies use *asterisks* for bold.

The school must have connected WhatsApp: a social_connection with provider = 'whatsapp' and status = 'connected'. Staff do this themselves; see Connect social channels.

Failure codes

Every channel except the bell writes its delivery row (queued, sent or failed) before trying to send, so no attempt is invisible.

errorChannelMeaningRetried
NO_ADDRESSEmail, WhatsAppNo email, or no usable numberNo
NO_EMAIL_TEMPLATEEmailNo EMAILS builder for the typeNo
NO_WHATSAPP_CONNECTIONWhatsAppNo connected line for this recipientNo
ACCOUNT_DISCONNECTEDWhatsAppThe provider says the line is disconnected. The connection is also marked disconnectedNo
NOT_ON_WHATSAPPWhatsAppValid number, no WhatsApp accountNo
A provider messageWhatsAppThe send failed upstreamYes, up to 3 attempts

A successful WhatsApp row also stores the provider message id, attempts and sentAt.

Why didn't someone get it?

Is there a notification row? None means emit was never called, or the person was the actor.

SELECT id, type, channels, created_at FROM notification
WHERE recipient_user_id = '<user-id>' ORDER BY created_at DESC LIMIT 5;

Does channels include the one you expected? It records the channel list at send time.

What does the delivery row say? Match error to the table above.

SELECT channel, status, address, error, attempts FROM notification_delivery
WHERE notification_id = '<id>';

Bell only, no toast? That's realtime, not notifications. The bell will show it on next load.

School WhatsApp wording

Schools can reword their WhatsApp messages at /api/v1/whatsapp-templates.

RouteNeedsDoes
GET /whatsapp-templates (listWhatsAppTemplates)read on social_connectionEvery key, with the school's body or null for the default
PUT /whatsapp-templates/:key (upsertWhatsAppTemplate)update on social_connection at school level (not a campus-only grant)Saves a body
DELETE /whatsapp-templates/:key (resetWhatsAppTemplate)SameBack to the default

A body is 1 to 4,000 characters with {{variable}} tokens. Missing required variables and unknown ones are both reported in one 400.

In the Hub: /staff-hub/school/whatsapp-templates, grouped into Accounts, Admissions, Enquiries, Academics and Payments. A saved body shows Custom; Reset to default appears only then.

Teams alerts

Staff alerts to Microsoft Teams are separate from the bell. Routes are under /api/v1/teams and need read or update on school.

RouteNeedsDoes
GET /teams/conversationsreadChannels and chats the school bot can post to
POST /teams/conversations/refreshupdateRe-reads them
GET /teams/routesreadWhich channel each alert goes to
PUT /teams/routes/:kindupdateSets one; a gone conversation is Channel not found
DELETE /teams/routes/:kindupdateClears one

Alert kinds: enquiry.created, admission.started, admission.submitted, payment.received, payment.unmatched. The Hub's Teams settings tab shows only the first three. Sent alert rows are purged after 90 days; see Security and example data.

On main 6bfb9f6b, the same tree as staging 0d611c96. The API adds ai_enquiry.created. When the WhatsApp or email bot passes a question on, the server sends that kind to the school's Teams route and to its WhatsApp alert route. A failed send is logged and does not drop the question. The worker asks social.open_enquiry so the turn can see one pending question for that chat. A failed read is left unset. This kind is not in the list above. Hub main 2dd88361 shares the tree of staging 413b5cfe and adds a settings row labelled Question for staff on the Teams tab and the WhatsApp tab. Its description is "Sent when Rover gets a question on WhatsApp or email that it cannot answer." A merge to Hub main is not a running deploy.

How the bot's inbound route is protected

POST /api/v1/teams/messages is @Public(), which only skips the staff bearer guard. Microsoft's own token check still runs:

CheckResult on failure
The recipient id maps to a school whose config has a bot app id, secret and tenant404, logged as Teams activity for a bot no school has configured
An Authorization header is present401 Missing authorization header
The token is a valid Bot Framework or Entra token for that app id401 JWT validation failed

Never set DANGEROUSLY_ALLOW_UNAUTHENTICATED_REQUESTS

The Teams SDK skips the token check when this environment variable is set. The API doesn't set it and its env schema doesn't mention it. Setting it on a deployed API would let anyone post fake activities to every school's bot.

Teams Rover

A worker that answers in a school's Teams group chats, on TEAMS_ROVER_QUEUE with concurrency 5.

JobRuns whenPosts
ChatNew messages arriveUsually nothing. One short line when tagged and it doesn't know
Weekly summaryOnce a week (the prompt is written for Friday afternoon), for chats with someone else's message in the last 7 daysWhat moved, what was decided, who owes what
IntroRover is added to a group chat (not a team install)A hello, plus a catch-up if the week had messages

Guardrails:

  • One run per chat at a time (a Redis lock), at most 5 minutes or 12 steps.
  • It only speaks through send_message, which drops empty, emoji-only and duplicate messages and strips em dashes and ellipses. It can also react, search the chat history and the knowledge base, and search the web from Kampala.
  • Silence is the default. School facts come from the knowledge base, Hub how-tos from the edu-hub-guide skill. It switches to a short, serious tone for safeguarding, injury, a missing student, a death, complaints, pay or discipline.
  • An error after a successful send is not retried, so nothing posts twice.

Where to go next

On this page