# Manual / Ad-Hoc Trigger

> Permite que un usuario o administrador inicie un workflow manualmente.

Source: https://docs.sommatic.ai/es/nodes/manual.trigger/

- Slug: `manual.trigger`
- Familia: Triggers
- Versión: 1.0.0
- Estado: Disponible
- Ejecución: sync

Permite que un usuario o administrador inicie un workflow manualmente.

Este trigger define el "botón de inicio" de un workflow. Se usa con frecuencia para pruebas, depuración o workflows que requieren que una persona los inicie de forma explícita (p. ej., "Generar el reporte de fin de mes").

**Características:**
- **Formulario de entrada:** Puede definir un esquema para el payload de entrada que el usuario debe proporcionar al hacer clic en "Run".
- **Pruebas:** Ideal para validar la lógica con conjuntos de datos de prueba variados.

**Casos de uso:**
- Lanzar un script puntual de migración de base de datos.
- Probar un workflow nuevo con datos de clientes simulados.

## Configuración

- `payload_template` (object, opcional): Precarga el formulario de entrada manual para mayor comodidad.

Su configuración muestra los ajustes de ejecución compartidos, pero este nodo aún no aplica reintentos (`retryOnFail`, `maxTries`). Ningún nodo aplica `continueOnFail`.

## Puertos de salida

- `out` (por defecto): Started
- `error`: Error

## Contrato de salida

- `triggered_by` (string, opcional): Usuario que hizo clic en Run.
- `timestamp` (string, opcional)
- `manual_payload` (object, opcional): Datos que ingresó el usuario.

## En expresiones

Lo que un nodo posterior puede leer de la salida de este nodo con `$("Manual / Ad-Hoc Trigger").item.json.<ruta>` (escribe la etiqueta de tu nodo en lugar de `Manual / Ad-Hoc Trigger`). **Editor** marca las rutas que sugiere el editor de workflows en Previous Nodes (el contrato de salida); **Worker** marca las rutas que el worker devuelve de verdad por `out`, según la salida que muestra Puertos.

- `$("Manual / Ad-Hoc Trigger").item.json.triggered_by` (string) = `"manual"`: Usuario que hizo clic en Run.
- `$("Manual / Ad-Hoc Trigger").item.json.timestamp` (string) = `"2026-11-26T09:15:42.008-05:00"`
- `$("Manual / Ad-Hoc Trigger").item.json.manual_payload` (object) = `{…}`: Datos que ingresó el usuario.
- `$("Manual / Ad-Hoc Trigger").item.json.manual_payload.period` (string) = `"2026-10"` (El editor no la sugiere)
- `$("Manual / Ad-Hoc Trigger").item.json.manual_payload.region` (string) = `"north"` (El editor no la sugiere)
- `$("Manual / Ad-Hoc Trigger").item.json.period` (string) = `"2026-10"` (El editor no la sugiere)
- `$("Manual / Ad-Hoc Trigger").item.json.region` (string) = `"north"` (El editor no la sugiere)


## Cómo funciona

Nodo de entrada para workflows iniciados a mano o por una solicitud de ejecución. Combina `payload_template` con la entrada y entrega el resultado tanto en `manual_payload` como en la raíz, con `triggered_by` y `timestamp`.

1. Qué lo inicia: una ejecución desde el editor o una solicitud de ejecución con una entrada. Ejecutar el borrador es una prueba; ejecutar una versión publicada es una ejecución de producción.
2. Resuelve la configuración del nodo y combina `{ ...payload_template, ...input }`: las claves de la entrada tienen prioridad sobre la plantilla.
3. Entrega `{ triggered_by, timestamp, manual_payload, ...merged }` por `out`.

## En un workflow

### Nodo

```json
{
  "node_id": "node-start",
  "label": "Run report",
  "operator_slug": "manual.trigger",
  "operator_version": "1.0.0",
  "config": {
    "payload_template": {
      "region": "north"
    }
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "triggered_by": "manual",
    "timestamp": "2026-11-26T09:15:42.008-05:00",
    "manual_payload": {
      "region": "north",
      "period": "2026-10"
    },
    "region": "north",
    "period": "2026-10"
  },
  "port": "out"
}
```

## Puertos de salida (comportamiento en el código)

### `out`

Siempre, salvo que ocurra una excepción inesperada.

```json
{
  "triggered_by": "manual",
  "timestamp": "2026-11-26T09:15:42.008-05:00",
  "manual_payload": {
    "period": "2026-10",
    "region": "north"
  },
  "period": "2026-10",
  "region": "north"
}
```

### `error`

Solo ante una excepción inesperada; la salida es `{ error, response }`. No se alcanza en el uso normal.

```json
{
  "error": "<exception message>",
  "response": null
}
```

## Comportamiento en el código

- `payload_template`: Valores predeterminados que se combinan por debajo de la entrada. Si una clave coincide con `triggered_by`, `timestamp` o `manual_payload`, el valor combinado los reemplaza en la raíz.

## Notas y límites

- `triggered_by` siempre es `manual`: el usuario que inició la ejecución no se pasa al nodo.
- `timestamp` es la hora local del orquestador en formato ISO.
- Cuando el workflow tiene estado guardado de disparador o clave-valor, el backend agrega `$trigger_state` / `$kv_state` a la entrada, así que también aparecen en la salida.
- Con datos de muestra el motor omite el nodo y entrega la entrada de muestra tal cual por `out`, sin `triggered_by`, `timestamp` ni `manual_payload`.


## Contratos (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "manual.trigger",
  "name": "Manual / Ad-Hoc Trigger",
  "category": "triggers",
  "version": "1.0.0",
  "description": "Allows a workflow to be started manually by a user or administrator.\n\n  This trigger defines the \"Start Button\" for a workflow. It is commonly used for testing, debugging, or workflows that require explicit human initiation (e.g., \"Run End of Month Report\").\n\n  **Features:**\n  - **Form Input:** Can define a schema for the input payload the user must provide when clicking \"Run\".\n  - **Testing:** Ideal for validating logic with disparate test datasets.\n\n  **Use Cases:**\n  - Launching a one-off database migration script.\n  - Testing a new workflow with mock customer data.",
  "capabilities": [
    "testing",
    "ad-hoc",
    "manual",
    "ui"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "payload_template": {
        "type": "object",
        "title": "Default/Sample Payload",
        "description": "Auto-fills the manual input form for convenience."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": null,
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "triggered_by": {
        "type": "string",
        "description": "User who clicked Run."
      },
      "timestamp": {
        "type": "string",
        "format": "date-time"
      },
      "manual_payload": {
        "type": "object",
        "description": "Data entered by user."
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Started",
      "is_default": true
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "test",
    "manual",
    "debug",
    "start"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "payload_template": {
      "type": "object",
      "title": "Default/Sample Payload",
      "description": "Auto-fills the manual input form for convenience."
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "triggered_by": {
      "type": "string",
      "description": "User who clicked Run."
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "manual_payload": {
      "type": "object",
      "description": "Data entered by user."
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Started",
    "is_default": true
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
