{ "name": "Outlevo: Competitor change to Microsoft Teams", "nodes": [ { "id": "6ba47eb3-3ed6-45ab-98a7-1e5bf9dbdc97", "name": "How to set it up", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -40, -606 ], "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- **Microsoft Teams**: connect your Microsoft Teams account.\n\n**API key scopes**: `companies:read`.\n\n**Pick in the node**:\n- **Post to Teams**: the team and the channel\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": 546, "width": 620 } }, { "id": "c0e8269d-d080-4384-a9f0-3b59412f7d80", "name": "Outlevo webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 0, 0 ], "parameters": { "httpMethod": "POST", "path": "outlevo-competitor-change-to-teams", "responseMode": "onReceived", "options": { "rawBody": true } }, "webhookId": "22cb3396-fe21-41e8-81cc-4bba6d3e3243" }, { "id": "d97d7946-4b95-4737-acdc-c12899b91e57", "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": "84a10822-f2a2-4a6e-b8a6-85d25100849b", "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": "51b47659-972d-40a4-bf5b-e054ce2404c4", "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": "cecbacc2-65c4-4368-b10d-5c0a7a1127e3", "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": "46ab2efe-0f1a-4ce3-8bd6-dcf83ed1763d", "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": "cd2199f7-ef94-413d-a0f6-4c0e75875d3c", "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": "3fff683d-1e1b-40d8-a4ba-4c8a2c304f32", "name": "Post to Teams", "type": "n8n-nodes-base.microsoftTeams", "typeVersion": 2, "position": [ 1680, 0 ], "parameters": { "resource": "channelMessage", "operation": "create", "teamId": { "__rl": true, "mode": "list", "value": "" }, "channelId": { "__rl": true, "mode": "list", "value": "" }, "contentType": "html", "message": "={{ $json.text.split('&').join('&').split('<').join('<').split('>').join('>').split('\\n').join('
') }}", "options": { "includeLinkToWorkflow": false } }, "credentials": { "microsoftTeamsOAuth2Api": { "id": "", "name": "Microsoft Teams" } } } ], "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 Teams", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "pinData": {}, "meta": { "templateCredsSetupCompleted": false } }