{
  "id": "Z3wOGZdXKSlSWzgO",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "TEMPLATE Process attached files in Gmail",
  "tags": [],
  "nodes": [
    {
      "id": "fc56a7c7-e89d-46f6-88d1-a6b4c8ce7364",
      "name": "Mark read and archive email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -80,
        -80
      ],
      "parameters": {
        "labelIds": [
          "UNREAD",
          "INBOX"
        ],
        "messageId": "={{ $('Filter based on sender or receiver').item.json.id }}",
        "operation": "removeLabels"
      },
      "credentials": {},
      "typeVersion": 2.1
    },
    {
      "id": "1327a765-2c40-40ef-929f-dfb0790cf048",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -928,
        -560
      ],
      "parameters": {
        "color": 5,
        "width": 1344,
        "height": 432,
        "content": "## Information\nTemplate created by Smultron Studio (https://smultronstudio.com/en) - feel free to reach out at hello@smultronstudio.com\n\n### Instructions (numbers refer to red cards):\n1. Configure credentials\n2. Configure credentials\n3. If you have one or many specific senders for the emails to be processed in this workflow, specify here\n4. If you want a filter on which file types to process, specify here\n5. If you want to process multiple file types and need separate paths, build that here\n6. Configure where to post or upload the files\n7. Configure credentials and customize Slack message\n\n#### Modifications:\nThis template is a skeleton to customize for your use case. It sorts out the n8n specific references and logic to process the files fetched from an email in Gmail.\n\n#### List of mimeTypes for filtering:\nhttps://docs.cloud.google.com/appengine/docs/legacy/standard/php/mail/mail-with-headers-attachments"
      },
      "typeVersion": 1
    },
    {
      "id": "f50f6e40-1b10-48da-9440-1cffe6f6d323",
      "name": "Send a message",
      "type": "n8n-nodes-base.slack",
      "position": [
        592,
        -336
      ],
      "parameters": {
        "text": "=Did something with {{$('Loop attachments').all().length}} files received from {{ $('Trigger on incoming email with attachment').item.json.from.value[0].address }}",
        "otherOptions": {}
      },
      "typeVersion": 2.3
    },
    {
      "id": "5c972c0f-dc9f-4056-a4b5-99bd62ea1a83",
      "name": "Trigger on incoming email with attachment",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -864,
        80
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "q": "has:attachment -label:DRAFT"
        },
        "options": {
          "downloadAttachments": true
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {},
      "typeVersion": 1.3
    },
    {
      "id": "d4504562-3549-4d70-8b60-37e8c027adc7",
      "name": "Filter based on file type",
      "type": "n8n-nodes-base.filter",
      "position": [
        144,
        144
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "5b96c7b7-5896-4e65-89e2-69e679346f42",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $binary.values()[0].mimeType }}",
              "rightValue": "application/zip"
            },
            {
              "id": "ac183995-c533-4698-a2e7-8601f7420c79",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $binary.values()[0].mimeType }}",
              "rightValue": "text/plain"
            },
            {
              "id": "0a949152-7478-4b66-a2c2-e52798627eba",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $binary.values()[0].mimeType }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "75ebfebd-0d76-45e1-b722-6ebcc159460d",
      "name": "Treat different file types different",
      "type": "n8n-nodes-base.switch",
      "position": [
        368,
        128
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "zip",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "48e9243a-8e5b-4f5d-90e7-4c78b0580a76",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $binary.values()[0].mimeType }}",
                    "rightValue": "application/zip"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "no file",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c9b50caa-7335-469f-a863-e24836c1ca79",
                    "operator": {
                      "type": "object",
                      "operation": "empty",
                      "singleValue": true
                    },
                    "leftValue": "={{ $input.first().json }}",
                    "rightValue": "0"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3.3
    },
    {
      "id": "e653ee4e-cf13-4d51-b43b-79920f5add10",
      "name": "Decompress zip",
      "type": "n8n-nodes-base.compression",
      "position": [
        528,
        48
      ],
      "parameters": {
        "outputPrefix": "=file_",
        "binaryPropertyName": "={{ Object.keys($binary)[0] }}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "faf61d9d-2e43-4c6c-b23c-08c85042e1fe",
      "name": "Post file to webhook",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1056,
        272
      ],
      "parameters": {
        "url": "https://n8n.com:8443/webhook/[unique-id]",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "binaryData",
        "inputDataFieldName": "={{ Object.keys($binary)[0] }}"
      },
      "typeVersion": 4.2
    },
    {
      "id": "f96f3ca8-fa1a-4f0c-b0a3-e7b6d9527a72",
      "name": "Loop attachments",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -272,
        80
      ],
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "typeVersion": 3
    },
    {
      "id": "febc18da-137c-4759-b21d-ec1910778a98",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -928,
        -112
      ],
      "parameters": {
        "color": 6,
        "width": 1904,
        "height": 560,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "9ebd9a7e-bc46-4d8c-81b9-c621394683a0",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        -560
      ],
      "parameters": {
        "width": 544,
        "height": 432,
        "content": "## Notification out\nNotify in Slack that files has been processed"
      },
      "typeVersion": 1
    },
    {
      "id": "512d195b-ffab-42db-9c60-dd9f60cde8fe",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        64
      ],
      "parameters": {
        "color": 3,
        "width": 192,
        "height": 448,
        "content": "## 6. Upload file somewhere\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nConfigure or replace this node with some other destination for your files."
      },
      "typeVersion": 1
    },
    {
      "id": "44de5019-f2fd-4c87-bc91-a3c789b18ae5",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        16
      ],
      "parameters": {
        "color": 3,
        "width": 192,
        "height": 496,
        "content": "## 4. Filter based on file type\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nIf you expect one or more file types, you can specify that here. \n\nOr if you only want to process a specific file type in emails with multiple attachments."
      },
      "typeVersion": 1
    },
    {
      "id": "3260063c-d547-418e-af65-2de4f80eaf35",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        320,
        0
      ],
      "parameters": {
        "color": 3,
        "width": 368,
        "height": 512,
        "content": "## 5. Treat different file types separate\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nIf you expect multiple file types that requires different processing, build those paths here (like decompressing zip files). \n\nIf you filter to only process one specific file type or will process all files the same then you can remove this part. "
      },
      "typeVersion": 1
    },
    {
      "id": "79a0bfcf-c12a-4c78-af7a-7174a9f6c8e0",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -912,
        -16
      ],
      "parameters": {
        "color": 3,
        "width": 192,
        "height": 272,
        "content": "## 1. Trigger\nConfigure your credentials here"
      },
      "typeVersion": 1
    },
    {
      "id": "f25b842d-2324-42f2-9f4a-847098d2669f",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        -176
      ],
      "parameters": {
        "color": 3,
        "width": 192,
        "height": 288,
        "content": "## 2. Archive\nConfigure your credentials here"
      },
      "typeVersion": 1
    },
    {
      "id": "367f6c68-5b16-4062-8be8-8a5094b24c0a",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -704,
        -16
      ],
      "parameters": {
        "color": 3,
        "width": 208,
        "height": 272,
        "content": "## 3. Filter sender/receiver\n"
      },
      "typeVersion": 1
    },
    {
      "id": "16094578-c919-4cd3-8a6b-4bf730426f11",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        544,
        -448
      ],
      "parameters": {
        "color": 3,
        "height": 288,
        "content": "## 7. Slack notification\nConfigure your credentials here"
      },
      "typeVersion": 1
    },
    {
      "id": "35253661-cf9c-414d-a0ad-b9f4bf9fa83a",
      "name": "Upload file to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        768,
        160
      ],
      "parameters": {
        "name": "={{ $binary.values()[0].fileName }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        },
        "inputDataFieldName": "={{ Object.keys($binary)[0] }}"
      },
      "credentials": {},
      "typeVersion": 3
    },
    {
      "id": "44a5eaa9-181c-4871-9a66-00927e293dd0",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        176
      ],
      "parameters": {
        "color": 3,
        "width": 256,
        "height": 272,
        "content": "## 8. Example\nThis is a webhook example to replace the Google Drive node (6)"
      },
      "typeVersion": 1
    },
    {
      "id": "95604855-1bf5-485c-bd31-65b4352b6cec",
      "name": "Filter based on sender or receiver",
      "type": "n8n-nodes-base.filter",
      "position": [
        -656,
        80
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "dab0779d-b14a-481c-80d6-33c356009ef5",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.from.value[0].address }}",
              "rightValue": "user@example.com"
            },
            {
              "id": "09479cf5-3c9a-4dab-a987-016462db5470",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.to.value[0].address }}",
              "rightValue": "user@example.com"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "87a1ecf3-63d8-4bb4-9426-f4c9afbc40e7",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -448,
        80
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "$binary"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "8fd24c8f-f0fe-48e5-bf27-da6a79d17f5e",
  "connections": {
    "Split Out": {
      "main": [
        [
          {
            "node": "Loop attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decompress zip": {
      "main": [
        [
          {
            "node": "Upload file to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a message": {
      "main": [
        []
      ]
    },
    "Loop attachments": {
      "main": [
        [
          {
            "node": "Mark read and archive email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Filter based on file type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post file to webhook": {
      "main": [
        []
      ]
    },
    "Filter based on file type": {
      "main": [
        [
          {
            "node": "Treat different file types different",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark read and archive email": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload file to Google Drive": {
      "main": [
        [
          {
            "node": "Loop attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter based on sender or receiver": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Treat different file types different": {
      "main": [
        [
          {
            "node": "Decompress zip",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop attachments",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Upload file to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger on incoming email with attachment": {
      "main": [
        [
          {
            "node": "Filter based on sender or receiver",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}