# WhatsApp Template

A **WhatsApp Template** configures outgoing WhatsApp messaging rules by binding an event trigger to a pre-approved WhatsApp template ID on integration provider services (such as AWS WhatsApp). When linked to a [Notification](/notification) rule, the platform resolves runtime variables for message headers, body components, and footers before handing off dispatch to WhatsApp gateways.

---

## How it works

1. **Configure provider integration** — select the target `integrationProvider` (e.g. `aws_whatsapp`) and assign the associated `integrationId`.
2. **Bind WhatsApp template ID** — specify the approved `whatsAppTemplateId` registered in your WhatsApp Business account.
3. **Map template variables** — the platform automatically maintains `whatsAppTemplateVariables` JSON mappings for `HEADER`, `BODY`, and `FOOTER` dynamic components.
4. **Attach to notification rules** — link the WhatsApp template to an active [Notification](/notification) rule with `templateType: whatsapp_template` to automate event-driven messaging.

---

## Fields

### Basic information

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

### Integration & template mapping

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `integrationProvider` | enum | ✅ | — | The WhatsApp integration service provider (`aws_whatsapp`). |
| `integrationId` | UUID | Conditionally | — | Identifier of the linked WhatsApp provider integration record. Required when `integrationProvider` is set. |
| `whatsAppTemplateId` | string | Conditionally | — | Identifier of the registered/approved WhatsApp template ID. Required when `integrationId` is set. |
| `whatsAppTemplateVariables` | JSON | Read-only | — | System-managed variable parameter mappings for WhatsApp `HEADER`, `BODY`, and `FOOTER` blocks. |

---

## Event codes

The `sampleEventCode` field maps event structures for WhatsApp notifications 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`

---

## Real-world examples

**🟢 WhatsApp — Streak Milestone WhatsApp Notification**

Configuring a WhatsApp template mapping for AWS WhatsApp integration:

```json
{
  "name": "Streak 14-Day Milestone WhatsApp Template",
  "description": "Sends an automated WhatsApp notification when a user hits 14 active streak days.",
  "sampleEventCode": "streak_progress_milestone_completed",
  "integrationProvider": "aws_whatsapp",
  "integrationId": "019985db-c631-74b1-913d-b404a5640c99",
  "whatsAppTemplateId": "streak_milestone_reward_v1",
  "whatsAppTemplateVariables": {
    "HEADER": ["gmp_var_header_01"],
    "BODY": ["gmp_var_body_01", "gmp_var_body_02"],
    "FOOTER": []
  },
  "status": "live"
}
```

---

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

---

## API reference

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

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