# Push Notification Template

A **Push Notification Template** defines the content, messaging structure, and optional deep link for push notifications dispatched to your mobile or web app users. When bound to an active [Notification](/notification) rule, the platform dynamically resolves template variables and sends push alerts via integration providers such as Firebase Cloud Messaging (FCM).

:::tip
The `notificationTitle`, `notificationBody`, and `deepLink` fields are **localisable**. Pass a `languageCode` query parameter when managing templates to support multi-language push notifications for international users.
:::

---

## How it works

1. **Create a push notification template** — set a name, description, and select a `sampleEventCode` to preview runtime event payload structure.
2. **Define title and body** — craft the push notification header (`notificationTitle`) and main message (`notificationBody`).
3. **Set deep link** — optionally provide a `deepLink` URL or app scheme (e.g. `gamopanda://rewards/{{rewardId}}` or `https://myapp.com/challenges`) to direct users to specific screens upon tapping the notification.
4. **Use template variables** — insert dynamic placeholders using double curly braces `{{ }}` (e.g. `{{$account_user.firstName}}` or `{{$helpers.periodText}}`).
5. **Attach to notification rules** — link the template to a [Notification](/notification) rule with `templateType: push_notification_template` to automate dispatch.

---

## Fields

### Basic information

| Field | Type | Required | Max length | Description |
|---|---|---|---|---|
| `name` | string | ✅ | 256 | Unique name of the push notification template |
| `description` | string | ❌ | 1 024 | A brief description of the template purpose |
| `sampleEventCode` | enum | ✅ | 64 | Sample event code used to load mock payload data during design |
| `status` | enum | ✅ | — | `draft` · `live` · `paused` |

### Content & display

| Field | Type | Required | Max length | Description |
|---|---|---|---|---|
| `notificationTitle` | string | ❌ | 256 | Header/title of the push notification. Supports variables and localisation. |
| `notificationBody` | text | ❌ | — | Main body content of the push notification. Supports variables and localisation. |
| `deepLink` | string | ❌ | 256 | Target URL or app URI scheme triggered on click/tap. Supports variables and localisation. |

---

## Event codes

The `sampleEventCode` field maps mock event structures for designing templates across:

- **Streak Events**: `streak_progress_broken` · `streak_progress_to_be_broken` · `streak_progress_completed` · `streak_progress_milestone_completed` · `streak_progress_non_milestone_completed` · `streak_progress_in_progress`
- **Challenge Events**: `challenge_progress_failed` · `challenge_progress_to_be_failed` · `challenge_progress_completed` · `challenge_progress_milestone_completed` · `challenge_progress_in_progress`
- **Mission Events**: `mission_progress_failed` · `mission_progress_to_be_failed` · `mission_progress_completed` · `mission_progress_milestone_completed` · `mission_progress_in_progress`
- **Reward Unlocked Events**: `streak_reward_unlocked_on_milestone_completion` · `challenge_reward_unlocked_on_milestone_completion` · `mission_reward_unlocked_on_completion` · `mission_reward_unlocked_on_milestone_completion`

---

## Template variables

The template engine replaces double curly braces `{{ }}` with runtime event context:

| Variable Namespace | Description | Example |
|---|---|---|
| `{{$account_user.*}}` | Member variables | `{{$account_user.firstName}}` |
| `{{$event_log.payload.*}}` | Context event log payload | `{{$event_log.payload.streakProgress.currentStreak}}` |
| `{{$helpers.*}}` | Formatted helper variables | `{{$helpers.formattedStreakToBeBrokenAt}}`, `{{$helpers.remainingValue}}` |

---

## Real-world examples

**📱 Mobile App — Streak Expiry Warning**

A push notification alerting a user before their active streak resets:

```json
{
  "name": "Streak Expiry Warning Push Template",
  "description": "Warns users 2 hours before daily streak expires.",
  "sampleEventCode": "streak_progress_to_be_broken",
  "status": "live",
  "notificationTitle": "🔥 Don't lose your streak, {{$account_user.firstName}}!",
  "notificationBody": "Complete your daily activity before midnight to maintain your {{$helpers.currentProgressValue}}-day streak.",
  "deepLink": "gamopanda://streaks/active"
}
```

---

## Access & permissions

| Caller | Allowed operations | Notes |
|---|---|---|
| Admin | CREATE · GET · LIST · UPDATE · DELETE | Full management access |
| End user | *(none)* | No access |
| Guest user | *(none)* | No access |

---

## Related resources

| Resource | Description |
|---|---|
| [Notification](/notification) | Active notification rules linking events to templates |
| [Notification Log](/notification-log) | Delivery audit trail for push notifications |
| [Member](/member) | Push recipient record |

---

## API reference

See the [API Reference](/api/push-notification-template) for full schemas and examples:

- `GET /schema/push_notification_template/record` — list push notification templates
- `POST /schema/push_notification_template/record` — create a push notification template
- `GET /schema/push_notification_template/record/{id}` — get a push notification template by ID
- `PATCH /schema/push_notification_template/record/{id}` — update a push notification template
- `DELETE /schema/push_notification_template/record/{id}` — delete a push notification template
