Skip to main content

Create

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.createMessageTemplate({
  whatsappBusinessAccountId: '123456789',
  name: 'appointment_booking',
  category: 'UTILITY',
  language: 'en_US',
  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'
        }
      ]
    }
  ]
});

Send

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', 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'
              }
            }
          }
        ]
      }
    ]
  }
});