{
  "name": "Smart Email Assistant",
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "25ef76a0-87b4-4c20-b43a-181dd8539d92",
              "name": "From",
              "value": "={{ $json.From }}",
              "type": "string"
            },
            {
              "id": "aa34cde5-0b72-47cc-a040-28bbc9cf4a21",
              "name": "Subject",
              "value": "={{ $json.Subject }}",
              "type": "string"
            },
            {
              "id": "21aa7e19-e9da-494d-99ab-a2eb02402015",
              "name": "snippet",
              "value": "={{ $json.snippet }}",
              "type": "string"
            },
            {
              "id": "9112614c-9d90-4715-8445-14c13e86382c",
              "name": "Time",
              "value": "={{ new Date(Number($json.internalDate)).toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' }) }}",
              "type": "string"
            },
            {
              "id": "5d8ad6b7-17a8-4dd5-b9d1-edc3dcd88934",
              "name": "email_context",
              "value": "=From: {{$json.From}} Subject: {{$json.Subject}} Received: {{ new Date(Number($json.internalDate)).toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' }) }}  Content: {{$json.text || $json.snippet}}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        64,
        -112
      ],
      "id": "d760d6d6-ee05-4cb1-9379-aca7d651291f",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=You are a professional executive assistant.\n\nYou will receive the content of emails received today.\n\nYour task is to:\n1. Identify which emails are IMPORTANT and require attention.\n2. Ignore promotional, newsletter, and low-priority emails unless they contain deadlines.\n3. Extract clear ACTION ITEMS if any.\n4. Highlight DEADLINES, DATES, or TIMES mentioned.\n5. Summarize each important email in 2–3 crisp bullet points.\n\nFor each important email, return the output in the following JSON format:\n\n{\n  \"is_important\": true,\n  \"summary\": \"Short summary of the email in 1–2 lines\",\n  \"action_items\": [\n    {\n      \"task\": \"What needs to be done\",\n      \"deadline\": \"Date or time if mentioned, otherwise null\"\n    }\n  ]\n}\n\nIf the email is NOT important, return:\n\n{\n  \"is_important\": false\n}\n\nEmail content:\n----------------\n{{$json.email_context}}\n",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        288,
        -112
      ],
      "id": "53719391-093f-4b02-952e-8109ea249aca",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": "llama-3.1-8b-instant",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "typeVersion": 1,
      "position": [
        368,
        112
      ],
      "id": "0d62989b-0f7e-490e-ada4-24b57792dd5f",
      "name": "Groq Chat Model",
      "credentials": {
        "groqApi": {
          "id": "qinuNuzvvqMt1qAb",
          "name": "Groq account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "7dc2201a-c12e-4193-ac37-2756e0c10c4e",
              "leftValue": "={{ $json.output}}",
              "rightValue": "\"is_important\": true",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.3,
      "position": [
        640,
        -112
      ],
      "id": "26767fd8-0a54-4b0f-bb76-58a69f84c8e0",
      "name": "Filter"
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\nconst tasks = [];\n\nitems.forEach((item, index) => {\n  try {\n    const parsed = JSON.parse(item.json.output);\n    \n    if (parsed.is_important === true && parsed.action_items) {\n      parsed.action_items.forEach(actionItem => {\n        tasks.push({\n          task: actionItem.task,\n          summary: parsed.summary,\n          deadline: actionItem.deadline\n        });\n      });\n    }\n  } catch (error) {\n    console.error(`Error parsing item ${index}:`, error);\n  }\n});\n\n// Return each task as a separate item\nreturn tasks.map(task => ({ json: task }));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        864,
        -112
      ],
      "id": "fea6193e-b2ad-4fec-93d1-f6f5a08c9ba4",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "2e1f0d39-2b66-80af-adc1-fe51f4276107",
          "mode": "list",
          "cachedResultName": "Ai Workflow",
          "cachedResultUrl": "https://www.notion.so/2e1f0d392b6680afadc1fe51f4276107"
        },
        "title": "Task",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Task|title",
              "title": "={{ $json.task }}"
            },
            {
              "key": "Summary|rich_text",
              "textContent": "={{ $json.summary }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        1088,
        -112
      ],
      "id": "9eb6cdb3-5184-4f2d-851d-fade03e281cd",
      "name": "Create a database page",
      "credentials": {
        "notionApi": {
          "id": "g92RVqcOAskZo54o",
          "name": "Notion account"
        }
      }
    },
    {
      "parameters": {
        "operation": "getAll",
        "limit": 10,
        "filters": {
          "receivedAfter": "={{ $now.minus({ hours: 24 }) }}"
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        -160,
        -112
      ],
      "id": "2e56ce62-b287-4c78-b1fa-f852737eda2a",
      "name": "Get Mails",
      "webhookId": "bcfabb65-4308-4cae-af94-81adf69c5ab8",
      "credentials": {
        "gmailOAuth2": {
          "id": "FCTEJeXrzhYk8Ee7",
          "name": "Gmail account 2"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -384,
        -112
      ],
      "id": "d6e81753-346d-49ff-973e-8c870f51b1af",
      "name": "Daily Trigger at 9 AM"
    }
  ],
  "pinData": {},
  "connections": {
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Create a database page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Mails": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Trigger at 9 AM": {
      "main": [
        [
          {
            "node": "Get Mails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": false,
    "timeSavedMode": "fixed",
    "timezone": "Asia/Kolkata",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "versionId": "4d7693cc-f704-40e0-80e6-2154d5e22a1c",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "6fdabfb3425051a03838967ed50d4350dc827cfd636ffc6821f571ab320d29a1"
  },
  "id": "VVKL2YUzlSb2CKNb",
  "tags": []
}