{
  "name": "Coolie: new lead → Slack",
  "nodes": [
    {
      "parameters": {
        "content": "## Coolie: post every new lead to Slack\n\nEach lead a Coolie agent finds arrives here as a **lead.created** webhook and is posted to a Slack channel: the company, the buying signal, the contact and their email, the AI score.\n\n### How it works\n1. **Coolie webhook** receives the event, raw body kept.\n2. **Verify Coolie signature** checks the `Coolie-Signature` header with your webhook's secret and stops anything else.\n3. **New leads only** lets `lead.created` events through, and Coolie's test event.\n4. **Post to Slack** sends the message.\n\n### Setup\n1. In **Post to Slack**, connect Slack and pick the channel.\n2. Copy the **Production URL** of **Coolie webhook**.\n3. In Coolie: **Settings → Webhooks**, paste the URL, tick **New lead**, click **Add webhook**, then **Reveal** the secret.\n4. Paste the secret at the top of **Verify Coolie signature**.\n5. Save and publish the workflow (on n8n before 2.0, activate it).\n6. Click **Send test** in Coolie: a sample lead appears in Slack.\n\nSelf-hosted n8n: allow the crypto module (`NODE_FUNCTION_ALLOW_BUILTIN=crypto`, on the task runners when you use them).\nGuide: https://trycoolie.ai/developers/templates/new-lead-to-slack",
        "height": 680,
        "width": 480
      },
      "id": "43277fe8-f0e4-4463-8be6-98831b532423",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        -280
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "coolie-new-lead-slack",
        "responseMode": "onReceived",
        "options": {
          "rawBody": true
        }
      },
      "id": "def7181d-f424-4875-82d9-88170030a0c1",
      "name": "Coolie webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "8b74fdd9-09a6-440c-8af8-f78ffec1563c"
    },
    {
      "parameters": {
        "jsCode": "// Coolie signs every event: Coolie-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of \"t.body\">.\n// This node recomputes it on the raw body with your webhook's secret, and stops anything else.\n// Paste the secret below: Coolie > Settings > Webhooks > Reveal (it starts with whsec_).\nconst SECRET = 'PASTE_YOUR_COOLIE_WEBHOOK_SECRET';\n\nconst crypto = require('crypto');\nif (!SECRET.startsWith('whsec_')) {\n  throw new Error('Paste your Coolie webhook secret (whsec_...) in the Verify Coolie signature node.');\n}\nconst request = $input.first().json;\nconst rawBody = (await this.helpers.getBinaryDataBuffer(0, 'data')).toString('utf8');\nconst parts = Object.fromEntries(\n  String(request.headers['coolie-signature'] || '').split(',').map((part) => part.split('=')),\n);\nconst expected = Buffer.from(crypto.createHmac('sha256', SECRET).update(parts.t + '.' + rawBody).digest('hex'));\nconst given = Buffer.from(String(parts.v1 || ''));\nconst fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;\nif (!fresh || given.length !== expected.length || !crypto.timingSafeEqual(given, expected)) {\n  throw new Error('Not a Coolie event: the signature does not match.');\n}\nreturn [{ json: JSON.parse(rawBody), pairedItem: { item: 0 } }];"
      },
      "id": "f27ed160-209c-48d1-8bbe-ed712357b9b4",
      "name": "Verify Coolie signature",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "65702f04-93d5-4a7b-8494-7ab25aa2756d",
              "leftValue": "={{ $json.type }}",
              "rightValue": "lead.created",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "0bcf2c7f-2a19-4703-8616-112d740929ff",
              "leftValue": "={{ $json.type }}",
              "rightValue": "test",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "id": "3af36dda-7d95-4ca6-8b62-2a5aa6d8db9a",
      "name": "New leads only",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        480,
        0
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "text": "=:sparkles: *New lead{{ $json.type === 'test' ? ' (test event)' : '' }}: {{ $json.data.lead.company.name }}*{{ $json.data.lead.company.domain ? ' · ' + $json.data.lead.company.domain : '' }}\n*{{ $json.data.lead.signal.name }}*{{ $json.data.lead.signal.headline ? ': ' + $json.data.lead.signal.headline : '' }}{{ $json.data.lead.signal.postedAt ? ' (' + $json.data.lead.signal.postedAt + ')' : '' }}\nContact: {{ $json.data.lead.contact ? $json.data.lead.contact.name + ($json.data.lead.contact.title ? ', ' + $json.data.lead.contact.title : '') : 'none found yet' }}\nEmail: {{ $json.data.lead.contact && $json.data.lead.contact.email ? $json.data.lead.contact.email : 'not found yet' }}\nAI score: {{ $json.data.lead.aiScore }}/10{{ $json.data.lead.signal.url ? ' · ' + $json.data.lead.signal.url : '' }}",
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "id": "62b1f7a6-1955-481d-88f3-f47a5a968642",
      "name": "Post to Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        720,
        0
      ]
    }
  ],
  "connections": {
    "Coolie webhook": {
      "main": [
        [
          {
            "node": "Verify Coolie signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify Coolie signature": {
      "main": [
        [
          {
            "node": "New leads only",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New leads only": {
      "main": [
        [
          {
            "node": "Post to Slack",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  }
}
