{ "name": "Outlevo: Replies log in Postgres", "nodes": [ { "id": "8a57dabb-dcbf-4bca-9ad6-f076e5e250c2", "name": "How to set it up", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -40, -914 ], "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- **Postgres**: connect your Postgres account.\n\n**API key scopes**: `companies:read`, `contacts: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\": [\"lead.replied\"]}'\n```\nPut the `secret` from the answer into the Crypto credential.\n\n**Table**:\n```sql\ncreate table outlevo_replies (\n id bigserial primary key,\n received text,\n channel text,\n person text,\n job_title text,\n company text,\n domain text,\n reply text,\n campaign_id text,\n link text,\n received_at timestamptz not null default now()\n);\n```\n\nThen switch the workflow to **Active**.", "height": 854, "width": 620 } }, { "id": "ae60aff0-c442-4041-9609-f426b43be6c3", "name": "Outlevo webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 0, 0 ], "parameters": { "httpMethod": "POST", "path": "outlevo-reply-to-postgres", "responseMode": "onReceived", "options": { "rawBody": true } }, "webhookId": "3e3ac2fd-903b-401e-a256-3d86eb8e6def" }, { "id": "8490674d-8b6c-49de-9943-09c30a51ec47", "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": "4a9af062-c669-4a0e-88fb-7843cbfb51b9", "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": "a9f8786d-609f-4746-80cd-8366e89725d7", "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": "377e756e-27d9-430f-89f4-77be11837c90", "name": "A reply?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 960, 0 ], "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "8e515c03-d8b9-47d5-b3c8-ff4d852f942a", "leftValue": "={{ $json.event }}", "rightValue": "lead.replied", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} } }, { "id": "6e191c44-2d1a-4771-a289-20d13fa023ee", "name": "Get the contact", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1200, 0 ], "parameters": { "method": "GET", "url": "=https://api.outlevo.com/v1/contacts/{{ $('A reply?').item.json.contact_id || 'none' }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": true } } } }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } }, { "id": "a725ccfa-b1a3-4256-a373-3a914b5e9ed5", "name": "Get the company", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1440, 0 ], "parameters": { "method": "GET", "url": "=https://api.outlevo.com/v1/companies/{{ $('A reply?').item.json.company_id || 'none' }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": true } } } }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } }, { "id": "cd2bcff2-cf2f-46ce-9f8b-6a27387821dc", "name": "Write the row", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1680, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "const ev = $('A reply?').first().json;\nconst c = $('Get the contact').first().json;\nconst co = $('Get the company').first().json;\nconst s = (v) => (v == null ? '' : typeof v === 'string' ? v : typeof v === 'object' ? JSON.stringify(v) : String(v));\nconst person = (c) => [c.first_name, c.last_name].filter(Boolean).join(' ');\nconst when = (d) => (d ? new Date(d).toUTCString().replace(/:\\d\\d GMT$/, ' UTC') : '');\nconst rows = [{ Received: s(ev.at || ev.created_at), Channel: ev.channel === 'linkedin' ? 'LinkedIn' : 'Email', Person: person(c), 'Job title': s(c.title), Company: s(co.name), Domain: s(co.domain), Reply: s(ev.reply_text).slice(0, 2000), 'Campaign id': s(ev.campaign_id), Link: 'https://app.outlevo.com/replies' }];\nconst snake = (k) => k.toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_|_$/g, '');\nreturn rows.map((r) => ({ json: Object.fromEntries(Object.entries(r).map(([k, v]) => [snake(k), v === '' ? null : String(v)])) }));\n" } }, { "id": "663b6ed5-111c-46a2-8ed3-7c111617e355", "name": "Insert into Postgres", "type": "n8n-nodes-base.postgres", "typeVersion": 2.5, "position": [ 1920, 0 ], "parameters": { "operation": "insert", "schema": { "__rl": true, "mode": "list", "value": "public" }, "table": { "__rl": true, "mode": "name", "value": "outlevo_replies" }, "columns": { "mappingMode": "autoMapInputData", "value": {}, "matchingColumns": [], "schema": [] }, "options": {} }, "credentials": { "postgres": { "id": "", "name": "Postgres" } } } ], "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": "A reply?", "type": "main", "index": 0 } ] ] }, "A reply?": { "main": [ [ { "node": "Get the contact", "type": "main", "index": 0 } ], [] ] }, "Get the contact": { "main": [ [ { "node": "Get the company", "type": "main", "index": 0 } ] ] }, "Get the company": { "main": [ [ { "node": "Write the row", "type": "main", "index": 0 } ] ] }, "Write the row": { "main": [ [ { "node": "Insert into Postgres", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "pinData": {}, "meta": { "templateCredsSetupCompleted": false } }