{
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "name": "Create smenso Task from Gmail with automatic Project Assignment",
  "tags": [],
  "nodes": [
    {
      "id": "b89f6d4c-b44d-4bca-b16f-2687c664bd31",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -720,
        224
      ],
      "parameters": {
        "filters": {
          "q": "subject:\"smenso Task\" is:unread"
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c6211bd8-5f49-4c23-a042-3154d43c7bbc",
      "name": "Note \u2013 Gmail Trigger",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -768,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 220,
        "height": 364,
        "content": "### 1\ufe0f\u20e3 Gmail Trigger\nPolls your Gmail inbox **every minute** for unread emails with subject containing **\"smenso Task\"**.\n\n**Setup:** Connect your Gmail account via OAuth2."
      },
      "typeVersion": 1
    },
    {
      "id": "6f61ae07-e7c0-45f6-93d5-3467db31a8e8",
      "name": "Filter by Sender Domain",
      "type": "n8n-nodes-base.filter",
      "position": [
        -480,
        224
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "0caffa85-7e3f-4704-a24f-8bf5d9d345a2",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.from.value[0].address }}",
              "rightValue": "@YOUR-DOMAIN.com"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d2b0c69c-c41e-4fec-b37a-0ba88963d63d",
      "name": "Note \u2013 Filter",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -528,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 220,
        "height": 368,
        "content": "### 2\ufe0f\u20e3 Filter by Sender Domain\nOnly processes emails from **trusted senders**.\n\n**Setup:** Replace `@YOUR-DOMAIN.com` with your company email domain.\n\n\ud83d\udca1 Remove this node to accept emails from anyone."
      },
      "typeVersion": 1
    },
    {
      "id": "7a54335e-1c8b-4880-9df0-0b1c149f27b0",
      "name": "Get All Projects",
      "type": "n8n-nodes-smenso.smenso",
      "position": [
        -240,
        224
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c32ea57f-25c7-441c-a09a-e0d091793bd8",
      "name": "Note \u2013 Get Projects",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -288,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 220,
        "height": 364,
        "content": "### 3\ufe0f\u20e3 Get All Projects\nFetches all active projects from your **smenso workspace** to enable automatic keyword matching.\n\n**Setup:** Connect your smenso API credentials."
      },
      "typeVersion": 1
    },
    {
      "id": "ecdb9619-adeb-4bb0-8580-989a2222b4a5",
      "name": "Match Project by Keyword",
      "type": "n8n-nodes-base.code",
      "position": [
        0,
        224
      ],
      "parameters": {
        "jsCode": "const subject = $('Gmail Trigger').item.json.subject ?? '';\nconst body = $('Gmail Trigger').item.json.text ?? $('Gmail Trigger').item.json.snippet ?? '';\nconst sender = $('Gmail Trigger').item.json.from?.value?.[0]?.address ?? '';\n\nconst keywordMatch = subject.match(/\\[([^\\]]+)\\]/);\nconst keyword = keywordMatch ? keywordMatch[1].toLowerCase() : '';\n\nconst title = subject\n  .replace(/smenso Task/i, '')\n  .replace(/\\[[^\\]]+\\]/g, '')\n  .replace(/^[:\\s]+/, '')\n  .trim() || 'New Task from Email';\n\nconst projects = items.map(i => i.json);\nconst matchedProject = projects.find(p =>\n  keyword && (p.title ?? p.name ?? '').toLowerCase().includes(keyword)\n);\n\nconst defaultProjectId = 'YOUR_DEFAULT_PROJECT_ID_HERE';\nconst projectId = matchedProject?.id ?? defaultProjectId;\nconst projectName = matchedProject?.title ?? matchedProject?.name ?? 'Default Project';\n\nreturn [{\n  json: {\n    title,\n    description: `From: ${sender}\\n\\n${body}`,\n    projectId,\n    projectName,\n    sender\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "87fbd0ee-7abd-419c-b7ee-04e64471becd",
      "name": "Note \u2013 Match Project",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 220,
        "height": 360,
        "content": "### 4\ufe0f\u20e3 Match Project by Keyword\nExtracts a **keyword** from the email subject and finds the matching smenso project.\n\n**Email format:**\n`smenso Task [Keyword]: Task Title`\n\n**Setup:** Replace `YOUR_DEFAULT_PROJECT_ID_HERE` with your fallback project ID.\n\n\ud83d\udca1 Find your Project ID: run smenso \u2192 Project \u2192 Get Many \u2192 copy the `id`."
      },
      "typeVersion": 1
    },
    {
      "id": "4a97b72c-3888-426e-a4c3-7c773f94a39e",
      "name": "Create smenso Task",
      "type": "n8n-nodes-smenso.smenso",
      "position": [
        240,
        224
      ],
      "parameters": {
        "title": "={{ $json.title }}",
        "resource": "task",
        "operation": "create",
        "projectId": "={{ $json.projectId }}",
        "additionalFields": {
          "description": "={{ $json.description }}"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f8038ea9-318c-478c-b75c-8a14209db5e2",
      "name": "Note \u2013 Create Task",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        192,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 220,
        "height": 370,
        "content": "### 5\ufe0f\u20e3 Create smenso Task\nCreates a new task in the **matched smenso project** using the email subject as title and email body as description."
      },
      "typeVersion": 1
    },
    {
      "id": "b103d6e4-d23f-4afb-9448-3b799e4d7e85",
      "name": "Send Confirmation Reply",
      "type": "n8n-nodes-base.gmail",
      "position": [
        480,
        224
      ],
      "parameters": {
        "message": "=Hi,\n\nYour task has been successfully created in smenso!\n\nTask: {{ $('Match Project by Keyword').item.json.title }}\nProject: {{ $('Match Project by Keyword').item.json.projectName }}\n\nYou can view it at: https://YOUR_WORKSPACE.smenso.cloud\n\nBest regards,\nyour smenso Automation",
        "options": {},
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "operation": "reply"
      },
      "typeVersion": 2.1
    },
    {
      "id": "47178354-ae2b-44f3-ba5a-be7f2c7b01cd",
      "name": "Note \u2013 Reply",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 220,
        "height": 370,
        "content": "### 6\ufe0f\u20e3 Send Confirmation Reply\nSends an **automatic reply** to the email sender confirming that the task was created, including the task title and project name.\n\n**Setup:** Replace `YOUR_WORKSPACE` with your smenso subdomain (e.g. if your workspace is `acme.smenso.cloud`, replace it with `acme`)."
      },
      "typeVersion": 1
    },
    {
      "id": "24ec584b-9387-4d92-aadf-d356933e8cc5",
      "name": "Mark as Read",
      "type": "n8n-nodes-base.gmail",
      "position": [
        720,
        224
      ],
      "parameters": {
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "operation": "markAsRead"
      },
      "typeVersion": 2.1
    },
    {
      "id": "b6ab176e-a7ac-4383-be97-a353f8f0b145",
      "name": "Note \u2013 Mark Read",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        672,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 220,
        "height": 376,
        "content": "### 7\ufe0f\u20e3 Mark as Read\nMarks the processed email as **read** so it won't be picked up again in the next poll cycle."
      },
      "typeVersion": 1
    },
    {
      "id": "790ca13e-71c0-4615-9c78-684b3c236767",
      "name": "README",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        448
      ],
      "parameters": {
        "color": 6,
        "width": 964,
        "height": 380,
        "content": "## \ud83d\udce7  Create smenso Task from Gmail with automatic Project Assignment\n\n**What this workflow does:**\nMonitors Gmail for emails with subject **\"smenso Task\"**, automatically assigns the task to the right smenso project based on a keyword in the subject line, sends a confirmation reply to the sender, and marks the email as read.\n\n**Quick setup:**\n1. Connect **Gmail** credentials\n2. Connect **smenso API** credentials\n3. Replace `@YOUR-DOMAIN.com` in the Filter node (e.g. `@smenso.de`)\n4. Replace `YOUR_DEFAULT_PROJECT_ID_HERE` in the Match Project node\n5. Replace `YOUR_WORKSPACE` in the Send Confirmation Reply node\n\n**How to send a task by email:**\n- Subject: `smenso Task [Marketing]: Create campaign brief`\n- Body: Task description\n\nThe keyword in `[ ]` is matched to a smenso project name automatically."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Filter by Sender Domain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get All Projects": {
      "main": [
        [
          {
            "node": "Match Project by Keyword",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create smenso Task": {
      "main": [
        [
          {
            "node": "Send Confirmation Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter by Sender Domain": {
      "main": [
        [
          {
            "node": "Get All Projects",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Confirmation Reply": {
      "main": [
        [
          {
            "node": "Mark as Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Match Project by Keyword": {
      "main": [
        [
          {
            "node": "Create smenso Task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}