{
  "name": "QuietDiff Webhook & Polling",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "quietdiff-webhook",
        "responseMode": "onReceived",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [240, 300],
      "webhookId": "quietdiff-change-alert"
    },
    {
      "parameters": {
        "content": "=**{{ $json.alert.subject }}**\n\n{{ $json.alert.message }}\n\n{% if $json.change %}\n**Monitor:** {{ $json.change.monitor.name }}\n**URL:** {{ $json.change.monitor.url }}\n**Field:** {{ $json.change.field }}\n**Old Value:** {{ $json.change.oldValue || 'None' }}\n**New Value:** {{ $json.change.newValue }}\n**Summary:** {{ $json.change.summary }}\n{% endif %}\n\n*Detected at {{ $json.alert.createdAt }}*",
        "channel": "#your-channel",
        "username": "QuietDiff",
        "iconEmoji": ":bell:"
      },
      "name": "Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 1,
      "position": [460, 300],
      "credentials": {
        "slackApi": {
          "id": "1",
          "name": "Slack Incoming Webhook"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "name": "Schedule (Daily 9am)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [240, 500]
    },
    {
      "parameters": {
        "url": "https://quietdiff.com/api/v1/changes",
        "authentication": "headerAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "limit",
              "value": "50"
            },
            {
              "name": "since",
              "value": "={{ $now.minus({ days: 1 }).toISO() }}"
            }
          ]
        },
        "options": {}
      },
      "name": "Get Recent Changes",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [460, 500],
      "credentials": {
        "httpHeaderAuth": {
          "id": "2",
          "name": "QuietDiff API Key"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.changes.length }}",
              "operation": "larger",
              "value2": 0
            }
          ]
        }
      },
      "name": "Has Changes?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [680, 500]
    },
    {
      "parameters": {
        "functionCode": "const changes = $input.item.json.changes || [];\nconst summary = changes.map(c => `• **${c.monitor.name}**: ${c.summary}`).join('\\n');\n\nreturn {\n  json: {\n    text: `**QuietDiff Daily Digest**\\n\\nDetected ${changes.length} change${changes.length === 1 ? '' : 's'} in the last 24 hours:\\n\\n${summary}`\n  }\n};"
      },
      "name": "Format Digest",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [900, 500]
    },
    {
      "parameters": {
        "content": "={{ $json.text }}",
        "channel": "#your-channel",
        "username": "QuietDiff Daily",
        "iconEmoji": ":newspaper:"
      },
      "name": "Post Digest to Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 1,
      "position": [1120, 500],
      "credentials": {
        "slackApi": {
          "id": "1",
          "name": "Slack Incoming Webhook"
        }
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule (Daily 9am)": {
      "main": [
        [
          {
            "node": "Get Recent Changes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Recent Changes": {
      "main": [
        [
          {
            "node": "Has Changes?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Changes?": {
      "main": [
        [
          {
            "node": "Format Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Digest": {
      "main": [
        [
          {
            "node": "Post Digest to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {},
  "tags": []
}
