{
  "name": "Recibos video",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "16jxSJmSNTuYFqvqMir70QCvj6hdzpjBo",
          "mode": "list",
          "cachedResultName": "Recibo Nuevo",
          "cachedResultUrl": "https://drive.google.com/drive/folders/16jxSJmSNTuYFqvqMir70QCvj6hdzpjBo"
        },
        "event": "fileCreated",
        "options": {}
      },
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "id": "7d90a81b-ee68-4a57-8916-4f88533bd210",
      "name": "Google Drive Trigger",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "move",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "value": "19qGRhA3gkF0L-iIjsyS6UYVQFZCClS2-",
          "mode": "list",
          "cachedResultName": "Sin Categoria",
          "cachedResultUrl": "https://drive.google.com/drive/folders/19qGRhA3gkF0L-iIjsyS6UYVQFZCClS2-"
        }
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        220,
        0
      ],
      "id": "2e715c2a-d5fc-4166-8ee8-4fafc59c54af",
      "name": "Google Drive",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {
          "fields": [
            "webViewLink"
          ]
        }
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        440,
        0
      ],
      "id": "f1f8825d-da2f-40af-8e12-e5f288ef2ddb",
      "name": "Google Drive1",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "0f686181-5cf0-4a09-b4c7-681367fe1ef6",
              "name": "LinkArchivo",
              "value": "={{ $json.webViewLink }}",
              "type": "string"
            },
            {
              "id": "25a13e30-1a83-4084-9d79-772990adad64",
              "name": "IdArchivo",
              "value": "={{ $('Google Drive').item.json.id }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        660,
        0
      ],
      "id": "f68772f4-7c9a-495c-98f0-1bb3881009d5",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -60,
        300
      ],
      "id": "80ce813c-7374-48c4-915f-81cb9a4b3707",
      "name": "Loop Over Items"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "name": "Replace Me",
      "typeVersion": 1,
      "position": [
        120,
        720
      ],
      "id": "e210744f-3c2a-4dca-bc45-f71527acdc74"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.pdf.co/v1/ai-invoice-parser",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "={{ $json.LinkArchivo }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        100,
        300
      ],
      "id": "b88f3d1b-0f9f-49a2-a908-8002f4a58609",
      "name": "HTTP Request",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "amount": 30
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        260,
        300
      ],
      "id": "3a2c6762-9eb6-414e-aa77-16962c20380f",
      "name": "Wait"
    },
    {
      "parameters": {
        "url": "https://api.pdf.co/v1/job/check",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "jobID",
              "value": "={{ $json.jobId }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        420,
        300
      ],
      "id": "bae6c5cb-bfb4-4d37-8790-7eaafc2814b9",
      "name": "HTTP Request1",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "working",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "54b30d7b-8829-413c-9555-22e1f0fd8484"
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "bcd876bf-2844-4867-ac19-8b948f2841d1",
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "success",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        600,
        300
      ],
      "id": "142330b2-6b01-4f7e-af6e-e9ac8611f56e",
      "name": "Switch"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-3.5-turbo",
          "mode": "list",
          "cachedResultName": "GPT-3.5-TURBO"
        },
        "messages": {
          "values": [
            {
              "content": "Eres mi contador, que me ayuda a tener en orden mis cuentas y mis facturas.",
              "role": "system"
            },
            {
              "content": "En el imput tendrzs la infroamcion de una factura, tienes que ayudarme a sacar la informacion importante la factura.\n\n- Comercio: quien genero la factura\n- Valor: Por cuanto es la factura\n- Fecha en formato dd/mm/aaaa\n- Numerode factura\n- Ademas dame la siguiente variable segun la fecha \"facturas_{mes_de la factura}\"\n\n- Todos estos datos devuelvemelos en formato json, cada dato es una variable por separado.\n= el \"facturas_{mes_de la factura}\" un ejemplo es \"facturas_{abril}\""
            },
            {
              "content": "=Input:  {{ $json.parsedInvoice }}"
            }
          ]
        },
        "jsonOutput": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        100,
        580
      ],
      "id": "f42e6c50-a386-4ca5-ba4f-cf397ddddd99",
      "name": "OpenAI",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "fileFolder",
        "searchMethod": "query",
        "queryString": "=name = '{{ $json.message.content.facturas_abril }}' and mimeType = 'application/vnd.google-apps.folder'\n",
        "filter": {},
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        420,
        580
      ],
      "id": "3b75660c-fe8c-4d93-84c7-6062311916b5",
      "name": "Google Drive2",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "move",
        "fileId": {
          "__rl": true,
          "value": "={{ $('Google Drive').item.json.id }}",
          "mode": "id"
        },
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        }
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        620,
        580
      ],
      "id": "936ed52d-2d2f-4f92-b2c5-d84fa617e287",
      "name": "Google Drive3",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "1G3kAJzpxfiTVl6sfmpt07996hZOIXrhd1QmWlygz9Mo"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Hoja 1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1G3kAJzpxfiTVl6sfmpt07996hZOIXrhd1QmWlygz9Mo/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Vendedor": "={{ $('OpenAI').item.json.message.content.Comercio }}",
            "Fecha": "={{ $('OpenAI').item.json.message.content.Fecha }}",
            "Valor": "={{ $('OpenAI').item.json.message.content.Valor }}",
            "Numero de Factura": "={{ $('OpenAI').item.json.message.content.NumeroDeFactura }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Valor",
              "displayName": "Valor",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Vendedor",
              "displayName": "Vendedor",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Fecha",
              "displayName": "Fecha",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Numero de Factura",
              "displayName": "Numero de Factura",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        -60,
        720
      ],
      "id": "13c5794e-e353-41c4-9340-ac46a7c081d6",
      "name": "Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Detectar factura\n\n",
        "height": 240,
        "width": 880,
        "color": 3
      },
      "id": "9f4f7cab-dcc5-457f-997e-d397ba7b9257",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        -80
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "## Extraer datos de factura\n\n",
        "height": 240,
        "width": 880
      },
      "id": "a32816b5-ec70-4607-91cf-d1826fd6c8c5",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        220
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "## Organizar datos\n\n\n\n",
        "height": 360,
        "width": 880,
        "color": 4
      },
      "id": "5d145f23-b91a-4dd9-a3b1-1438ce6d461a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        520
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "jsCode": "return [\n  {\n    json: {\n      parsedInvoice: JSON.stringify($json.body)\n    }\n  }\n]"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -60,
        580
      ],
      "id": "6885555f-ae2b-4c83-94c0-bdba43f581ae",
      "name": "Code"
    }
  ],
  "connections": {
    "Google Drive Trigger": {
      "main": [
        [
          {
            "node": "Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive": {
      "main": [
        [
          {
            "node": "Google Drive1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive1": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Replace Me": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "Google Drive2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive2": {
      "main": [
        [
          {
            "node": "Google Drive3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive3": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Replace Me",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "b6acfbe0-7d8d-4ad5-90ab-8d990557001b",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "q5Gn2rrUKPsfoIi4",
  "tags": []
}