{
  "name": "TBOT10",
  "nodes": [
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "1uHnZR2d9a_6_0XI87g44ejTALaFrsTfIyWcIKc1U2-k",
          "mode": "list",
          "cachedResultName": "N8N_PRUEBA",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1uHnZR2d9a_6_0XI87g44ejTALaFrsTfIyWcIKc1U2-k/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Hoja 1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1uHnZR2d9a_6_0XI87g44ejTALaFrsTfIyWcIKc1U2-k/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Fotos": "={{ $json.excel_data.imagenes }}",
            "SKU": "={{ $json.excel_data.numero_pieza }}",
            "Stock": "=10",
            "Precio [$]": "={{ $json.excel_data.precio }}",
            "Descripci\u00f3n": "={{ $json.excel_data.descripcion }}",
            "Cuotas": "=No agregar cuotas",
            "Costo de env\u00edo": "={{ $json.excel_data.costo_envio }}",
            "Retiro en persona": "={{ $json.excel_data.retiro_persona }}",
            "Forma de env\u00edo": "={{ $json.excel_data.forma_envio }}",
            "Tipo de garant\u00eda": "Garant\u00eda del vendedor",
            "Tiempo de garant\u00eda": "30",
            "Unidad de Tiempo de garant\u00eda": "d\u00edas",
            "Marca": "={{ $json.excel_data.marca }}",
            "N\u00famero de pieza": "={{ $json.excel_data.numero_pieza }}",
            "Origen": "=USA",
            "Condici\u00f3n": "=Nuevo",
            "T\u00edtulo: inclu\u00ed producto, marca, modelo y destaca sus caracter\u00edsticas principales": "={{ $json.excel_data.titulo }}",
            "Cargo por vender": "14%",
            "Costo por ofrecer cuotas": "Sin costo"
          },
          "matchingColumns": [
            "T\u00edtulo: inclu\u00ed producto, marca, modelo y destaca sus caracter\u00edsticas principales"
          ],
          "schema": [
            {
              "id": "T\u00edtulo: inclu\u00ed producto, marca, modelo y destaca sus caracter\u00edsticas principales",
              "displayName": "T\u00edtulo: inclu\u00ed producto, marca, modelo y destaca sus caracter\u00edsticas principales",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Cantidad de caracteres",
              "displayName": "Cantidad de caracteres",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Condici\u00f3n",
              "displayName": "Condici\u00f3n",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "C\u00f3digo universal de producto",
              "displayName": "C\u00f3digo universal de producto",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Fotos",
              "displayName": "Fotos",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "SKU",
              "displayName": "SKU",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Stock",
              "displayName": "Stock",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Precio [$]",
              "displayName": "Precio [$]",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Descripci\u00f3n",
              "displayName": "Descripci\u00f3n",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Cargo por vender",
              "displayName": "Cargo por vender",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Cuotas",
              "displayName": "Cuotas",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Costo por ofrecer cuotas",
              "displayName": "Costo por ofrecer cuotas",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Forma de env\u00edo",
              "displayName": "Forma de env\u00edo",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Costo de env\u00edo",
              "displayName": "Costo de env\u00edo",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Retiro en persona",
              "displayName": "Retiro en persona",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tipo de garant\u00eda",
              "displayName": "Tipo de garant\u00eda",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Tiempo de garant\u00eda",
              "displayName": "Tiempo de garant\u00eda",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Unidad de Tiempo de garant\u00eda",
              "displayName": "Unidad de Tiempo de garant\u00eda",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Marca",
              "displayName": "Marca",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "N\u00famero de pieza",
              "displayName": "N\u00famero de pieza",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Modelo",
              "displayName": "Modelo",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "N\u00famero de identificaci\u00f3n de autoparte usada",
              "displayName": "N\u00famero de identificaci\u00f3n de autoparte usada",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Cantidad de bocas",
              "displayName": "Cantidad de bocas",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Cantidad de cilindros",
              "displayName": "Cantidad de cilindros",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Origen",
              "displayName": "Origen",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Resumen de errores",
              "displayName": "Resumen de errores",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.6,
      "position": [
        1280,
        220
      ],
      "id": "47601d26-738e-4dee-b275-a270e97cf439",
      "name": "Append or update row in sheet",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $json.chatInput }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        160,
        280
      ],
      "id": "550582b6-4db3-4a5d-bcfe-ef43383462fb",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "text": "={{ $json.data }}",
        "attributes": {
          "attributes": [
            {
              "name": "OE/OEM Part Number",
              "description": "OE/OEM Part Number"
            },
            {
              "name": "Manufacturer Part Number",
              "description": "Manufacturer Part Number"
            },
            {
              "name": "title",
              "description": "title"
            },
            {
              "name": "description",
              "description": "description"
            },
            {
              "name": "price",
              "description": "price"
            },
            {
              "name": "images",
              "description": "scrape all images"
            },
            {
              "name": "brand",
              "description": "brand"
            },
            {
              "name": "category",
              "description": "category"
            }
          ]
        },
        "options": {
          "systemPromptTemplate": "You are an expert extraction algorithm.\nOnly extract relevant information from the text and translate to Argentine Spanish.\nIf you do not know the value of an attribute asked to extract, you may omit the attribute's value.\n\nIMPORTANT: When translating descriptions, use Argentine Spanish with proper e-commerce styling - make it appealing, clear, and commercial for MercadoLibre customers.\n\nTITLE OPTIMIZATION: Make titles direct and concise, avoid connectors, maximum 50 characters,traslate Argentina spanish, focus on key product info and compatibility.\n\nAssign the product to a category, choosing from the following list:\n\nCarburadores\n\nChasis\n\nAccesorios\n\nMotor\n\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        560,
        280
      ],
      "id": "1e7019c6-68cd-4737-96d3-a4896dc49b0d",
      "name": "Information Extractor"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        520,
        520
      ],
      "id": "084ee17f-e5ef-4ff5-8173-40507a4e9880",
      "name": "OpenAI Chat Model1",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json.output || {};\n\n// =======================\n// EXTRAER IM\u00c1GENES\n// =======================\nlet imagenes = [];\nif (data.images) {\n  imagenes = data.images.split(',').map(img => img.trim());\n}\n\n// =======================\n// EXTRAER PRECIO Y CALCULAR PRECIO FINAL\n// =======================\nlet precioFinal = null;\nlet precioPagina = null;\nlet priceOriginal = data.price;\n\nif (priceOriginal) {\n  try {\n    const precioString = priceOriginal.toString().replace(/[^\\d.,]/g, '');\n    const precioOriginalNumerico = parseFloat(precioString.replace(',', '.'));\n    \n    if (!isNaN(precioOriginalNumerico)) {\n      const precioEnPesos = precioOriginalNumerico + 52;\n      const precioDef = precioEnPesos * 1280;\n      precioPagina = Math.ceil(precioDef + 56000).toLocaleString('es-AR');\n\n      const precioConAumento = precioDef * 1.34;\n\n      let precioConEscala;\n      if (precioConAumento < 100000) {\n        precioConEscala = precioConAumento + 48000;\n      } else if (precioConAumento <= 200000) {\n        precioConEscala = precioConAumento + 68000;\n      } else {\n        precioConEscala = precioConAumento + 88000;\n      }\n\n      precioFinal = Math.ceil(precioConEscala);\n      precioFinal = precioFinal.toLocaleString('es-AR');\n    }\n  } catch (error) {\n    console.log('Error calculando precio:', error);\n    precioFinal = priceOriginal;\n  }\n}\n\n// =======================\n// EXTRAER N\u00daMERO DE PARTE\n// =======================\nlet numeroPieza = '';\nif (data['OE Part Number']) {\n  numeroPieza = data['OE Part Number'];\n} else if (data['OEM Part Number']) {\n  numeroPieza = data['OEM Part Number'];\n} else if (data['Manufacturer Part Number']) {\n  numeroPieza = data['Manufacturer Part Number'];\n} \n\n// =======================\n// FUNCI\u00d3N PARA LIMPIAR EMOJIS\n// =======================\nfunction limpiarEmojis(texto) {\n  if (!texto) return '';\n  return texto\n    .replace(/[\\u{1F600}-\\u{1F64F}]/gu, '')\n    .replace(/[\\u{1F300}-\\u{1F5FF}]/gu, '')\n    .replace(/[\\u{1F680}-\\u{1F6FF}]/gu, '')\n    .replace(/[\\u{1F1E0}-\\u{1F1FF}]/gu, '')\n    .replace(/[\\u{2600}-\\u{26FF}]/gu, '')\n    .replace(/[\\u{2700}-\\u{27BF}]/gu, '')\n    .replace(/[\\u{FE00}-\\u{FE0F}]/gu, '')\n    .replace(/[\\u{1F900}-\\u{1F9FF}]/gu, '')\n    .replace(/[\\u{1FA70}-\\u{1FAFF}]/gu, '')\n    .replace(/[\ud83c\udffb\ud83c\udffc\ud83c\udffd\ud83c\udffe\ud83c\udfff]/g, '')\n    .replace(/\\s+/g, ' ')\n    .trim();\n}\n\n// =======================\n// ESTRUCTURAR DATOS PARA EXCEL\n// =======================\nconst excelData = {\n  titulo: data.title || '',\n  descripcion: limpiarEmojis(data.description || ''),\n  precio: precioFinal,\n  precio_pagina: precioPagina,\n  marca: data.brand || '',\n  imagenes: imagenes.join(', '),         // para exportaci\u00f3n tipo CSV\n  imagenesPagina: imagenes,              // array real para base de datos\n  condicion: 'Nuevo',\n  category: $input.first().json.output.category,\n  stock: 5,\n  cuotas: 'Agregar cuotas',\n  forma_envio: 'Mercado Env\u00edos',\n  costo_envio: 'Ofrec\u00e9s env\u00edo gratis',\n  retiro_persona: 'Acepto',\n  tipo_garantia: '',\n  tiempo_garantia: '',\n  unidad_tiempo_garantia: '',\n  numero_pieza: numeroPieza || '100',\n  modelo: data.brand || '',\n  cantidad_bocas: '1',\n  cantidad_cilindros: '1',\n  origen: 'USA',\n};\n\nreturn {\n  excel_data: excelData,\n};\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1000,
        360
      ],
      "id": "23432bd7-c568-4f25-963d-82fd1e541912",
      "name": "Extract Apify Data1",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "41ff65b6-9885-49e5-a970-d3ed91ecc819",
              "name": "Incorrecto",
              "value": "No es una url de Ebay",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        160,
        500
      ],
      "id": "667a4647-d138-4a81-8baa-745f2e314def",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "tableId": "productos",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "titulo",
              "fieldValue": "={{ $json.excel_data.titulo }}"
            },
            {
              "fieldId": "descripcion",
              "fieldValue": "={{ $json.excel_data.descripcion }}"
            },
            {
              "fieldId": "marca",
              "fieldValue": "={{ $json.excel_data.marca }}"
            },
            {
              "fieldId": "imagenes",
              "fieldValue": "={{ $json.excel_data.imagenesPagina }}"
            },
            {
              "fieldId": "modelo",
              "fieldValue": "={{ $json.excel_data.numero_pieza }}"
            },
            {
              "fieldId": "origen",
              "fieldValue": "={{ $json.excel_data.origen }}"
            },
            {
              "fieldId": "preciopagina",
              "fieldValue": "={{ $json.excel_data.precio_pagina }}"
            },
            {
              "fieldId": "condicion",
              "fieldValue": "={{ $json.excel_data.condicion }}"
            },
            {
              "fieldId": "category",
              "fieldValue": "={{ $json.excel_data.category }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        1280,
        440
      ],
      "id": "1ebd6526-8686-4cf6-9c40-54edd5e2c6a3",
      "name": "Create a row",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        -440,
        380
      ],
      "id": "78076069-50b3-40a0-a41c-a07a23ef4ae1",
      "name": "When chat message received"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "leftValue": "={{ $json.chatInput }}",
              "rightValue": "ebay",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "id": "20bb972b-7396-4197-9409-917f77a251b4"
            },
            {
              "id": "2b8a730c-8a24-4945-9c51-49f1fb595f04",
              "leftValue": "={{ $json.chatInput }}",
              "rightValue": "amazon",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        -180,
        380
      ],
      "id": "49470d22-747d-4650-a365-b83b3965523b",
      "name": "Validate eBay/Amazon Link"
    }
  ],
  "connections": {
    "Append or update row in sheet": {
      "main": [
        []
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Information Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Information Extractor": {
      "main": [
        [
          {
            "node": "Extract Apify Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Apify Data1": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          },
          {
            "node": "Create a row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a row": {
      "main": [
        []
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Validate eBay/Amazon Link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate eBay/Amazon Link": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5d9c25b6-125a-467f-b446-c35fc075e2a6",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "BDSenKAibMptq3nq",
  "tags": [
    {
      "createdAt": "2025-07-09T21:34:33.571Z",
      "updatedAt": "2025-07-09T21:34:33.571Z",
      "id": "bEaKf8mfCbAO4av1",
      "name": "Engineering"
    },
    {
      "createdAt": "2025-07-09T21:34:33.638Z",
      "updatedAt": "2025-07-09T21:34:33.638Z",
      "id": "Xdycywb8metTDcjE",
      "name": "AI"
    }
  ]
}