# Templates

> Create WhatsApp templates in Talqing, the rules checked before review, statuses, duplicating and deleting.

WhatsApp lets you message someone freely only within **24 hours of their last
message or call**. Outside that window you can send only a **template**: a
message WhatsApp reviewed in advance, with `{{variables}}` filled in per person.
[Batches](https://docs.talqing.com/whatsapp/creating-a-batch.md) and conversation openers both send them.

Templates are written, submitted, tracked and deleted under **WhatsApp →
Templates**, or through the API. Talqing keeps no copy: they live on your
WhatsApp account and are read live, so templates made in Twilio's console show
up too.

> **Note:**
> Creating templates works for **Twilio** numbers. A template belongs to the
> Twilio account, so it is shared by every number on that account. Gupshup
> templates are listed, but created and deleted in your Gupshup app.

## What a template holds

| Part | Rules |
| --- | --- |
| Name | Lowercase letters, digits and `_`. Unique per language. |
| Language | One of Meta's codes, such as `en_US`, `hi` or `pt_BR` (`whatsapp_template_languages` in `GET /v1/catalog`). |
| Category | `utility` for updates about something the person asked for: orders, bookings, reminders. `marketing` for offers, announcements and re-engagement. |
| Header (optional) | Text up to 60 characters with at most one variable, or a public `https` image (`.jpg`, `.png`), video (`.mp4`, `.3gp`) or document (`.pdf`). |
| Body | Up to 1,024 characters. |
| Footer (optional) | Up to 60 characters, no variables. |
| Buttons (optional) | Up to 10: quick replies (up to 10, kept together), website (up to 2), one call button — a phone number **or** a WhatsApp call — and one copy-code. Titles up to 20 characters, no variables. |

**Variables are named**, like `{{first_name}}`: lowercase letters, digits and
`_`, starting with a letter, at most 16 characters. A batch maps each one to a
CSV column of the same name. Every variable needs a **sample value** in
`examples`; WhatsApp reviews the template with them, so make them realistic.

A **Call on WhatsApp** button (`voice_call`) starts a WhatsApp call to the
number that sent the template, answered by that number's calls agent. It works
for `ttl_minutes` after sending (7 days by default, at most 30).

## Rules checked before submitting

Twilio accepts nearly anything and WhatsApp rejects it minutes later, so
Talqing checks WhatsApp's rules first and returns every problem in one `400`:

- the body can't start or end with a variable (punctuation after it still counts as the end);
- two variables can't be next to each other;
- `x` variables need at least `2x + 1` other words;
- at most 10 emoji, no tabs, no more than four spaces in a row, no `wa.me` links;
- a website button's variable goes at the very end of the URL, after a `/` that follows the domain;
- every variable has a sample, and no sample is left over.

## Creating one

In the dashboard, **New template** opens a form with a live preview filled with
your samples. Through the API:

```bash
curl -X POST https://api.talqing.com/v1/whatsapp/templates \
  -H "Authorization: Bearer $TALQING_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "integration_id": "…",
    "name": "appointment_reminder",
    "language": "en_US",
    "category": "utility",
    "header": {"type": "text", "text": "Your visit"},
    "body": "Hi {{first_name}}, your appointment is on {{date}}. Reply to reschedule.",
    "footer": "Acme Clinic",
    "buttons": [
      {"type": "quick_reply", "text": "Confirm"},
      {"type": "url", "text": "Manage booking", "url": "https://acme.com/b/{{booking_id}}"},
      {"type": "voice_call", "text": "Call us"}
    ],
    "examples": {"first_name": "Rahul", "date": "12 Nov", "booking_id": "8812"}
  }'
```

It is submitted to WhatsApp at once and comes back with `status: "pending"`.

## Statuses

| `status` | Meaning |
| --- | --- |
| `pending` | In review. Usually minutes, at most 48 hours. |
| `approved` | Can be sent. |
| `rejected` | WhatsApp refused it; `rejection_reason` says why. |
| `paused` | WhatsApp paused it after poor feedback from recipients. |
| `disabled` | WhatsApp disabled it. |

`GET /v1/whatsapp/templates?integration_id=…` lists every status, newest
first; add `status=approved` for the sendable ones. The Templates page refreshes
itself while one is in review.

## No editing: duplicate instead

A submitted template can't be changed. To fix a rejected one or change an
approved one, **Duplicate** it, edit the copy and submit it under a new name.

## Deleting

**Delete** (`DELETE /v1/whatsapp/templates/{id}?integration_id=…`) removes it
from Twilio and from WhatsApp, and the name is free again right away. It is
refused while a scheduled, sending or paused batch uses it.

## In WhatsApp Manager

Meta's WhatsApp Manager shows a Talqing template under its name plus a suffix
Twilio adds, such as `appointment_reminder_hx82d3…`, and shows named variables
as `{{1}}`, `{{2}}`. That is expected: sends still use the names.
