{
  "name": "週次レポート自動配信テンプレート（Slack/Teams/メール対応）",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "weeksInterval": 1,
              "triggerAtDay": [1],
              "triggerAtHour": 9,
              "triggerAtMinute": 0
            }
          ]
        }
      },
      "id": "a1b2c3d4-0001-4abc-8def-000000000001",
      "name": "Schedule Trigger（毎週月曜9:00）",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [240, 300],
      "notes": "毎週月曜 09:00 に起動します。\n曜日・時刻は Parameters → Trigger Rules で変更してください。\n例: triggerAtDay: [5] → 金曜日"
    },
    {
      "parameters": {
        "jsCode": "// ===================================================\n// 週次レポート本文を生成するサンプルコード\n// ---------------------------------------------------\n// ここを実際のデータ取得処理に書き換えてください。\n// 例: HTTP Requestで社内APIを叩く、Googleスプレッドシートを読む、など。\n// ===================================================\n\nconst today = new Date();\nconst dateStr = today.toLocaleDateString('ja-JP', {\n  year: 'numeric', month: 'long', day: 'numeric'\n});\n\n// --- サンプルデータ（実際はAPIやDBから取得してください） ---\nconst weeklyData = {\n  title: `週次レポート（${dateStr}）`,\n  summary: 'この週のハイライトをここに記載します。',\n  items: [\n    { label: '完了タスク', value: '12件' },\n    { label: '未対応問い合わせ', value: '3件' },\n    { label: 'システム稼働率', value: '99.8%' }\n  ],\n  footer: 'IroHive n8n テンプレート — n8n-weekly-report-v1'\n};\n\n// --- Slack用メッセージ（Block Kit形式） ---\n// ※ Slack以外を使う場合は後続ノードを切り替えてください\nconst slackPayload = {\n  text: weeklyData.title,\n  blocks: [\n    {\n      type: 'header',\n      text: { type: 'plain_text', text: weeklyData.title, emoji: true }\n    },\n    {\n      type: 'section',\n      text: { type: 'mrkdwn', text: weeklyData.summary }\n    },\n    { type: 'divider' },\n    ...weeklyData.items.map(item => ({\n      type: 'section',\n      fields: [\n        { type: 'mrkdwn', text: `*${item.label}*` },\n        { type: 'mrkdwn', text: item.value }\n      ]\n    })),\n    { type: 'divider' },\n    {\n      type: 'context',\n      elements: [{ type: 'mrkdwn', text: weeklyData.footer }]\n    }\n  ]\n};\n\n// --- Teams Workflow用メッセージ（Adaptive Card形式）---\n// Teams経由で配信する場合は、下記を HTTP Request ノードのBodyにセットしてください\n// Power Automate Workflows 側で \"When a Teams Webhook request is received\" を使ってください\nconst teamsPayload = {\n  title: weeklyData.title,\n  summary: weeklyData.summary,\n  items: weeklyData.items\n};\n\n// --- メール用テキスト（SMTP/Gmail ノード向け） ---\nconst emailBody = [\n  weeklyData.title,\n  '='.repeat(40),\n  weeklyData.summary,\n  '',\n  ...weeklyData.items.map(i => `・${i.label}: ${i.value}`),\n  '',\n  weeklyData.footer\n].join('\\n');\n\nreturn [{\n  json: {\n    weeklyData,\n    slackPayload,\n    teamsPayload,\n    emailSubject: weeklyData.title,\n    emailBody\n  }\n}];"
      },
      "id": "a1b2c3d4-0002-4abc-8def-000000000002",
      "name": "レポート本文を生成（要カスタマイズ）",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [480, 300],
      "notes": "このCodeノードがレポート本文を生成します。\nslackPayload / teamsPayload / emailBody の3形式を出力します。\n実際のデータは HTTP Request などで取得してください。"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://hooks.slack.com/services/T000/B000/XXXX",
        "sendBody": true,
        "contentType": "json",
        "body": {
          "specifyBody": "json",
          "jsonBody": "={{ JSON.stringify($json.slackPayload) }}"
        },
        "options": {
          "timeout": 10000
        }
      },
      "id": "a1b2c3d4-0003-4abc-8def-000000000003",
      "name": "Slack へ送信（Incoming Webhook）",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [720, 200],
      "notes": "【Slack送信ノード】\nURL に Slack Incoming Webhook URL を設定してください。\n取得方法: api.slack.com/apps → OAuth & Permissions → Incoming Webhooks → Add New Webhook\n必要スコープ: chat:write（incoming-webhook でも可）\n\nSlack OAuth App（Bot Token）を使う場合は、\nこのノードを Slack ノード（Send Message）に切り替えて\nBot User OAuth Token（xoxb-...）を Credentials に設定してください。"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://prod-XX.westus.logic.azure.com/workflows/XXXXX/triggers/manual/paths/invoke",
        "sendBody": true,
        "contentType": "json",
        "body": {
          "specifyBody": "json",
          "jsonBody": "={{ JSON.stringify($json.teamsPayload) }}"
        },
        "options": {
          "timeout": 10000
        }
      },
      "id": "a1b2c3d4-0004-4abc-8def-000000000004",
      "name": "Teams へ送信（Power Automate Workflows）",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [720, 340],
      "disabled": true,
      "notes": "【Teams送信ノード — デフォルト無効】\n使う場合は右クリック → Enable でオンにしてください。\n\n【前提条件】\n・M365 Business Basic 以上（追加ライセンス不要）\n・Power Automate Workflows で事前設定が必要\n\n【Teams側の設定手順】\n1. Teams でチャンネルを開く → 右上「...」→ Workflows\n2. 「Post to a chat when a webhook request is received」を選択\n3. フローを作成 → 生成された Webhook URL をこのノードの URL に貼り付け\n\n注: URL に logic.azure.com が含まれる 長いURL が正しいWebhook URLです。"
    },
    {
      "parameters": {
        "fromEmail": "your-sender@example.com",
        "toEmail": "report-recipients@example.com",
        "subject": "={{ $json.emailSubject }}",
        "text": "={{ $json.emailBody }}",
        "options": {}
      },
      "id": "a1b2c3d4-0005-4abc-8def-000000000005",
      "name": "メール送信（SMTP）",
      "type": "n8n-nodes-base.sendEmail",
      "typeVersion": 2.1,
      "position": [720, 480],
      "disabled": true,
      "notes": "【メール送信ノード — デフォルト無効】\nGmail / SMTP どちらでも動きます。\n\n【Gmail OAuth2 の設定手順】\n1. n8n Credentials → Gmail OAuth2 API を作成\n2. Google Cloud Console でプロジェクト作成 → Gmail API 有効化\n3. OAuth 2.0 クライアント ID を取得 → n8n にリダイレクトURLを登録\n\n【SMTP の設定手順】\n1. n8n Credentials → SMTP を作成\n2. Host / Port / User / Password を設定\n   例: Gmail SMTP の場合 smtp.gmail.com:587（TLS）\n   ※ Googleアカウントはアプリパスワードが必要（2段階認証設定後）"
    }
  ],
  "connections": {
    "Schedule Trigger（毎週月曜9:00）": {
      "main": [
        [
          { "node": "レポート本文を生成（要カスタマイズ）", "type": "main", "index": 0 }
        ]
      ]
    },
    "レポート本文を生成（要カスタマイズ）": {
      "main": [
        [
          { "node": "Slack へ送信（Incoming Webhook）", "type": "main", "index": 0 },
          { "node": "Teams へ送信（Power Automate Workflows）", "type": "main", "index": 0 },
          { "node": "メール送信（SMTP）", "type": "main", "index": 0 }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner",
    "errorWorkflow": ""
  },
  "staticData": null,
  "tags": [],
  "pinData": {},
  "meta": {
    "templateId": "irohive-n8n-weekly-report-v1",
    "templateCredsSetupCompleted": false,
    "instanceId": "irohive-template"
  },
  "notes": "irohive.com テンプレート | 詳細: https://irohive.com/blog/n8n-notification-channel-guide/\n配信先は Slack（有効）/ Teams（無効）/ メール（無効）の3つ。\n使う配信先のノードだけ Enable して、不要なノードは Disable のまま残してください。"
}
