{
  "id": "JQP0dkQCszkc3cZy",
  "meta": {
    "instanceId": "15d6057a37b8367f33882dd60593ee5f6cc0c59310ff1dc66b626d726083b48d",
    "templateCredsSetupCompleted": true
  },
  "name": "AI Team Morale Monitor",
  "tags": [],
  "nodes": [
    {
      "id": "bb8d11dc-5c7c-4e27-8090-8670682ecf9d",
      "name": "Split In Batches",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -864,
        208
      ],
      "parameters": {
        "options": {},
        "batchSize": 5
      },
      "typeVersion": 1
    },
    {
      "id": "dea3c66c-a383-4092-afb5-e8e1bbe13ffb",
      "name": "Fetch Teams Messages (Simulated)1",
      "type": "n8n-nodes-base.code",
      "position": [
        -1088,
        208
      ],
      "parameters": {
        "jsCode": "\n// Placeholder: Fetch messages from Microsoft Graph API\nconst config = $input.item.json;\nreturn [{\n  json: {\n    messages: [\n      { text: \"今週はタスク多くて疲れたけど、みんな頑張ってる！\", author: \"Aさん\", createdDateTime: new Date().toISOString() },\n      { text: \"進捗良い感じ。あと少しで完了！\", author: \"Bさん\", createdDateTime: new Date().toISOString() },\n      { text: \"少しモチベ下がってるかも…\", author: \"Cさん\", createdDateTime: new Date().toISOString() }\n    ]\n  }\n}];\n                "
      },
      "typeVersion": 2
    },
    {
      "id": "a03c52e8-e4dd-4b7f-b6cf-398d6352fb0e",
      "name": "Log Progress1",
      "type": "n8n-nodes-base.code",
      "position": [
        -416,
        208
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "console.log('Batch processed'); return item;"
      },
      "typeVersion": 2
    },
    {
      "id": "8dec94bd-20e3-44b1-aacc-e7e2cd5da5cd",
      "name": "Weekly Morale Check Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1536,
        208
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3d6d4f1a-51d2-4bdb-b12f-d14515a86780",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -1312,
        208
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "teamId",
              "type": "string",
              "value": "<YOUR_TEAM_ID>"
            },
            {
              "id": "id-2",
              "name": "channelId",
              "type": "string",
              "value": "<YOUR_CHANNEL_ID>"
            },
            {
              "id": "id-3",
              "name": "managerUserId",
              "type": "string",
              "value": "<MANAGER_USER_ID>"
            },
            {
              "id": "id-4",
              "name": "daysToAnalyze",
              "type": "number",
              "value": 7
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a4d77258-1178-4365-ad86-70448907299e",
      "name": "Aggregate Sentiment Scores",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -192,
        208
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "163118d1-9387-4678-a2d3-662d3ec34688",
      "name": "Calculate Weekly Statistics",
      "type": "n8n-nodes-base.code",
      "position": [
        48,
        208
      ],
      "parameters": {
        "jsCode": "\nconst items = $input.all();\nconst avgSentiment = (items.reduce((a,b)=>a+b.json.sentiment,0)/items.length).toFixed(2);\nconst avgStress = (items.reduce((a,b)=>a+b.json.stress,0)/items.length).toFixed(2);\nreturn [{ json: { avgSentiment, avgStress, messageCount: items.length } }];\n                "
      },
      "typeVersion": 2
    },
    {
      "id": "e061e16e-70b9-4852-86b4-e4080b3d16da",
      "name": "Generate Morale Report (OpenAI)1",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        272,
        208
      ],
      "parameters": {
        "text": "=あなたは、わずかな情報からでも深い洞察を引き出すことができる、超一流の組織行動分析コンサルタントです。\nあなたの仕事は、以下の個々のメッセージ分析結果だけを頼りに、チームで観測された事実と、そこから導き出される潜在的な兆候をマネージャーに報告することです。\n\n**## 分析レポート**\n\n### **1. 観測されたコミュニケーション**\nまず、分析対象となった個々のメッセージの内容を引用または要約し、客観的な事実としてリストアップしてください。\n\n### **2. 読み取れる兆候（インサイト）**\n次に、上記のコミュニケーションから読み取れるチームや個人の心理状態、関係性、業務への姿勢について、あなたの専門的な知見を基に、具体的かつ深く考察してください。\n- ポジティブな兆候は何か？\n- 注意すべき潜在的なリスクや懸念事項は何か？\n- この一行のメッセージの裏には、どのような背景や文脈が隠されている可能性があるか？\n\n**【重要】**\n- 平均値やメッセージの「数」については一切言及しないでください。\n- あなたの分析は、提供されたメッセージの「内容（テキスト）」そのものに100%基づく必要があります。\n- 「データが少ない」という言い訳は絶対にせず、プロとして目の前の情報から最大限の価値を引き出してください。\n\n---\n**▼分析対象データ**\n{{ JSON.stringify($('Aggregate Sentiment Scores').all()) }}\n---\n\n上記のルールに従い、コンサルタントとして価値のあるレポートを作成してください。",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "resource": "document"
      },
      "typeVersion": 1
    },
    {
      "id": "bc331851-dd10-4c94-affc-ce0bb5a8cc58",
      "name": "Sentiment Analysis (OpenAI)1",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        -640,
        208
      ],
      "parameters": {
        "text": "あなたは心理言語分析AIです。以下のTeamsメッセージの感情トーンを分析し、構造化JSONで出力してください。\n\nメッセージ: {{ $json.text }}\n投稿者: {{ $json.author }}\n時間帯: {{ $json.timeOfDay }}\n曜日: {{ $json.dayOfWeek }}\n\n以下の形式で出力してください:\n{\n  \"sentiment\": <1-5の数値。1=非常にネガティブ、3=中立、5=非常にポジティブ>,\n  \"emotion\": \"<主な感情: 喜び/不安/怒り/疲労/中立など>\",\n  \"stress\": <ストレス指標: 0-10>,\n  \"engagement\": <エンゲージメント: 0-10>,\n  \"key_phrases\": [\"<重要なフレーズ1>\", \"<重要なフレーズ2>\"],\n  \"concerns\": \"<懸念事項があれば記載、なければ空文字>\",\n  \"message\": \"{{ $json.text }}\"\n}",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "resource": "document"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "credential-id",
          "name": "googlePalmApi Credential"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a4807793-b036-469d-a4c2-f873e0b84f72",
      "name": "Send a message1",
      "type": "n8n-nodes-base.slack",
      "position": [
        496,
        208
      ],
      "webhookId": "b3d83199-274b-41d8-8f45-b485bfba418f",
      "parameters": {
        "text": "={{ $json.content.parts[0].text }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09LUABPRGT",
          "cachedResultName": "ソーシャル"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "typeVersion": 2.3
    },
    {
      "id": "7aa489e4-f487-4334-bd6c-4e54961b2995",
      "name": "Template Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2160,
        -48
      ],
      "parameters": {
        "width": 528,
        "height": 752,
        "content": "## AI Team Morale Monitor\n\n### Who’s it for\nFor team leads, HR, and managers who want to monitor the emotional tone and morale of their teams based on message sentiment.\n\n### How it works\n1. **Trigger:** Runs every Monday at 9 AM.\n2. **Config:** Defines your Teams and Slack channels.\n3. **Fetch:** Gathers messages for the week.\n4. **AI Analysis:** Evaluates tone and stress levels.\n5. **Aggregate:** Computes team sentiment averages.\n6. **Report:** Creates a readable morale summary.\n7. **Slack Post:** Sends report to your workspace.\n\n### How to set up\n1. Connect Microsoft Teams and Slack credentials.\n2. Enter your Team and Channel IDs in the **Workflow Configuration** node.\n3. Adjust the schedule if desired.\n\n### Requirements\n- Microsoft Teams and Slack access.\n- Gemini (or OpenAI) API credentials set in AI nodes.\n\n### How to customize\n- Modify the AI prompts for different insight depth.\n- Replace Gemini with other LLMs if preferred.\n- Change posting platform or format.\n\n**Note:** This workflow uses *only* linguistic data — no personal identifiers or private metadata."
      },
      "typeVersion": 1
    },
    {
      "id": "aa1e99df-6667-42b0-8e5f-a16a95ebb704",
      "name": "Trigger Description",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1616,
        16
      ],
      "parameters": {
        "height": 352,
        "content": "### Weekly Trigger\nActivates automatically every Monday at 9:00 AM.\nYou can change this schedule in the node settings."
      },
      "typeVersion": 1
    },
    {
      "id": "0a1e5f36-4395-48d5-ac3a-e1434e7b4f54",
      "name": "Configuration Description",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1376,
        16
      ],
      "parameters": {
        "width": 208,
        "height": 352,
        "content": "### Workflow Configuration\nDefines IDs and settings such as:\n- Team ID\n- Channel ID\n- Manager User ID\n- Analysis Period (days)"
      },
      "typeVersion": 1
    },
    {
      "id": "9e301552-4f9f-4326-bb03-94b5ffbd6512",
      "name": "Fetch Messages Description",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1168,
        16
      ],
      "parameters": {
        "width": 464,
        "height": 352,
        "content": "### Fetch Messages\nCollects recent Microsoft Teams messages.\nReplace this with a real API node for live data."
      },
      "typeVersion": 1
    },
    {
      "id": "4346e576-a225-434e-a1fc-20c47c94fa25",
      "name": "AI Analysis Description",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -704,
        16
      ],
      "parameters": {
        "width": 464,
        "height": 352,
        "content": "### Sentiment Analysis\nUses Gemini or OpenAI to assess sentiment, stress, and engagement per message."
      },
      "typeVersion": 1
    },
    {
      "id": "0b81f776-097d-472b-9bf5-2ea5bc84b5d9",
      "name": "Aggregate Description",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        16
      ],
      "parameters": {
        "width": 448,
        "height": 352,
        "content": "### Aggregate Statistics\nCalculates weekly averages of sentiment and stress indicators."
      },
      "typeVersion": 1
    },
    {
      "id": "fc2bd727-c235-4843-88b7-7eb17179aa4e",
      "name": "Report Description",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        16
      ],
      "parameters": {
        "height": 352,
        "content": "### Generate Report\nSummarizes emotional insights into a readable report for managers."
      },
      "typeVersion": 1
    },
    {
      "id": "21427b2f-e985-4977-8422-642a4902a2a0",
      "name": "Slack Description",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        448,
        16
      ],
      "parameters": {
        "width": 208,
        "height": 352,
        "content": "### Post to Slack\nPublishes the morale report to Slack or Teams for visibility."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d5d88f18-04b2-48a3-be88-4158141b1ea5",
  "connections": {
    "Log Progress1": {
      "main": [
        [
          {
            "node": "Aggregate Sentiment Scores",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split In Batches": {
      "main": [
        [
          {
            "node": "Sentiment Analysis (OpenAI)1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Fetch Teams Messages (Simulated)1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Sentiment Scores": {
      "main": [
        [
          {
            "node": "Calculate Weekly Statistics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Weekly Statistics": {
      "main": [
        [
          {
            "node": "Generate Morale Report (OpenAI)1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly Morale Check Trigger": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sentiment Analysis (OpenAI)1": {
      "main": [
        [
          {
            "node": "Log Progress1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Morale Report (OpenAI)1": {
      "main": [
        [
          {
            "node": "Send a message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Teams Messages (Simulated)1": {
      "main": [
        [
          {
            "node": "Split In Batches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}