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

# Templates

> Build and send approved WhatsApp templates

## Build with components

```ts theme={null}
import { buildTemplatePayload } from '@kapso/whatsapp-cloud-api';

const template = buildTemplatePayload({
  name: 'order_confirmation',
  language: 'en_US', // or { code: 'en_US', policy: 'deterministic' }
  components: [
    {
      type: 'body',
      parameters: [
        { type: 'text', text: 'Ada' },
        { type: 'text', text: '#1234' }
      ]
    }
  ]
});

await client.messages.sendTemplate({
  phoneNumberId: '123',
  to: '56961567267',
  template
});
```

<Note>
  The SDK validates structures with Zod and converts your keys to snake\_case for the Meta API.
</Note>

## Typed helper (optional)

Prefer typed guardrails? Use `buildTemplateSendPayload`. It outputs the same Meta structure with compile‑time guidance.

```ts theme={null}
import { buildTemplateSendPayload } from '@kapso/whatsapp-cloud-api';

const template = buildTemplateSendPayload({
  name: 'order_confirmation',
  language: 'en_US',
  body: [
    { type: 'text', text: 'Ada' },
    { type: 'text', text: '#1234' }
  ]
});
```

### Flow buttons

```ts theme={null}
const withFlow = buildTemplateSendPayload({
  name: 'flow_cta',
  language: 'en_US',
  buttons: [
    {
      type: 'button',
      subType: 'flow',
      index: 0,
      parameters: [{ type: 'action', action: { flow_token: 'FT_123', flow_action_data: { step: 'one' } } }]
    }
  ]
});
```

<Note>
  If you pass an object for language, include <code>policy: "deterministic"</code>.
</Note>

## Tips

* Ensure the template name and language match what’s approved in your WABA.
* Provide parameters in the same order they appear in the template body and buttons.
* For creation, examples are required when your header/body strings contain variables.
