{
  "nodes": [
    {
      "id": "804be255-fa04-4da2-ade7-720815a54719",
      "name": "Delete a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        480,
        272
      ],
      "parameters": {
        "messageId": "={ { $json.content.parts[0].text.id } }",
        "operation": "delete"
      },
      "typeVersion": 2.1
    },
    {
      "id": "168d8523-8167-4365-8f86-3114f48f0887",
      "name": "Reply to a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        480,
        464
      ],
      "parameters": {
        "message": "= { { $json.content.parts[0].text.replyMessage } }",
        "options": {},
        "messageId": "={ { $json.content.parts[0].text.id } }",
        "operation": "reply"
      },
      "typeVersion": 2.1
    },
    {
      "id": "12a25055-b776-4203-a65e-2adc405b6187",
      "name": "Get many messages",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -592,
        272
      ],
      "parameters": {
        "limit": 2,
        "filters": {},
        "operation": "getAll"
      },
      "typeVersion": 2.1
    },
    {
      "id": "7b4c77aa-0d4d-4f94-89f2-c546a689a8c8",
      "name": "Append or update row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        752,
        528
      ],
      "parameters": {
        "columns": {
          "value": {
            "subject": "={ { $('Get many messages').item.json.Subject } }",
            "email id": "={ { $('Get many messages').item.json.From } }"
          },
          "schema": [
            {
              "id": "email id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "email id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1EsLx3e71u3YIboqIlc7pUM81YJAjNuhMSqv7kgyGkzw"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "c4a2506f-c0eb-4e0c-9187-c256c104f596",
      "name": "Append or update row in sheet1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        912,
        384
      ],
      "parameters": {
        "columns": {
          "value": {
            "subject": "={ { $('Get many messages').item.json.Subject } }",
            "email id": "={ { $('Get many messages').item.json.From } }"
          },
          "schema": [
            {
              "id": "email id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "email id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "1619439968"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1EsLx3e71u3YIboqIlc7pUM81YJAjNuhMSqv7kgyGkzw"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "60b53d94-5748-486a-a559-e70f4e125756",
      "name": "When clicking ‘Execute workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -816,
        272
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "27d393ea-46fc-4d25-828f-440043864122",
      "name": "Email Trigger (IMAP)",
      "type": "n8n-nodes-base.emailReadImap",
      "position": [
        -672,
        592
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 2.1
    },
    {
      "id": "f412f452-5f84-49b9-b0a6-d3e06ab1600d",
      "name": "Message a model",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        -368,
        368
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=Take below inputs and validate is it is marketing email\n { { $json.Subject } }\n{ { $json.From } }\n{ { $json.snippet } }\n\nAdd below nodes in body\nid: { { $json.id } },\nsubject: { { $json.Subject } }\nfrom:{ { $json.From } } \n\nalso add isMarketing flag and make it true or false if this a marketing email or not respectively\n\nIncase if it is not a marketing email, I need to reply back to the sender and so create a custom and a respectable reply message and add this reply as new field in response"
            }
          ]
        },
        "jsonOutput": true
      },
      "typeVersion": 1
    },
    {
      "id": "cbb4bf93-536b-47ea-852d-2dfd4fbe24a5",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -992,
        160
      ],
      "parameters": {
        "color": 4,
        "width": 560,
        "height": 256,
        "content": "# 🖐️ Manual Trigger\n⚡ Triggered based on user actions – the workflow starts when the user decides to take action 🧠🕹️"
      },
      "typeVersion": 1
    },
    {
      "id": "2ebd1e06-a096-4283-bfb9-d9cf260c3441",
      "name": "categories emails",
      "type": "n8n-nodes-base.switch",
      "position": [
        256,
        368
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "91c407cc-3862-42f7-a04a-939c05445b6d",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={ { $json.content.parts[0].text.isMarketing } }",
                    "rightValue": "\"isMarketing\": false"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "f0a5e7c2-dd98-4c58-a582-888245c42d35",
                    "operator": {
                      "type": "boolean",
                      "operation": "false",
                      "singleValue": true
                    },
                    "leftValue": "={ { $json.content.parts[0].text.isMarketing } }",
                    "rightValue": "\"isMarketing\": false"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    }
  ],
  "connections": {
    "Message a model": {
      "main": [
        [
          {
            "node": "AI response formatter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete a message": {
      "main": [
        [
          {
            "node": "Append or update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get many messages": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "categories emails": {
      "main": [
        [
          {
            "node": "Delete a message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reply to a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply to a message": {
      "main": [
        [
          {
            "node": "Append or update row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Trigger (IMAP)": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI response formatter": {
      "main": [
        [
          {
            "node": "categories emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Get many messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}