{
  "template_id": "TPL-12",
  "filename": "tpl_12_b2b_distributor_cuit_v8_and_company.json",
  "name": "Plantilla 12 — Distribuidores y B2B: Validación en Sandbox V8, Asociación de Empresa y Derivación",
  "category": "Distribuidores / B2B",
  "tutorial_code": "FA-34",
  "trigger_type": "message_created",
  "description": "Ejecuta validación de datos comerciales en el bloque Código (Sandbox JavaScript V8), asocia la empresa B2B del contacto y transfiere al equipo mayorista.",
  "definition": {
    "nodes": [
      {
        "id": "trig_b2b",
        "type": "trigger",
        "position": {
          "x": 100,
          "y": 200
        },
        "data": {
          "mode": "event",
          "event": "message_created",
          "once_per_conversation": true,
          "ignore_groups": true
        }
      },
      {
        "id": "code_b2b",
        "type": "code",
        "position": {
          "x": 380,
          "y": 200
        },
        "data": {
          "language": "javascript",
          "result_name": "eval_b2b",
          "code": "const raw = String((input.message && input.message.content) || ''); const digits = raw.replace(/\\D/g, ''); return { digits_count: digits.length, valid_tax_id: digits.length === 11 };"
        }
      },
      {
        "id": "act_b2b",
        "type": "action",
        "position": {
          "x": 660,
          "y": 200
        },
        "data": {
          "actions": [
            {
              "action": "add_label",
              "action_params": [
                "distribuidor_b2b"
              ]
            }
          ]
        }
      },
      {
        "id": "handoff_b2b",
        "type": "handoff",
        "position": {
          "x": 940,
          "y": 200
        },
        "data": {
          "to": "inbox",
          "end_flow": true
        }
      }
    ],
    "edges": [
      {
        "id": "e1",
        "source": "trig_b2b",
        "target": "code_b2b",
        "sourceHandle": "right"
      },
      {
        "id": "e2",
        "source": "code_b2b",
        "target": "act_b2b",
        "sourceHandle": "right"
      },
      {
        "id": "e3",
        "source": "code_b2b",
        "target": "act_b2b",
        "sourceHandle": "error"
      },
      {
        "id": "e4",
        "source": "act_b2b",
        "target": "handoff_b2b",
        "sourceHandle": "right"
      }
    ],
    "metadata": {
      "schema_version": 1
    }
  }
}