> ## 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.

# Advanced

> Create and send templates with catalog, MPM, and Flow buttons

## Create

<CodeGroup>
  ```typescript Create template - TypeScript SDK icon="square-js" theme={null}
  import { WhatsAppClient } from '@kapso/whatsapp-cloud-api';

  const client = new WhatsAppClient({
    baseUrl: 'https://api.kapso.ai/meta/whatsapp',
    kapsoApiKey: process.env.KAPSO_API_KEY!
  });

  await client.templates.create({
    businessAccountId: '123456789',
    name: 'appointment_booking',
    category: 'UTILITY',
    language: 'en_US',
    parameterFormat: 'NAMED',
    components: [
      {
        type: 'BODY',
        text: 'Hi {{customer_name}}, book your appointment using the button below.',
        example: {
          body_text_named_params: [
            { param_name: 'customer_name', example: 'Michael' }
          ]
        }
      },
      {
        type: 'BUTTONS',
        buttons: [
          {
            type: 'FLOW',
            text: 'Book Now',
            flow_id: '123456789012345',
            flow_action: 'navigate'
          }
        ]
      }
    ]
  });
  ```

  ```bash Create template - REST API icon="code" theme={null}
  curl -X POST 'https://api.kapso.ai/meta/whatsapp/v24.0/123456789/message_templates' \
    -H 'X-API-Key: YOUR_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
      "name": "appointment_booking",
      "category": "UTILITY",
      "language": "en_US",
      "parameter_format": "NAMED",
      "components": [
        {
          "type": "BODY",
          "text": "Hi {{customer_name}}, book your appointment using the button below.",
          "example": {
            "body_text_named_params": [
              { "param_name": "customer_name", "example": "Michael" }
            ]
          }
        },
        {
          "type": "BUTTONS",
          "buttons": [
            {
              "type": "FLOW",
              "text": "Book Now",
              "flow_id": "123456789012345",
              "flow_action": "navigate"
            }
          ]
        }
      ]
    }'
  ```
</CodeGroup>

## Send

<CodeGroup>
  ```typescript Send template - TypeScript SDK icon="square-js" theme={null}
  import { WhatsAppClient } from '@kapso/whatsapp-cloud-api';

  const client = new WhatsAppClient({
    baseUrl: 'https://api.kapso.ai/meta/whatsapp',
    kapsoApiKey: process.env.KAPSO_API_KEY!
  });

  await client.messages.sendTemplate({
    phoneNumberId: '647015955153740',
    to: '15551234567',
    template: {
      name: 'appointment_booking',
      language: { code: 'en_US' },
      components: [
        {
          type: 'body',
          parameters: [
            { type: 'text', parameterName: 'customer_name', text: 'Michael' }
          ]
        },
        {
          type: 'button',
          sub_type: 'flow',
          index: '0',
          parameters: [
            {
              type: 'action',
              action: {
                flow_token: 'user_session_abc123',
                flow_action_data: {
                  customer_id: 'cust_12345',
                  preferred_date: '2024-02-15'
                }
              }
            }
          ]
        }
      ]
    }
  });
  ```

  ```bash Send template - REST API icon="code" theme={null}
  curl -X POST 'https://api.kapso.ai/meta/whatsapp/v24.0/647015955153740/messages' \
    -H 'X-API-Key: YOUR_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
      "messaging_product": "whatsapp",
      "to": "15551234567",
      "type": "template",
      "template": {
        "name": "appointment_booking",
        "language": {
          "code": "en_US"
        },
        "components": [
          {
            "type": "body",
            "parameters": [
              { "type": "text", "parameter_name": "customer_name", "text": "Michael" }
            ]
          },
          {
            "type": "button",
            "sub_type": "flow",
            "index": "0",
            "parameters": [
              {
                "type": "action",
                "action": {
                  "flow_token": "user_session_abc123",
                  "flow_action_data": {
                    "customer_id": "cust_12345",
                    "preferred_date": "2024-02-15"
                  }
                }
              }
            ]
          }
        ]
      }
    }'
  ```
</CodeGroup>
