{
  "name": "ControlLaunchPad - Signed Offer Ready stage to Slack (starter)",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "content": "## Setup\nSet CLP_WEBHOOK_SECRET in private n8n Variables. Variables are readable by users with access to them: restrict your workspace, and never share a configured export containing secrets. n8n Cloud includes crypto; self-hosted instances must allow it with NODE_FUNCTION_ALLOW_BUILTIN=crypto. Keep Raw Body enabled. Activate/publish and subscribe the production webhook in CLP. Signed test events validate and stop before output. Wrong, missing or stale signatures must fail. Use one lead you control for the final output test. Retries can repeat outputs; add durable event-ID deduplication if one output per event is required. Provider import/runtime is not verified by offline checks. Set CLP_OFFER_READY_STAGE_ID to the intended stage ID, replace the Slack URL placeholder, and subscribe only to lead.stage_changed. Stage names are not used for matching.",
        "height": 370,
        "width": 820
      },
      "id": "setup-notes",
      "name": "Setup notes",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        200,
        0
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "clp-offer-ready",
        "responseMode": "lastNode",
        "options": {
          "rawBody": true
        }
      },
      "id": "clp-event",
      "name": "CLP event",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        460
      ],
      "webhookId": "clp-offer-ready"
    },
    {
      "parameters": {
        "jsCode": "const crypto = require('crypto');\nconst input = $input.first();\nconst headers = input.json.headers || {};\nconst secret = $vars.CLP_WEBHOOK_SECRET;\nif (typeof secret !== 'string' || secret.length < 16 || secret === 'CLP_WEBHOOK_SECRET') throw new Error('Configure the private CLP_WEBHOOK_SECRET variable.');\nconst timestamp = String(headers['x-clp-timestamp'] || '');\nconst signature = String(headers['x-clp-signature'] || '');\nif (!/^\\d{10,11}$/.test(timestamp) || !/^sha256=[a-f0-9]{64}$/.test(signature)) throw new Error('Missing or malformed CLP signature.');\nif (!input.binary?.data) throw new Error('Keep Raw Body enabled on the Webhook node.');\nconst raw = await this.helpers.getBinaryDataBuffer(0, 'data');\nconst expected = 'sha256=' + crypto.createHmac('sha256', secret).update(timestamp + '.').update(raw).digest('hex');\nif (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300 || !crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) throw new Error('CLP signature or timestamp could not be verified.');\nconst event = JSON.parse(raw.toString('utf8'));\nif (event.object !== 'event' || event.version !== 1 || typeof event.id !== 'string' || !event.id || typeof event.type !== 'string' || typeof event.test !== 'boolean') throw new Error('Unexpected CLP event format.');\nif (event.test) return [];\nif (event.type !== 'lead.stage_changed') return [];\nconst stageId = $vars.CLP_OFFER_READY_STAGE_ID;\nif (typeof stageId !== 'string' || !stageId.trim() || stageId.startsWith('REPLACE_')) throw new Error('Set CLP_OFFER_READY_STAGE_ID to your exact target stage ID.');\nif (event.data?.to?.id !== stageId) return [];\nif (event.data?.object?.object !== 'lead' || typeof event.data.object.id !== 'string') throw new Error('Missing lead record.');\nreturn [{json:{eventId:event.id,eventType:event.type,occurredAt:event.occurredAt,leadId:event.data.object.id}}];"
      },
      "id": "verify",
      "name": "Verify and route CLP event",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        460
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://hooks.slack.com/services/REPLACE_WITH_SLACK_WEBHOOK",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: 'ControlLaunchPad: lead entered the configured offer stage. Event ' + $json.eventId + ' | ' + $json.occurredAt }) }}",
        "options": {
          "timeout": 10000
        }
      },
      "id": "slack-notice",
      "name": "Notify Slack",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        800,
        460
      ]
    }
  ],
  "connections": {
    "CLP event": {
      "main": [
        [
          {
            "node": "Verify and route CLP event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify and route CLP event": {
      "main": [
        [
          {
            "node": "Notify Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "tags": []
}
