# SMS Template

An **SMS Template** defines the text message body dispatched for automated SMS alerts (such as streak status updates, challenge deadlines, or milestone completion rewards). When attached to an active [Notification](/notification) rule, the platform resolves dynamic variables and delivers text messages via integrated provider gateways like AWS SMS.

:::tip
The `message` field is **localisable**. Pass a `languageCode` query parameter when managing templates to support internationalised SMS content.
:::

---

## How it works

1. **Create an SMS template** — define a unique name, description, and assign a `sampleEventCode` for mock payload context.
2. **Write the SMS copy** — populate the `message` field with concise, engaging text copy.
3. **Insert dynamic variables** — embed variable tokens in double curly braces `{{ }}` (e.g. `{{$account_user.firstName}}`, `{{$helpers.periodText}}`).
4. **Attach to notification rules** — map the template to an active [Notification](/notification) rule with `templateType: sms_template` to automate dispatch.

---

## Fields

### Basic information

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

### Content & display

| Field | Type | Required | Description |
|---|---|---|---|
| `message` | text | ❌ | The body text of the SMS message. Supports variables and localisation. |

---

## Event codes

The `sampleEventCode` maps mock event structure 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.challengeProgress.completionTargetValue}}` |
| `{{$helpers.*}}` | Formatted helper variables | `{{$helpers.remainingValue}}`, `{{$helpers.formattedChallengeToBeFailedAt}}` |

---

## Real-world examples

**💬 Transactional SMS — Challenge Completed Alert**

An SMS template congratulating a member on finishing a challenge:

```json
{
  "name": "Challenge Completed SMS Template",
  "description": "Sent via AWS SMS when a challenge is successfully completed.",
  "sampleEventCode": "challenge_progress_completed",
  "status": "live",
  "message": "Congrats {{$account_user.firstName}}! You completed your challenge and unlocked your reward. View details in app."
}
```

---

## 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 SMS templates |
| [Notification Log](/notification-log) | Delivery audit trail for dispatched SMS messages |
| [Member](/member) | SMS recipient record |

---

## API reference

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

- `GET /schema/sms_template/record` — list SMS templates
- `POST /schema/sms_template/record` — create an SMS template
- `GET /schema/sms_template/record/{id}` — get an SMS template by ID
- `PATCH /schema/sms_template/record/{id}` — update an SMS template
- `DELETE /schema/sms_template/record/{id}` — delete an SMS template
