{
  "name": "Processar Anexos ServiceNow",
  "nodes": [
    {
      "parameters": {
        "downloadAttachments": true,
        "options": {
          "customEmailConfig": "[\"FROM \\\"ricardo.amorim@wkve.com.br\\\"\"]"
        }
      },
      "name": "EmailReadImap",
      "type": "n8n-nodes-base.emailReadImap",
      "typeVersion": 2,
      "position": [
        1296,
        176
      ],
      "id": "f2cf68bf-9ff9-4418-a284-639512dbd606",
      "credentials": {
        "imap": {
          "id": "CyqBL8TW3I7MWyhs",
          "name": "IMAP account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const result = [];\nfor (const item of $input.all()) {\n  if (item.binary) {\n    for (const key of Object.keys(item.binary)) {\n      result.push({\n        json: {\n          ...item.json,\n          attachmentKey: key,\n          fileName: item.binary[key].fileName\n        },\n        binary: {\n          data: item.binary[key]\n        }\n      });\n    }\n  } else {\n    result.push(item);\n  }\n}\nreturn result;"
      },
      "name": "Split Attachments",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1464,
        176
      ],
      "id": "a2cf68bf-9ff9-4418-a284-639512dbd607"
    },
    {
      "parameters": {
        "fileName": "=/tmp/{{$json.fileName}}",
        "options": {},
        "dataPropertyName": "data"
      },
      "name": "Write Binary File",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        1632,
        176
      ],
      "id": "f58a904c-a828-4252-aad4-404f7b26629d"
    },
    {
      "parameters": {
        "command": "=/var/www/html/robot/.venv/bin/python3 /var/www/html/robot/execution/process_attachment_sgd.py \"{{$json.fileName}}\""
      },
      "name": "Execute Command",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1856,
        176
      ],
      "id": "88f62534-609a-4ef4-8807-ab693fdeae34"
    }
  ],
  "connections": {
    "EmailReadImap": {
      "main": [
        [
          {
            "node": "Split Attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Attachments": {
      "main": [
        [
          {
            "node": "Write Binary File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Binary File": {
      "main": [
        [
          {
            "node": "Execute Command",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}