{
  "id": "BVP6Cf7CmBQI9nib",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Create smenso Task from Gmail with automatic Project Assignment",
  "tags": [],
  "nodes": [
    {
      "id": "f450d65f-9862-4583-8f25-70a7a9aad8d0",
      "name": "Section \u2013 Receive & Filter",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2048,
        1360
      ],
      "parameters": {
        "width": 520,
        "height": 320,
        "content": "## 1\ufe0f\u20e3 Receive & Filter\nPolls Gmail every minute for unread mails with subject containing `smenso Task` and lets only senders from your trusted domain through."
      },
      "typeVersion": 1
    },
    {
      "id": "53fc6ab1-13cd-4df9-ad0e-5cbc386a01b9",
      "name": "Section \u2013 Match Project",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2576,
        1360
      ],
      "parameters": {
        "width": 480,
        "height": 320,
        "content": "## 2\ufe0f\u20e3 Match Project\nFetches all active smenso projects and finds the one whose name contains the keyword `[xxx]` from the email subject. Falls back to a default project if nothing matches."
      },
      "typeVersion": 1
    },
    {
      "id": "1a28fc6f-8bb0-4496-acf3-289f976da130",
      "name": "Section \u2013 Create & Notify",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3056,
        1360
      ],
      "parameters": {
        "width": 760,
        "height": 320,
        "content": "## 3\ufe0f\u20e3 Create Task & Confirm\nCreates the smenso task in the matched project, sends a confirmation reply to the sender, and marks the email as read so it isn't picked up again."
      },
      "typeVersion": 1
    },
    {
      "id": "4c655ad2-3fc3-4d0b-918c-3b1217158e21",
      "name": "Main Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2048,
        560
      ],
      "parameters": {
        "color": 5,
        "width": 1304,
        "height": 544,
        "content": "# \ud83d\udce7 Create smenso Task from Gmail with automatic Project Assignment\n\nMonitors Gmail for emails with subject **`smenso Task`**, automatically routes the task to the right smenso project based on a keyword in the subject line, replies to the sender, and marks the email as read.\n\n### How it works\n1. The Gmail trigger polls your inbox every minute for unread mails whose subject contains `smenso Task`.\n2. A filter checks that the sender belongs to your trusted domain.\n3. All projects are fetched from smenso. A Code node extracts the keyword in `[ ]` from the subject and finds the best-matching project (falling back to a default one if nothing matches).\n4. A new task is created in that project, with the email subject as title and body as description.\n5. The sender gets an automatic confirmation reply and the original email is marked as read.\n\n### Setup\n1. Connect your **Gmail** OAuth2 credentials.\n2. Connect your **smenso API** credentials.\n3. Replace `@YOUR-DOMAIN.com` in the *Filter by Sender Domain* node with your company email domain (e.g. `@acme.com`).\n4. Replace `YOUR_DEFAULT_PROJECT_ID_HERE` in the *Match Project by Keyword* node with the project ID to use when no keyword matches.\n5. Replace `YOUR_WORKSPACE` in the *Send Confirmation Reply* node with your smenso subdomain (e.g. `acme.smenso.cloud` \u2192 `acme`).\n\n### Customization\n- **Sending a task by email:** subject `smenso Task [Marketing]: Create campaign brief`. The keyword in `[ ]` is matched to a smenso project name automatically.\n- Remove the *Filter by Sender Domain* node to accept emails from anyone.\n- Replace the Gmail trigger with Outlook / IMAP / Webhook to feed the workflow from a different source."
      },
      "typeVersion": 1
    },
    {
      "id": "14e75553-79c9-4934-90bc-f9afc4d28717",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        2128,
        1520
      ],
      "parameters": {
        "filters": {
          "q": "subject:\"smenso Task\" is:unread"
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "504d7e1a-ea95-4534-99c5-bd5a669dfbfa",
      "name": "Filter by Sender Domain",
      "type": "n8n-nodes-base.filter",
      "position": [
        2368,
        1520
      ],
      "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": "4cb2e04a-7ea4-4fe2-9d87-105b2ba30dc4",
      "name": "Get All Projects",
      "type": "n8n-nodes-smenso.smenso",
      "position": [
        2656,
        1520
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "fbd8cc73-1e86-4b67-af7d-a89d137aee54",
      "name": "Match Project by Keyword",
      "type": "n8n-nodes-base.code",
      "position": [
        2912,
        1520
      ],
      "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": "3cbc0ec7-d4dd-4e47-82f2-2cfcf68eae56",
      "name": "Create smenso Task",
      "type": "n8n-nodes-smenso.smenso",
      "position": [
        3168,
        1520
      ],
      "parameters": {
        "title": "={{ $json.title }}",
        "resource": "task",
        "operation": "create",
        "projectId": "={{ $json.projectId }}",
        "additionalFields": {
          "description": "={{ $json.description }}"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9f2a8e7b-1d51-486c-9189-ed30010c28c7",
      "name": "Send Confirmation Reply",
      "type": "n8n-nodes-base.gmail",
      "position": [
        3440,
        1520
      ],
      "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": "d4a04f88-89f8-460f-afc5-0f9aa41fd1b4",
      "name": "Mark as Read",
      "type": "n8n-nodes-base.gmail",
      "position": [
        3696,
        1520
      ],
      "parameters": {
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "operation": "markAsRead"
      },
      "typeVersion": 2.1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "1928b1ce-27ba-44bf-9664-071f01c5e1a7",
  "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
          }
        ]
      ]
    }
  }
}