{ "name": "Outlevo: Proposed action to Google Chat", "nodes": [ { "id": "9b6a5f28-9f2d-49cb-9128-b046150aa8cf", "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`, `revenue_actions: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\": [\"revenue_action.proposed\"]}'\n```\nPut the `secret` from the answer into the Crypto credential.\n\nThen switch the workflow to **Active**.", "height": 502, "width": 620 } }, { "id": "4787ff11-4d93-4bc2-8f3d-b407c699f5d8", "name": "Outlevo webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 0, 0 ], "parameters": { "httpMethod": "POST", "path": "outlevo-proposed-action-to-google-chat", "responseMode": "onReceived", "options": { "rawBody": true } }, "webhookId": "cf05b2c9-9864-480a-9088-e8c5c145e9be" }, { "id": "8e4cd91c-5317-4d64-b173-baf8ce8ee6fe", "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": "b076a888-9603-490f-9eae-80acefdfe0ac", "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": "a07ee4d7-dfcd-46ac-851c-21a4542da072", "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": "d6563663-0265-4d8e-9e82-3655ee4b54ad", "name": "Proposed action?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 960, 0 ], "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "f9ca2ed2-4c89-450d-8a2e-f7d22aac19e6", "leftValue": "={{ $json.event }}", "rightValue": "revenue_action.proposed", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} } }, { "id": "f264e1f2-f512-469e-8175-e38bbdbb357c", "name": "Get the action", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1200, 0 ], "parameters": { "method": "GET", "url": "=https://api.outlevo.com/v1/revenue-actions/{{ $('Proposed action?').item.json.id || 'none' }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": true } } } }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } }, { "id": "1a4a5e8a-40b5-4588-906e-8dcafb2d304b", "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/{{ $json.target_account_id || 'none' }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": true } } } }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } }, { "id": "d132ac45-8b0d-4afe-85b2-887bab1f35e3", "name": "Write the message", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1680, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "const ev = $('Proposed action?').first().json;\nconst a = $('Get the action').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 LABEL = { crm_task: 'CRM task', outbound_step: 'Outbound step', ad_audience: 'Ad audience', research_request: 'Research request', handoff: 'Handoff' };\nconst kind = LABEL[ev.action_type || a.action_type] || 'Action';\nconst wait = ['pending', 'required'].includes(ev.approval_status || a.approval_status);\nconst at = co.name || co.domain;\nconst text = `${wait ? '🗳️ Waiting for your approval' : '💡 Proposed'}: ${kind}${at ? ` for ${at}` : ''}${a.reason ? `\\nWhy: ${s(a.reason)}` : ''}${a.expected_outcome ? `\\nExpected: ${s(a.expected_outcome)}` : ''}\\nhttps://app.outlevo.com/${wait ? 'approvals' : 'actions'}`;\nreturn [{ json: { text, subject: `${wait ? 'To approve' : 'Proposed'}: ${kind}${at ? ` for ${at}` : ''}` } }];\n" } }, { "id": "f7c03eeb-efa4-458f-99d5-f7c82e9ba47f", "name": "Post to Google Chat", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1920, 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": "Proposed action?", "type": "main", "index": 0 } ] ] }, "Proposed action?": { "main": [ [ { "node": "Get the action", "type": "main", "index": 0 } ], [] ] }, "Get the action": { "main": [ [ { "node": "Get the company", "type": "main", "index": 0 } ] ] }, "Get the company": { "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 } }