{
  "name": "AI-Renamed Gmail Attachments to Drive",
  "tags": [],
  "nodes": [
    {
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1120,
        124
      ],
      "parameters": {
        "text": "=You are an expert content analyser and file naming assistant...\ntext: {{ $json.text }}\ndate: {{ $json.info.CreationDate }}",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1192,
        348
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "name": "Upload file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1696,
        0
      ],
      "parameters": {
        "name": "={{ $json.output }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "url",
          "value": ""
        },
        "inputDataFieldName": "attachment_1"
      },
      "typeVersion": 3
    },
    {
      "name": "Mark message as read",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1920,
        0
      ],
      "parameters": {
        "messageId": "={{ $('Set Required Fields').item.json.id }}",
        "operation": "markAsRead"
      },
      "typeVersion": 2.1
    },
    {
      "name": "Merge Data for Upload",
      "type": "n8n-nodes-base.merge",
      "position": [
        1472,
        0
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "name": "Get Unread Messages with Attachments",
      "type": "n8n-nodes-base.gmail",
      "position": [
        224,
        0
      ],
      "parameters": {
        "filters": {
          "readStatus": "unread"
        },
        "operation": "getAll"
      },
      "typeVersion": 2.1
    },
    {
      "name": "Set Required Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        448,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "name": "id",
              "type": "string",
              "value": "={{ $json.id }}"
            },
            {
              "name": "threadId",
              "type": "string",
              "value": "={{ $json.threadId }}"
            },
            {
              "name": "from.value[0].name",
              "type": "string",
              "value": "={{ $json.from.value[0].name }}"
            },
            {
              "name": "date",
              "type": "string",
              "value": "={{ $json.date }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "name": "Download Attachments",
      "type": "n8n-nodes-base.gmail",
      "position": [
        672,
        0
      ],
      "parameters": {
        "simple": false,
        "options": {
          "downloadAttachments": true
        },
        "messageId": "={{ $json.id }}",
        "operation": "get"
      },
      "typeVersion": 2.1
    },
    {
      "name": "Extract from Attachments",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        896,
        0
      ],
      "parameters": {
        "options": {},
        "operation": "pdf",
        "binaryPropertyName": "attachment_0"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "81cda4d6-8828-4b64-8afe-88b302168717",
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Merge Data for Upload",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Upload file": {
      "main": [
        [
          {
            "node": "Mark message as read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Unread Messages with Attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set Required Fields": {
      "main": [
        [
          {
            "node": "Download Attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Attachments": {
      "main": [
        [
          {
            "node": "Extract from Attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Data for Upload": {
      "main": [
        [
          {
            "node": "Upload file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from Attachments": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge Data for Upload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Unread Messages with Attachments": {
      "main": [
        [
          {
            "node": "Set Required Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}