# v387 — Guarded Urgent Text Send and Audit Records

## Decision

v387 continues the simple app-style notifications track instead of returning to CORI Mail.

Reason: v386 prepared urgent text previews only. Before Dispatch Spot can treat text alerts as a real user-facing delivery path, the app needs a final approval button and an auditable send record.

## What changed

- Added guarded urgent text send execution.
- Added `/api/app-notifications/send-urgent-text`.
- Added Twilio REST send support through saved Workspace Integration credentials.
- Added a schema-backed `OutboundTextMessageLog` audit model.
- Every urgent text send attempt now records:
  - user
  - workspace
  - Twilio provider account
  - phone last four digits
  - message preview
  - urgent alert count
  - approval time
  - sent time when successful
  - provider message id when available
  - failure message when sending fails
- Updated the Notifications delivery panel so users must preview the urgent text first and then click **Send urgent text**.
- Preserved the rule that Twilio credentials stay in Workspace Settings > Third-Party Integrations.

## User-facing behavior

At `/notifications`, users can now:

1. Review alerts.
2. Save urgent text opt-in.
3. Preview the urgent text.
4. Explicitly approve sending.

Dispatch Spot does not send the text just because it exists. The user must click **Send urgent text** after preview.

## Placement rule

The Notifications page remains simple. It shows alert readiness, preview, and user approval only.

Twilio setup remains in:

`/company/integrations`

under the Twilio tab.

## Prisma schema impact

Yes. v387 adds `OutboundTextMessageLog` and relation fields on `User`, `Organization`, and `WorkspaceIntegrationAccount`.

Run:

```bash
npx prisma generate
npx prisma db push
```

before TypeScript and Next build.
