For: Arun (QAVACH_API)
Date: 2-Dec-2026
You do not need the Polaris screens or the alert-detection work. This file is everything you need.
Today, when Polaris finds a safety problem (overdue CAPA, PPE spike, and so on), QAI_CHAT already knows the alert exists. Nothing is actually sent to people. That send is what we need from QAVACH_API.
We expect one internal API. We will call it every time an alert must go out. You do the rest:
You are not building a new mail server, SMS gateway, or push system. You are the fan-out: alert in → right people, right channels, messages out.
Two different kinds of data. Do not mix them:
A person at a terminal should get a Polaris alert only if:
Their role is on the list for that terminal and that severity.
Example: at Mersin, Critical alerts go to HSE Manager and Area Supervisor. A clerk with neither role gets nothing.
They have not switched that severity off.
Example: Ravi turned High off. A High alert is raised. Ravi gets nothing. Priya left High on. Priya is notified.
It is not their quiet hours, unless the alert is Critical or Catastrophic.
Example: Ravi’s quiet hours are 22:00–06:00. A High alert at 23:00 is not sent to him. A Critical alert at 23:05 is sent — nights do not block serious alerts.
The message goes only on the channels they switched on.
Four channels exist: in-app (Qavach inbox), email, mobile push, SMS.
Example: Priya wants email + push. Ravi wants in-app only. Same Critical alert: Priya gets an email and a phone notification; Ravi gets an inbox message only.
Those four choices (channels, which severities, quiet hours) belong to the person, not the terminal. Two HSE managers at the same terminal can receive the same alert in completely different ways.
Who is in the audience belongs to the terminal. Admin data already says “at this terminal, Critical → these roles”. You read that. You do not decide the role list yourself.
For each person you found, apply the checks in this order:
QAI_CHAT calls you with:
At terminal 16, Critical is mapped to role HSE Manager. Two active users have that role: Priya and Ravi.
| Priya | Ravi | |
|---|---|---|
| Channels on | Email, push | In-app only |
| High / Critical | Both on | Both on |
| Quiet hours | Off | 22:00–06:00 |
| Time now (terminal) | 23:05 | 23:05 |
What we expect you to send:
You then write a log row for each attempt (Priya email sent, Priya push sent, Ravi in-app sent, and skipped rows if you evaluated SMS and skipped it).
If QAI_CHAT posts the same request again, send nothing. Return the same result. People must not get two emails for one alert.
SMS is noisy and costs money, so it is tighter than the other channels:
Polaris:SmsEnabled is true in config. Default is false, so on a normal environment SMS is off for everyone until ops turn it on.GeneralRepository.SendSms). Do not add Twilio or a new gateway.Catastrophic must always go out to the people in the audience, even if:
You still honour which channels they have on (do not force SMS if they never enabled it). You just do not drop the whole person.
no_device), do not fail the request.You do not decide when an alert exists. QAI_CHAT already did that.
You do not build screens. You do not create the routing/preference tables. You do not run a clock that waits and then “escalates”.
If the same alert later needs a wider audience, QAI_CHAT will call this same API again with a different severity for routing and escalationLevel 1, 2, … You treat that as a new send (new log rows), using the same rules.
| Build | Do not build |
|---|---|
POST api/PolarisNotify/Send |
Screens, settings save/load, alert detection |
Table PolarisNotificationLog |
The routing / preference tables (QAI_CHAT already creates those) |
Use the email, in-app, push, and SMS code that already exists in QAVACH_API. Do not write new gateways. The diagrams above are the behaviour. The sections below are the API contract.
POST api/PolarisNotify/Send
X-Polaris-Service-KeyPolaris:ServiceKey.[AllowAnonymous] plus that header check (filter or attribute). Wrong or missing key → 401.{
"alertId": 12345,
"terminalId": 16,
"eventCode": "8b",
"criticality": "Critical",
"routingCriticality": "Critical",
"escalationLevel": 0,
"title": "Overdue CAPA",
"description": "3 critical CAPAs are overdue by more than 14 days in Berth 4.",
"raisedAt": "2026-12-02T23:05:00",
"deepLink": "/polaris?alert=12345"
}
| Field | Required | Meaning |
|---|---|---|
alertId |
yes | Id from QAI_CHAT. Used in the log and to stop duplicates. |
terminalId |
yes | Terminalmaster_FK. Roles and users are for this terminal only. |
eventCode |
yes | Put in the log / message. You do not look up events. |
criticality |
yes | Severity of this alert: Catastrophic | Critical | High | Medium | Routine |
routingCriticality |
yes | Which role-list to use. Same as criticality on first send. On a later call it may be a higher severity. |
escalationLevel |
yes | 0 = first send, 1+ = later send of the same alert. Part of the duplicate key. |
title |
yes | Short title (max 60 characters). |
description |
yes | Body text. |
raisedAt |
yes | When the alert was raised (ISO). Quiet hours use terminal local time, not this timestamp’s zone blindly. |
deepLink |
no | Link to include in email / in-app / push. |
If the body is valid, always return HTTP 200 — even if some channels failed or nobody was found.
{
"alertId": 12345,
"escalationLevel": 0,
"recipients": [
{ "userPk": 101, "channel": "email", "status": "sent" },
{ "userPk": 101, "channel": "sms", "status": "skipped", "reason": "sms_not_allowed_for_high" },
{ "userPk": 102, "channel": "inapp", "status": "skipped", "reason": "quiet_hours" }
]
}
status |
Meaning |
|---|---|
sent |
Handed to the existing send service without error |
skipped |
A rule said no — see reasons below |
failed |
Send threw; put a short reason |
Do not return 5xx because one SMS failed. Log that row as failed and still return 200.
Return 4xx only for a bad body or missing auth.
Read PolarisRouting for (terminalId, routingCriticality).
Read that row’s roles from PolarisRoutingRole.
Recipients = active users on that terminal who hold those roles.
RoleName case-insensitive.RoleMaster_FK is not null, prefer that id.HSE MANAGER, Administrator, …). Use the same role matching you already use in other modules.Each user can turn severities off (except Catastrophic).
criticality → skip all channels. Reason: priority_off.Each user can set a night window (example 22:00–06:00). The window may cross midnight.
If quiet hours are on and terminal local time is inside [QuietStart, QuietEnd):
| Severity | Action |
|---|---|
| High, Medium, Routine | Skip all channels. Reason: quiet_hours |
| Critical, Catastrophic | Still send |
Only channels the user has on:
| Channel | When to send | Existing code |
|---|---|---|
| In-app | If ticked | MessageCenterService (SendInternal / SaveMail) |
| If ticked | EmailService |
|
| Push | If ticked | AlertPubSubService.SendMobileFcm (FCM) |
| SMS | If ticked and severity is Critical or Catastrophic and Polaris:SmsEnabled is true |
GeneralRepository.SendSms (Mersin OTP gateway) |
SMS skip reasons:
sms_not_allowedPolaris:SmsEnabled is false (default) → sms_disabledNo FCM device → no_device (do not fail the whole request).
No users at all → 200 with empty recipients (reason no_users is optional).
Use defaults:
One send per (alertId, escalationLevel, userPk, channel).
Put a unique constraint on the log table. If QAI_CHAT retries, return the previous result. Do not send again.
[Polaris][Critical] Overdue CAPAdeepLinkPolaris CRITICAL: Overdue CAPA. Open Qavach to review.QAI_CHAT creates the routing and preference tables. You only read them. Column names below are what is in the database today. If a name does not match what you see on the tenant, ping Balaji — do not rename on your side.
PolarisRouting — 5 rows per terminal (one per severity)
| Column | Type | Notes |
|---|---|---|
PolarisRoutingPK |
INT PK | |
Terminalmaster_FK |
INT | Terminal |
Criticality |
VARCHAR(16) | Catastrophic / Critical / High / Medium / Routine |
EscalateAfter |
VARCHAR(16) | Ignore. QAI_CHAT uses this. |
PolarisRoutingRole — roles for one routing row
| Column | Type | Notes |
|---|---|---|
PolarisRoutingRolePK |
INT PK | |
PolarisRoutingPK |
INT | FK to PolarisRouting |
RoleMaster_FK |
INT NULL | Role id when known |
RoleName |
NVARCHAR(128) | Always present |
PolarisUserPrefs — one row per user. Missing row = defaults in rule 5.
| Column | Type | Notes |
|---|---|---|
UserPk |
INT PK | |
ChInApp ChEmail ChSms ChPush |
BIT | Channels |
PriCatastrophic PriCritical PriHigh PriMedium PriRoutine |
BIT | Severities this user wants |
QuietHoursOn |
BIT | |
QuietStart QuietEnd |
VARCHAR(5) | HH:mm |
AlertCount SoundCritical AutoAckRoutine GroupSimilar |
BIT | Ignore |
UpdatedAt |
DATETIME | Ignore |
You do not need any other Polaris tables.
CREATE TABLE dbo.PolarisNotificationLog (
PolarisNotificationLogPK INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
AlertId INT NOT NULL,
EscalationLevel INT NOT NULL,
Terminalmaster_FK INT NOT NULL,
UserPk INT NOT NULL,
Channel VARCHAR(16) NOT NULL, -- inapp | email | sms | push
Status VARCHAR(16) NOT NULL, -- sent | skipped | failed
Reason VARCHAR(64) NULL,
SentAt DATETIME NOT NULL,
CONSTRAINT UQ_PolarisNotificationLog UNIQUE (AlertId, EscalationLevel, UserPk, Channel)
);
Rename to match your conventions if you need to. Keep the unique key.
| Key | Default | Use |
|---|---|---|
Polaris:ServiceKey |
(required) | X-Polaris-Service-Key |
Polaris:SmsEnabled |
false |
Allow SMS for Critical and Catastrophic |
Critical alert. Routing has HSE Manager. Two users on the terminal have that role.
→ Both get every channel they have on.
User has High turned off. High alert.
→ Skip that user (priority_off).
Catastrophic alert. User has Catastrophic stored as off, or quiet hours on.
→ Still send.
Quiet hours 22:00–06:00. High at 23:00.
→ Skip (quiet_hours).
Same window. Critical at 23:05.
→ Send.
Quiet hours 22:00–06:00. Medium at 05:59 and at 06:00.
→ Skip at 05:59. Send at 06:00.
High alert. User has SMS on.
→ No SMS. Other channels still send.
Polaris:SmsEnabled = false. Critical alert.
→ No SMS. Other channels still send.
User has no PolarisUserPrefs row.
→ In-app + email + push. Routine skipped.
Same request posted twice.
→ Second call sends nothing new. Same result.
Routing role with no users on the terminal.
→ 200. No recipients for that role.
Missing or wrong service key.
→ 401.
QHSE.API/Controllers/.../PolarisNotifyController.cs — SendQHSE.Services/Polaris/PolarisNotificationService.cs — roles → users → rules → send → logX-Polaris-Service-KeyPolarisNotificationLogReuse, do not rewrite: MessageCenterService, EmailService, AlertPubSubService.SendMobileFcm, GeneralRepository.SendSms.
QAI_CHAT will POST to {API_BASE_URL}api/PolarisNotify/Send with the JSON above and header X-Polaris-Service-Key.
You can implement and unit-test against the 12 cases with a mocked request before that call is wired. Balaji will share a sample payload when we plug it in.