{
  "name": "【共通】エラー通知（失敗したら知らせる）",
  "nodes": [
    {
      "parameters": {},
      "name": "ワークフローが失敗したとき",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "id": "e1"
    },
    {
      "parameters": {
        "jsCode": "// 失敗したワークフローの情報を、通知の文面にする\nconst d = $input.first().json;\nconst when = $now.setZone('Asia/Tokyo').toFormat('yyyy/MM/dd HH:mm');\nconst text = [\n  `⚠ n8nのワークフローが止まりました（${when}）`,\n  `ワークフロー：${d.workflow?.name ?? '不明'}`,\n  `止まった処理：${d.execution?.lastNodeExecuted ?? d.trigger?.error?.node?.name ?? '不明'}`,\n  `エラー内容：${d.execution?.error?.message ?? d.trigger?.error?.message ?? '不明'}`,\n  d.execution?.url ? `実行の記録：${d.execution.url}` : '（トリガーで止まったため、実行の記録はありません）',\n].join('\\n');\nreturn [{ json: { text } }];"
      },
      "name": "通知の文面を作る",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        200,
        0
      ],
      "id": "e2"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXX",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: $json.text }) }}",
        "options": {}
      },
      "name": "Slackに知らせる",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        400,
        0
      ],
      "id": "e3"
    }
  ],
  "connections": {
    "ワークフローが失敗したとき": {
      "main": [
        [
          {
            "node": "通知の文面を作る",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "通知の文面を作る": {
      "main": [
        [
          {
            "node": "Slackに知らせる",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}