{
  "name": "Lector de facturas",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {
          "q": "(from:clientes@clientesiberdrola.es subject:\"Ya tienes disponible tu factura de electricidad de Iberdrola\" has:attachment) OR (from:GRP.es.streamserve@mail02.totalenergies.com subject:\"Nueva factura\") OR \n(from:info@o2online.es subject:\"Factura O2\")"
        },
        "options": {
          "dataPropertyAttachmentsPrefixName": "attachment_",
          "downloadAttachments": true
        }
      },
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.3,
      "position": [
        -2080,
        -144
      ],
      "id": "7ce132ef-ea59-408d-8b78-71c1a94a4b7f",
      "name": "Gmail Trigger",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "0d369666-1fdc-49a0-b6b8-d77b28545429",
              "leftValue": "={{ $binary.attachment_0.fileExtension }}",
              "rightValue": "pdf",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.3,
      "position": [
        -2000,
        -480
      ],
      "id": "a80f8ce7-e8b6-4792-9a6f-45bb137ea701",
      "name": "Filter"
    },
    {
      "parameters": {
        "queue": "tareas_facturas",
        "options": {
          "headers": {
            "header": [
              {
                "key": "proveedor",
                "value": "iberdrola"
              }
            ]
          }
        }
      },
      "type": "n8n-nodes-base.rabbitmq",
      "typeVersion": 1.1,
      "position": [
        -1328,
        -288
      ],
      "id": "5408f224-8c00-4a3b-86f0-5a19e54ca053",
      "name": "RabbitMQ",
      "credentials": {
        "rabbitmq": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "pdf",
        "binaryPropertyName": "attachment_0",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        -1536,
        -288
      ],
      "id": "4be2a07e-dd9d-46d1-9543-765f5bfe6e22",
      "name": "Extract from File"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.headers.from }}",
                    "rightValue": "iberdrola",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "id": "3e5020e2-dce6-4759-a112-13fad61bb75f"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "iberdrola"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "f05fdd4b-22ff-4ca8-bb10-7c9f2c8bc015",
                    "leftValue": "={{ $json.headers.from }}",
                    "rightValue": "totalenergies",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "totalenergies"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "cbadae3c-1182-4c01-aa3a-029c82fd2fd0",
                    "leftValue": "={{ $json.headers.from }}",
                    "rightValue": "o2",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "o2"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        -1872,
        -160
      ],
      "id": "ea42ed6c-c653-430d-a594-c649ef5e6631",
      "name": "Switch"
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={\n  \"text\": \"{{ $json.text }}\"\n}\n ",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1536,
        -96
      ],
      "id": "1f071f58-96ca-48f8-8ecb-902967dd331f",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "queue": "tareas_facturas",
        "options": {
          "headers": {
            "header": [
              {
                "key": "proveedor",
                "value": "totalenergies"
              }
            ]
          }
        }
      },
      "type": "n8n-nodes-base.rabbitmq",
      "typeVersion": 1.1,
      "position": [
        -1328,
        -96
      ],
      "id": "125bbd2b-4c3f-48fc-99fc-fb891b0dc004",
      "name": "RabbitMQ1",
      "credentials": {
        "rabbitmq": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "pdf",
        "binaryPropertyName": "attachment_0",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        -1536,
        96
      ],
      "id": "6cd9ce3a-fa52-4dd2-813c-b68c314f3f0c",
      "name": "Extract from File1"
    },
    {
      "parameters": {
        "queue": "tareas_facturas",
        "options": {
          "headers": {
            "header": [
              {
                "key": "proveedor",
                "value": "o2"
              }
            ]
          }
        }
      },
      "type": "n8n-nodes-base.rabbitmq",
      "typeVersion": 1.1,
      "position": [
        -1328,
        96
      ],
      "id": "b30804b3-ad30-4844-aa05-f9aff5e05245",
      "name": "RabbitMQ2",
      "credentials": {
        "rabbitmq": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter": {
      "main": [
        []
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "RabbitMQ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from File1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "RabbitMQ1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File1": {
      "main": [
        [
          {
            "node": "RabbitMQ2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}