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

# Botones dinámicos

> Variables en botones URL, quick reply y copiar código.

Guía de [Enviar plantilla](/whatsapp/enviar-plantilla) · [Tipos de plantilla](/whatsapp/tipos-de-plantilla)

Los botones dinámicos usan `type: "button"`. El campo `index` indica la posición del botón en la plantilla (comienza en `0`).

El playground se precarga con un botón URL. Completa `to` y `name` con tus datos reales; los ejemplos solo muestran `components`.

## Botón URL (`sub_type: "url"`)

El valor de `text` se concatena al final de la URL base definida en la plantilla.

```json theme={null}
{
  "language": "es_MX",
  "components": [
    {
      "type": "button",
      "sub_type": "url",
      "index": "0",
      "parameters": [
        { "type": "text", "text": "?ref=abc123" }
      ]
    }
  ]
}
```

## Botón quick reply (`sub_type: "quick_reply"`)

Envía el `payload` que identifica la opción seleccionada.

```json theme={null}
{
  "language": "es",
  "components": [
    {
      "type": "button",
      "sub_type": "quick_reply",
      "index": "0",
      "parameters": [
        { "type": "payload", "payload": "ACCION_OK" }
      ]
    }
  ]
}
```

## Botón copiar código (`sub_type: "copy_code"`)

Envía el código que el destinatario podrá copiar con un toque.

```json theme={null}
{
  "language": "es",
  "components": [
    {
      "type": "button",
      "sub_type": "copy_code",
      "index": "0",
      "parameters": [
        { "type": "coupon_code", "coupon_code": "CODIGO123" }
      ]
    }
  ]
}
```

<Note>
  Puedes combinar varios componentes en un mismo envío (por ejemplo, header PDF + variables en body + botón URL). Cada `index` de botón debe corresponder a la posición real del botón en la plantilla aprobada.
</Note>


## OpenAPI

````yaml openapi/examples/botones-dinamicos.json POST /whatsapp/{phoneNumberId}/template
openapi: 3.1.0
info:
  title: Insurance Boosters API - Botón URL dinámico
  version: 1.0.0
servers:
  - url: https://api.insuranceboosters.com/api/v1
    description: Producción
security:
  - IbApiKey: []
paths:
  /whatsapp/{phoneNumberId}/template:
    post:
      tags:
        - WhatsApp
      summary: Botón URL dinámico
      description: Envía una plantilla de WhatsApp aprobada a un destinatario.
      operationId: sendWhatsAppTemplate_botones_dinamicos
      parameters:
        - name: phoneNumberId
          in: path
          required: true
          description: >-
            Identificador de tu línea de WhatsApp. Solicítalo con tu ejecutivo
            de cuenta.
          schema:
            type: string
            example: '123456789012345'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SendTemplateRequest'
            example:
              to: ''
              name: ''
              language: es_MX
              components:
                - type: button
                  sub_type: url
                  index: '0'
                  parameters:
                    - type: text
                      text: '?ref=abc123'
      responses:
        '200':
          description: Plantilla enviada correctamente.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SendTemplateResponse'
        '400':
          description: >-
            Solicitud inválida (campos faltantes, components incorrectos o URL
            de media no accesible).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SimpleErrorResponse'
              example:
                error: Missing Recipient Phone Number (to).
        '401':
          description: API key inválida o línea sin credenciales de WhatsApp.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SimpleErrorResponse'
              example:
                message: Invalid API key.
        '404':
          description: Línea de WhatsApp no encontrada.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SimpleErrorResponse'
              example:
                error: Phone line not found
        '500':
          description: Error del servicio.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SimpleErrorResponse'
              example:
                error: Internal server error
      security:
        - IbApiKey: []
components:
  schemas:
    SendTemplateRequest:
      type: object
      required:
        - to
        - name
      properties:
        to:
          type: string
          description: >-
            Teléfono del destinatario en formato E.164 (solo dígitos, sin `+`).
            Ejemplo México: 5215512345678.
          x-default: ''
        name:
          type: string
          description: Nombre exacto de la plantilla aprobada.
          x-default: ''
        language:
          type: string
          description: Código de idioma de la plantilla. Por defecto `es`.
          default: es
          example: es
        components:
          type: array
          description: >-
            Componentes dinámicos (`header`, `body`, `button`). Omitir o enviar
            `[]` si la plantilla no tiene variables.
          items:
            $ref: '#/components/schemas/TemplateComponent'
          default: []
        inactiveBot:
          type: boolean
          description: >-
            Si es `true`, desactiva respuestas automáticas para ese contacto
            tras el envío.
          default: false
    SendTemplateResponse:
      type: object
      properties:
        messaging_product:
          type: string
          enum:
            - whatsapp
        contacts:
          type: array
          items:
            type: object
            properties:
              input:
                type: string
              wa_id:
                type: string
        messages:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                description: Identificador del mensaje enviado.
    SimpleErrorResponse:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
    TemplateComponent:
      oneOf:
        - $ref: '#/components/schemas/HeaderComponent'
        - $ref: '#/components/schemas/BodyComponent'
        - $ref: '#/components/schemas/ButtonComponent'
      discriminator:
        propertyName: type
        mapping:
          header:
            $ref: '#/components/schemas/HeaderComponent'
          body:
            $ref: '#/components/schemas/BodyComponent'
          button:
            $ref: '#/components/schemas/ButtonComponent'
    HeaderComponent:
      title: Encabezado (header)
      type: object
      required:
        - type
        - parameters
      properties:
        type:
          type: string
          enum:
            - header
        parameters:
          type: array
          items:
            oneOf:
              - $ref: '#/components/schemas/ImageParameter'
              - $ref: '#/components/schemas/VideoParameter'
              - $ref: '#/components/schemas/DocumentParameter'
            discriminator:
              propertyName: type
              mapping:
                image:
                  $ref: '#/components/schemas/ImageParameter'
                video:
                  $ref: '#/components/schemas/VideoParameter'
                document:
                  $ref: '#/components/schemas/DocumentParameter'
    BodyComponent:
      title: Cuerpo (body)
      type: object
      required:
        - type
        - parameters
      properties:
        type:
          type: string
          enum:
            - body
        parameters:
          type: array
          items:
            $ref: '#/components/schemas/TextParameter'
    ButtonComponent:
      title: Botón (button)
      type: object
      required:
        - type
        - sub_type
        - index
        - parameters
      properties:
        type:
          type: string
          enum:
            - button
        sub_type:
          type: string
          enum:
            - url
            - quick_reply
            - copy_code
          description: Tipo de botón dinámico.
        index:
          type: string
          description: Índice del botón en la plantilla (base 0, como string).
          example: '0'
        parameters:
          type: array
          items:
            $ref: '#/components/schemas/ButtonParameter'
    ImageParameter:
      title: Imagen
      type: object
      required:
        - type
        - image
      properties:
        type:
          type: string
          enum:
            - image
        image:
          title: Archivo de imagen
          type: object
          required:
            - link
          properties:
            link:
              type: string
              format: uri
              description: URL pública de la imagen (HTTPS). Es el único campo requerido.
    VideoParameter:
      title: Video
      type: object
      required:
        - type
        - video
      properties:
        type:
          type: string
          enum:
            - video
        video:
          title: Archivo de video
          type: object
          required:
            - link
          properties:
            link:
              type: string
              format: uri
    DocumentParameter:
      title: Documento
      type: object
      required:
        - type
        - document
      properties:
        type:
          type: string
          enum:
            - document
        document:
          title: Archivo PDF
          type: object
          required:
            - link
          properties:
            link:
              type: string
              format: uri
            filename:
              type: string
    TextParameter:
      title: Texto
      type: object
      required:
        - type
        - text
      properties:
        type:
          type: string
          enum:
            - text
        text:
          type: string
        parameter_name:
          type: string
          description: Nombre del parámetro cuando la plantilla usa variables con nombre.
    ButtonParameter:
      oneOf:
        - $ref: '#/components/schemas/ButtonTextParameter'
        - $ref: '#/components/schemas/ButtonPayloadParameter'
        - $ref: '#/components/schemas/ButtonCouponParameter'
      discriminator:
        propertyName: type
        mapping:
          text:
            $ref: '#/components/schemas/ButtonTextParameter'
          payload:
            $ref: '#/components/schemas/ButtonPayloadParameter'
          coupon_code:
            $ref: '#/components/schemas/ButtonCouponParameter'
    ButtonTextParameter:
      title: Texto para URL
      type: object
      required:
        - type
        - text
      properties:
        type:
          type: string
          enum:
            - text
        text:
          type: string
          description: Fragmento que se concatena al final de la URL del botón.
    ButtonPayloadParameter:
      title: Payload quick reply
      type: object
      required:
        - type
        - payload
      properties:
        type:
          type: string
          enum:
            - payload
        payload:
          type: string
    ButtonCouponParameter:
      title: Código copiar
      type: object
      required:
        - type
        - coupon_code
      properties:
        type:
          type: string
          enum:
            - coupon_code
        coupon_code:
          type: string
  securitySchemes:
    IbApiKey:
      type: apiKey
      in: header
      name: x-ib-api-key
      description: API key emitida por Insurance Boosters.

````