Build with components
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
});
The SDK validates structures with Zod and converts your keys to snake_case for the Meta API.
Typed helper (optional)
Prefer typed guardrails? Use buildTemplateSendPayload. It outputs the same Meta structure with compile‑time guidance.
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' }
]
});
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' } } }]
}
]
});
If you pass an object for language, include policy: “deterministic”.
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.