{ "name": "Outlevo: Competitor change to Discord", "nodes": [ { "id": "60fedaeb-5ae0-4cb8-a4e2-e1b5b6847b81", "name": "How to set it up", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -40, -540 ], "parameters": { "content": "## How to set it up\n\n**Credentials** (n8n asks for each on first open):\n- **Outlevo webhook signing secret**: a Crypto credential; paste the `secret` Outlevo returns when you register the webhook (below) as its secret.\n- **Outlevo API key**: a Header Auth credential, name `Authorization`, value `Bearer olv_live_…` (Settings → API keys in Outlevo).\n- **Discord webhook**: connect your Discord webhook account.\n\n**API key scopes**: `companies:read`.\n\n**Register the webhook** (needs a key with `webhooks:manage`): copy the Production URL of the **Outlevo webhook** node, then:\n```\ncurl -X POST https://api.outlevo.com/v1/webhooks \\\n -H \"Authorization: Bearer $OUTLEVO_KEY\" \\\n -H \"Idempotency-Key: $(uuidgen)\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"url\": \"\", \"events\": [\"competitor.changed\"]}'\n```\nPut the `secret` from the answer into the Crypto credential.\n\nThen switch the workflow to **Active**.", "height": 480, "width": 620 } }, { "id": "c3bd7d5b-fb26-4e00-b36c-670b1d7ea37a", "name": "Outlevo webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 0, 0 ], "parameters": { "httpMethod": "POST", "path": "outlevo-competitor-change-to-discord", "responseMode": "onReceived", "options": { "rawBody": true } }, "webhookId": "2af1e98c-dc6b-48a5-be90-6684c00f35ee" }, { "id": "6f959f2b-d8f7-4062-9321-6bcfd599434a", "name": "Read the body", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 240, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "// Outlevo signs every delivery: Outlevo-Signature: t=,v1=.\n// This node reads the raw body and the header; the Crypto node signs the same text with your secret; the next node compares.\nconst item = $input.first();\nconst raw = (await this.helpers.getBinaryDataBuffer(0, 'data')).toString('utf8');\nconst header = String((item.json.headers || {})['outlevo-signature'] || '');\nconst parts = header.split(',').map((kv) => kv.trim().split('='));\nconst t = Number((parts.find(([k]) => k === 't') || [])[1]) || 0;\nconst sigs = parts.filter(([k]) => k === 'v1').map(([, v]) => v || '');\nreturn [{ json: { raw, t, sigs, signed: `${t}.${raw}` } }];\n" } }, { "id": "f300e7b3-3645-438a-92f0-e0602f0ff82a", "name": "Sign with your secret", "type": "n8n-nodes-base.crypto", "typeVersion": 2, "position": [ 480, 0 ], "parameters": { "action": "hmac", "type": "SHA256", "value": "={{ $json.signed }}", "dataPropertyName": "hmac", "encoding": "hex" }, "credentials": { "crypto": { "id": "", "name": "Outlevo webhook signing secret" } } }, { "id": "43efcda0-d9ef-4f37-9a43-c15de964269f", "name": "Check signature", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 720, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "// Accept the event only if a v1 signature equals the HMAC and it was signed in the last 5 minutes; anything else stops here.\nconst { raw, t, sigs, hmac } = $input.first().json;\nconst same = (a, b) => { if (typeof a !== 'string' || a.length !== b.length) return false; let d = 0; for (let i = 0; i < a.length; i++) d |= a.charCodeAt(i) ^ b.charCodeAt(i); return d === 0; };\nif (!t || Math.abs(Date.now() / 1000 - t) > 300 || !sigs.some((s) => same(s, hmac))) throw new Error('Outlevo signature did not verify');\nconst event = JSON.parse(raw);\nreturn [{ json: { ...event.data, event_id: event.id, event: event.type, created_at: event.created_at } }];\n" } }, { "id": "13af451f-a194-47dc-beb5-c3a8bf0371ca", "name": "Competitor changed?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 960, 0 ], "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "8bebca7e-2b28-47ca-8fe1-36004f078679", "leftValue": "={{ $json.event }}", "rightValue": "competitor.changed", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} } }, { "id": "f3d01d23-3c30-4533-9b24-2e99c5096db5", "name": "Get the competitor", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1200, 0 ], "parameters": { "method": "GET", "url": "=https://api.outlevo.com/v1/competitors/{{ $('Competitor changed?').item.json.competitor_id }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": {} }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } }, { "id": "2e17cc64-cefb-43bb-a62b-66cf93d3dfa6", "name": "Write the message", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1440, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "// The newest changes first; the event says how many this crawl found.\nconst ev = $('Competitor changed?').first().json;\nconst cp = $('Get the competitor').first().json;\nconst n = ev.changes || 1;\nconst list = [...(cp.changes || [])].sort((a, b) => String(b.detected_at).localeCompare(String(a.detected_at))).slice(0, Math.min(n, 10));\nconst lines = list.map((c) => `• ${c.field}: ${c.from_value ?? '(none)'} → ${c.to_value ?? '(removed)'}${c.to_url ? ` (${c.to_url})` : ''}`);\nconst name = cp.name || cp.domain || ev.domain;\nconst text = `👀 ${name} changed ${n} thing(s) on its site${lines.length ? `:\\n${lines.join('\\n')}` : '.'}\\nhttps://app.outlevo.com/competitors/${cp.link_id}`;\nreturn [{ json: { text, subject: `${name} changed ${n} thing(s)` } }];\n" } }, { "id": "8cef8991-ccad-4275-8a48-b2f7c0be0cb4", "name": "Post to Discord", "type": "n8n-nodes-base.discord", "typeVersion": 2, "position": [ 1680, 0 ], "parameters": { "authentication": "webhook", "operation": "sendLegacy", "content": "={{ $json.text.slice(0, 2000) }}", "options": {} }, "credentials": { "discordWebhookApi": { "id": "", "name": "Discord webhook" } } } ], "connections": { "Outlevo webhook": { "main": [ [ { "node": "Read the body", "type": "main", "index": 0 } ] ] }, "Read the body": { "main": [ [ { "node": "Sign with your secret", "type": "main", "index": 0 } ] ] }, "Sign with your secret": { "main": [ [ { "node": "Check signature", "type": "main", "index": 0 } ] ] }, "Check signature": { "main": [ [ { "node": "Competitor changed?", "type": "main", "index": 0 } ] ] }, "Competitor changed?": { "main": [ [ { "node": "Get the competitor", "type": "main", "index": 0 } ], [] ] }, "Get the competitor": { "main": [ [ { "node": "Write the message", "type": "main", "index": 0 } ] ] }, "Write the message": { "main": [ [ { "node": "Post to Discord", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "pinData": {}, "meta": { "templateCredsSetupCompleted": false } }