|
| 1 | +# Notification Trigger |
| 2 | + |
| 3 | +A standalone toy platform to send push notifications via **APNS** (iOS) and **FCM** (Android). Accepts a common payload structure and routes to the appropriate service based on platform. |
| 4 | + |
| 5 | +Kept in this repo for testing purposes. Can be moved to its own project for standalone use. |
| 6 | + |
| 7 | +## Quick start |
| 8 | + |
| 9 | +```bash |
| 10 | +pnpm install |
| 11 | +cp .env.example .env |
| 12 | +# Edit .env with your credentials |
| 13 | +pnpm dev |
| 14 | +``` |
| 15 | + |
| 16 | +Open http://localhost:3998 to use the web UI. |
| 17 | + |
| 18 | +## Requirements |
| 19 | + |
| 20 | +- **Node.js** 18+ |
| 21 | +- **FCM (Android)**: Firebase service account JSON |
| 22 | +- **APNS (iOS)**: Apple .p8 auth key + key ID, team ID, bundle ID |
| 23 | + |
| 24 | +You can run with only one provider configured; the other will be disabled. |
| 25 | + |
| 26 | +## API |
| 27 | + |
| 28 | +### GET /api/health |
| 29 | + |
| 30 | +Returns health status and which providers are configured. |
| 31 | + |
| 32 | +```json |
| 33 | +{ |
| 34 | + "ok": true, |
| 35 | + "apns": true, |
| 36 | + "fcm": true |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +### POST /api/send |
| 41 | + |
| 42 | +Send a push notification. |
| 43 | + |
| 44 | +**Request body:** |
| 45 | + |
| 46 | +```json |
| 47 | +{ |
| 48 | + "token": "<APNS or FCM device token>", |
| 49 | + "platform": "ios" | "android" | null, |
| 50 | + "payload": { |
| 51 | + "title": "Hello", |
| 52 | + "body": "Notification body", |
| 53 | + "subtitle": "Optional subtitle", |
| 54 | + "data": { "key": "value" }, |
| 55 | + "sound": "default", |
| 56 | + "badge": 1, |
| 57 | + "clickAction": "category-id" |
| 58 | + } |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +- **token**: APNS device token (iOS) or FCM registration token (Android) |
| 63 | +- **platform**: Optional. If omitted, auto-detected from token format (64 hex chars → iOS/APNS, else → Android/FCM) |
| 64 | +- **payload**: Common structure; `title` and `body` are required. `data` values must be strings for FCM compatibility. |
| 65 | + |
| 66 | +**Example (curl):** |
| 67 | + |
| 68 | +```bash |
| 69 | +curl -X POST http://localhost:3998/api/send \ |
| 70 | + -H "Content-Type: application/json" \ |
| 71 | + -d '{ |
| 72 | + "token": "YOUR_DEVICE_TOKEN", |
| 73 | + "payload": { |
| 74 | + "title": "Test", |
| 75 | + "body": "Hello from notification trigger" |
| 76 | + } |
| 77 | + }' |
| 78 | +``` |
| 79 | + |
| 80 | +## Environment |
| 81 | + |
| 82 | +Copy `.env.example` to `.env` and fill in your credentials. See `.env.example` for all required variables. |
| 83 | + |
| 84 | +| Variable | Required | Description | |
| 85 | +|----------|----------|--------------| |
| 86 | +| `NOTIFICATION_TRIGGER_PORT` | No | Server port (default: 3998) | |
| 87 | +| `GOOGLE_APPLICATION_CREDENTIALS` | For FCM | Path to Firebase service account JSON | |
| 88 | +| `APNS_KEY_PATH` | For APNS | Path to .p8 APNS auth key | |
| 89 | +| `APNS_KEY_ID` | For APNS | APNS key ID | |
| 90 | +| `APNS_TEAM_ID` | For APNS | Apple team ID | |
| 91 | +| `APNS_BUNDLE_ID` | For APNS | App bundle ID | |
| 92 | +| `APNS_PRODUCTION` | No | `true` for production APNS (default: `false`) | |
| 93 | +| `APNS_BROADCAST_CHANNEL_ID` | No | Base64 channel ID for Live Activities (optional) | |
| 94 | + |
| 95 | +## Build & run |
| 96 | + |
| 97 | +```bash |
| 98 | +pnpm build |
| 99 | +pnpm start |
| 100 | +``` |
| 101 | + |
| 102 | +## Integration with this repo |
| 103 | + |
| 104 | +When used from the prototype monorepo: |
| 105 | + |
| 106 | +- Control panel uses `NOTIFICATION_TRIGGER_URL` (e.g. `http://localhost:3998`) to send notifications |
| 107 | +- The provisioner (evault-core) stores device tokens; the control panel fetches them and sends via this service |
0 commit comments