> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zavu.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates

> Create, list and submit WhatsApp message templates via the Zavu TypeScript SDK. Manage variables, categories and approval status from your code.

Templates are reusable message formats for sending structured messages across WhatsApp, SMS, Telegram, and other channels. WhatsApp requires template approval for business-initiated conversations.

## Create Template

```typescript theme={null}
const result = await client.templates.create({
  name: "order_confirmation",
  language: "en",
  body: "Hi {{1}}, your order #{{2}} is confirmed!",
  whatsappCategory: "UTILITY",
  variables: ["customer_name", "order_id"],
});

console.log(result.id); // tpl_xxx
console.log(result.status); // draft, pending, approved, rejected
```

## List Templates

```typescript theme={null}
const result = await client.templates.list({});

for (const template of result.items) {
  console.log(template.id, template.name, template.status);
}

// With pagination
const result = await client.templates.list({
  limit: 50,
  cursor: "cursor_xxx",
});
```

## Get Template

```typescript theme={null}
const result = await client.templates.get({
  templateId: "tpl_abc123",
});

console.log(result.name);
console.log(result.body);
console.log(result.status);
```

## Delete Template

```typescript theme={null}
await client.templates.delete({
  templateId: "tpl_abc123",
});
```

## Submit Template for Approval

After creating a template, you need to submit it to Meta for approval before you can use it:

```typescript theme={null}
const result = await client.templates.submit({
  templateId: "tpl_abc123",
  senderId: "sender_xyz",
  category: "UTILITY", // Optional if already set on template
});

console.log(result.status); // "pending"
```

<Info>
  The `senderId` must reference a sender that has a WhatsApp Business Account configured. Templates are submitted to the WABA associated with that sender.
</Info>

## Template Categories

| Category         | Use Case                                             |
| ---------------- | ---------------------------------------------------- |
| `UTILITY`        | Order updates, account alerts, appointment reminders |
| `MARKETING`      | Promotions, offers, newsletters                      |
| `AUTHENTICATION` | OTP codes, verification messages                     |

## Using Templates in Messages

Templates can be sent on any channel by specifying the `channel` parameter:

```typescript theme={null}
// WhatsApp (default if no channel specified)
const result = await client.messages.send({
  to: "+14155551234",
  messageType: "template",
  content: {
    templateId: "tpl_abc123",
    templateVariables: {
      "1": "John",
      "2": "ORD-12345",
    },
  },
});

// Telegram
const telegramResult = await client.messages.send({
  to: "123456789",
  channel: "telegram",
  messageType: "template",
  content: {
    templateId: "tpl_abc123",
    templateVariables: {
      "1": "John",
      "2": "ORD-12345",
    },
  },
});

// SMS
const smsResult = await client.messages.send({
  to: "+14155551234",
  channel: "sms",
  messageType: "template",
  content: {
    templateId: "tpl_abc123",
    templateVariables: {
      "1": "John",
      "2": "ORD-12345",
    },
  },
});
```

<Info>
  When a channel-specific body (`smsBody`, `telegramBody`) is set on the template, it will be used instead of the default `body`. Contact variables like `{{contact.first_name}}` are auto-resolved from the recipient's contact metadata.
</Info>
