{
  "name": "Smart Project Management with AI",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "new-task-request",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "pm1a2b3c-1111-2222-3333-444455556666",
      "name": "Task Request Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4",
          "mode": "id"
        },
        "messages": {
          "values": [
            {
              "content": "=Parse this raw task request and structure it:\n\nRaw Request: {{ $json.request_text }}\nRequested By: {{ $json.requester }}\n\nReturn JSON with:\n- title (string, max 10 words)\n- description (string, clear and concise)\n- priority (low/medium/high/critical)\n- estimated_hours (number)\n- required_skills (array of strings)\n- task_type (bug/feature/documentation/meeting)\n\nReturn only valid JSON."
            }
          ]
        },
        "options": {
          "temperature": 0.3
        }
      },
      "id": "pm2b3c4d-2222-3333-4444-555566667777",
      "name": "AI Task Parser",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.3,
      "position": [
        480,
        300
      ]
    },
    {
      "parameters": {
        "operation": "getAll",
        "documentId": {
          "__rl": true,
          "value": "YOUR_GOOGLE_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "TeamMembers",
          "mode": "name"
        },
        "options": {}
      },
      "id": "pm3c4d5e-3333-4444-5555-666677778888",
      "name": "Fetch Team Workload",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        710,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Smart Resource Allocation Logic\nconst parsedTask = JSON.parse($('AI Task Parser').first().json.message.content);\nconst teamMembers = $('Fetch Team Workload').all().map(item => item.json);\n\n// Filter by required skills (simplified matching)\nlet eligibleMembers = teamMembers.filter(member => {\n  const memberSkills = member.skills.toLowerCase().split(',').map(s => s.trim());\n  return parsedTask.required_skills.some(skill => \n    memberSkills.includes(skill.toLowerCase())\n  );\n});\n\n// If no exact skill match, use all members\nif (eligibleMembers.length === 0) {\n  eligibleMembers = teamMembers;\n}\n\n// Find member with lowest current workload\nlet bestMember = eligibleMembers.reduce((prev, current) => {\n  return (prev.current_hours < current.current_hours) ? prev : current;\n});\n\n// Calculate new workload\nconst newWorkload = parseFloat(bestMember.current_hours) + parsedTask.estimated_hours;\n\nreturn [{\n  json: {\n    task_id: 'TASK-' + Date.now(),\n    title: parsedTask.title,\n    description: parsedTask.description,\n    priority: parsedTask.priority,\n    estimated_hours: parsedTask.estimated_hours,\n    required_skills: parsedTask.required_skills.join(', '),\n    task_type: parsedTask.task_type,\n    assigned_to: bestMember.name,\n    assigned_email: bestMember.email,\n    assigned_slack_id: bestMember.slack_id,\n    previous_workload: bestMember.current_hours,\n    new_workload: newWorkload,\n    status: 'To Do',\n    created_by: $('Task Request Webhook').first().json.requester,\n    created_at: $now.toISO(),\n    deadline: $now.plus({days: parsedTask.priority === 'critical' ? 1 : parsedTask.priority === 'high' ? 3 : 7}).toISO()\n  }\n}];"
      },
      "id": "pm4d5e6f-4444-5555-6666-777788889999",
      "name": "Smart Assignment Logic",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        940,
        300
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "YOUR_GOOGLE_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Tasks",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "task_id": "={{ $json.task_id }}",
            "title": "={{ $json.title }}",
            "description": "={{ $json.description }}",
            "priority": "={{ $json.priority }}",
            "estimated_hours": "={{ $json.estimated_hours }}",
            "assigned_to": "={{ $json.assigned_to }}",
            "status": "={{ $json.status }}",
            "created_at": "={{ $json.created_at }}",
            "deadline": "={{ $json.deadline }}"
          },
          "schema": []
        },
        "options": {}
      },
      "id": "pm5e6f7a-5555-6666-7777-888899990000",
      "name": "Save Task to DB",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        1170,
        300
      ]
    },
    {
      "parameters": {
        "channel": "=#project-updates",
        "text": "=\ud83d\udccc New Task Assigned!\n\n\ud83c\udd94 Task ID: {{ $json.task_id }}\n\ud83d\udcdd Title: {{ $json.title }}\n Assigned to: {{ $json.assigned_to }}\n\u23f1\ufe0f Estimated: {{ $json.estimated_hours }} hours\n\ufe0f Priority: {{ $json.priority }}\n\ud83d\udcc5 Deadline: {{ new Date($json.deadline).toLocaleDateString('fa-IR') }}\n\nPlease check your dashboard for details.",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "id": "pm6f7a8b-6666-7777-8888-999900001111",
      "name": "Notify Team on Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.1,
      "position": [
        1400,
        300
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 17 * * 1-5"
            }
          ]
        }
      },
      "id": "pm7a8b9c-7777-8888-9999-000011112222",
      "name": "Daily Report Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        250,
        600
      ]
    },
    {
      "parameters": {
        "operation": "getAll",
        "documentId": {
          "__rl": true,
          "value": "YOUR_GOOGLE_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Tasks",
          "mode": "name"
        },
        "options": {}
      },
      "id": "pm8b9c0d-8888-9999-0000-111122223333",
      "name": "Fetch All Tasks",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        480,
        600
      ]
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4",
          "mode": "id"
        },
        "messages": {
          "values": [
            {
              "content": "=Analyze this project task data for a daily management report:\n\nTasks Data: {{ JSON.stringify($input.first().json) }}\n\nProvide a JSON response with:\n- total_tasks (number)\n- completed_today (number)\n- at_risk_tasks (array of task_ids that are close to deadline or high priority and not started)\n- team_velocity_score (1-10)\n- top_bottlenecks (array of 2-3 strings)\n- daily_summary (2-3 sentences)\n- manager_action_items (array of 3 actionable items for the project manager)\n\nReturn only valid JSON."
            }
          ]
        },
        "options": {
          "temperature": 0.4
        }
      },
      "id": "pm9c0d1e-9999-0000-1111-222233334444",
      "name": "AI Risk & Progress Analysis",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.3,
      "position": [
        710,
        600
      ]
    },
    {
      "parameters": {
        "fromEmail": "pm-bot@yourcompany.com",
        "toEmail": "project-manager@yourcompany.com",
        "subject": "=Daily Project Health Report - {{ $now.toFormat('yyyy-MM-dd') }}",
        "emailType": "text",
        "message": "=Dear Project Manager,\n\nHere is your daily project health report:\n\n\ud83d\udcca OVERVIEW:\n- Total Active Tasks: {{ JSON.parse($('AI Risk & Progress Analysis').first().json.message.content).total_tasks }}\n- Completed Today: {{ JSON.parse($('AI Risk & Progress Analysis').first().json.message.content).completed_today }}\n- Team Velocity Score: {{ JSON.parse($('AI Risk & Progress Analysis').first().json.message.content).team_velocity_score }}/10\n\n\ud83d\udcdd DAILY SUMMARY:\n{{ JSON.parse($('AI Risk & Progress Analysis').first().json.message.content).daily_summary }}\n\n AT-RISK TASKS:\n{{ JSON.parse($('AI Risk & Progress Analysis').first().json.message.content).at_risk_tasks.join(', ') || 'None' }}\n\n\ud83d\udd0d TOP BOTTLENECKS:\n{{ JSON.parse($('AI Risk & Progress Analysis').first().json.message.content).top_bottlenecks.join('\\n- ') }}\n\n\u2705 ACTION ITEMS FOR YOU:\n{{ JSON.parse($('AI Risk & Progress Analysis').first().json.message.content).manager_action_items.map((item, i) => `${i+1}. ${item}`).join('\\n') }}\n\nBest regards,\nSmart Project Management System",
        "options": {}
      },
      "id": "pm0d1e2f-0000-1111-2222-333344445555",
      "name": "Send Daily Report Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2,
      "position": [
        940,
        600
      ]
    }
  ],
  "connections": {
    "Task Request Webhook": {
      "main": [
        [
          {
            "node": "AI Task Parser",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Task Parser": {
      "main": [
        [
          {
            "node": "Fetch Team Workload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Team Workload": {
      "main": [
        [
          {
            "node": "Smart Assignment Logic",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Smart Assignment Logic": {
      "main": [
        [
          {
            "node": "Save Task to DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Task to DB": {
      "main": [
        [
          {
            "node": "Notify Team on Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Report Schedule": {
      "main": [
        [
          {
            "node": "Fetch All Tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch All Tasks": {
      "main": [
        [
          {
            "node": "AI Risk & Progress Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Risk & Progress Analysis": {
      "main": [
        [
          {
            "node": "Send Daily Report Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}