{ "name": "Outlevo: Campaign status to Telegram", "nodes": [ { "id": "6795b4ca-41ec-4f25-b921-8a0167ad4b1a", "name": "How to set it up", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [ -40, -584 ], "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- **Telegram bot**: connect your Telegram bot account.\n\n**API key scopes**: `campaigns:read`.\n\n**Replace**: `YOUR_CHAT_ID`.\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\": [\"campaign.status_changed\"]}'\n```\nPut the `secret` from the answer into the Crypto credential.\n\nThen switch the workflow to **Active**.", "height": 524, "width": 620 } }, { "id": "2fd9b7d3-561c-44e7-a619-a22b7aac3404", "name": "Outlevo webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 0, 0 ], "parameters": { "httpMethod": "POST", "path": "outlevo-campaign-status-to-telegram", "responseMode": "onReceived", "options": { "rawBody": true } }, "webhookId": "e5e85210-c563-48ec-9d62-f82d82a7adb2" }, { "id": "2096c57d-c9c1-438b-83c8-44fc29f92be1", "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": "cf458233-6733-4a5d-a834-a5debe8ffbd6", "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": "f1c1314d-8c22-4861-b9a0-4104c943d982", "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": "5ca3bbd4-5930-4d0c-a165-7a91c195564b", "name": "Campaign status?", "type": "n8n-nodes-base.if", "typeVersion": 2, "position": [ 960, 0 ], "parameters": { "conditions": { "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict" }, "conditions": [ { "id": "8035c94b-3dc9-4bab-a2bb-2968ccdc57c1", "leftValue": "={{ $json.event }}", "rightValue": "campaign.status_changed", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} } }, { "id": "dcacb263-0cb4-49ac-b94d-90b8d61e553c", "name": "Get the campaign", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1200, 0 ], "parameters": { "method": "GET", "url": "=https://api.outlevo.com/v1/campaigns/{{ $('Campaign status?').item.json.campaign_id || 'none' }}", "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": { "response": { "response": { "neverError": true } } } }, "credentials": { "httpHeaderAuth": { "id": "", "name": "Outlevo API key (Authorization: Bearer olv_live_…)" } } }, { "id": "ad438538-9bd9-4bcc-b71b-5eba79d216da", "name": "Write the message", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1440, 0 ], "parameters": { "mode": "runOnceForAllItems", "jsCode": "const ev = $('Campaign status?').first().json;\nconst cp = $('Get the campaign').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 icon = { active: '▶️', paused: '⏸️', stopped: '⏹️', built: '✅', building: '🛠️', draft: '📝' }[ev.status] || 'ℹ️';\nconst why = s(ev.reason || cp.paused_reason);\nconst text = `${icon} Campaign ${cp.name ? `\"${cp.name}\" ` : ''}is now ${ev.status}${why ? `: ${why}` : ''}\\nhttps://app.outlevo.com/campaigns/${ev.campaign_id}`;\nreturn [{ json: { text, subject: `Campaign ${cp.name || ''} ${ev.status}`.replace(/\\s+/g, ' ') } }];\n" } }, { "id": "37e6742a-7e19-47de-874f-f58202d640ca", "name": "Send to Telegram", "type": "n8n-nodes-base.telegram", "typeVersion": 1.2, "position": [ 1680, 0 ], "parameters": { "chatId": "YOUR_CHAT_ID", "text": "={{ $json.text.slice(0, 4096) }}", "additionalFields": { "appendAttribution": false, "disable_web_page_preview": true } }, "credentials": { "telegramApi": { "id": "", "name": "Telegram bot" } } } ], "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": "Campaign status?", "type": "main", "index": 0 } ] ] }, "Campaign status?": { "main": [ [ { "node": "Get the campaign", "type": "main", "index": 0 } ], [] ] }, "Get the campaign": { "main": [ [ { "node": "Write the message", "type": "main", "index": 0 } ] ] }, "Write the message": { "main": [ [ { "node": "Send to Telegram", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "pinData": {}, "meta": { "templateCredsSetupCompleted": false } }