{ "name": "Outlevo: Competitor change to Google Chat", "nodes": [ { "id": "47643a29-c1cf-4cbf-ac23-c63d29853c35", "name": "How to set it up", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -40, -562 ], "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\n**API key scopes**: `companies:read`.\n\n**Replace**: `YOUR_SPACE`, `YOUR_KEY`, `YOUR_TOKEN`.\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": 502, "width": 620 } }, { "id": "f714ea32-5867-49cb-bec0-55ddcf6abcc3", "name": "Outlevo webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 0, 0 ], "parameters": { "httpMethod": "POST", "path": "outlevo-competitor-change-to-google-chat", "responseMode": "onReceived", "options": { "rawBody": true } }, "webhookId": "38426d37-6631-4429-8f8e-d5cf780a1d32" }, { "id": "991c1b3a-b8f5-4ed7-918b-98d87ed1c372", "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": "5e479bbc-72d1-4175-b5b7-f00e9e36b1fd", "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": "2c04443b-6fb0-4ce8-88e2-2872f196908b", "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": "a5f94df9-ca5a-4e21-8515-45018904e658", "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": "f523cc40-915e-4656-b4f0-41cfe0a18533", "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": "1ea19e7b-b90b-42aa-a0e4-976f2b0b3c13", "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": "8db2db44-357b-4ee8-baba-edc5e4503b50", "name": "Post to Google Chat", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1680, 0 ], "parameters": { "method": "POST", "url": "https://chat.googleapis.com/v1/spaces/YOUR_SPACE/messages?key=YOUR_KEY&token=YOUR_TOKEN", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ text: $json.text }) }}", "options": {} } } ], "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 Google Chat", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "pinData": {}, "meta": { "templateCredsSetupCompleted": false } }