From 3ac5086161a204ceee1dd933cc564ad2ab8a6161 Mon Sep 17 00:00:00 2001 From: Marcio Bevervanso Date: Tue, 16 Jun 2026 15:55:02 -0300 Subject: [PATCH] docs: workflows n8n prontos pra importar (monitor, resumo, alertas) Co-Authored-By: Claude Opus 4.8 --- docs/n8n/01-engine-monitor.json | 60 +++++++++++++++++++++++++++++++ docs/n8n/02-engine-summary.json | 63 +++++++++++++++++++++++++++++++++ docs/n8n/03-engine-alerts.json | 63 +++++++++++++++++++++++++++++++++ docs/n8n/README.md | 27 ++++++++++++++ 4 files changed, 213 insertions(+) create mode 100644 docs/n8n/01-engine-monitor.json create mode 100644 docs/n8n/02-engine-summary.json create mode 100644 docs/n8n/03-engine-alerts.json create mode 100644 docs/n8n/README.md diff --git a/docs/n8n/01-engine-monitor.json b/docs/n8n/01-engine-monitor.json new file mode 100644 index 0000000..53402ef --- /dev/null +++ b/docs/n8n/01-engine-monitor.json @@ -0,0 +1,60 @@ +{ + "name": "ADsPRO — Engine Monitor (a cada 4h)", + "nodes": [ + { + "parameters": { + "rule": { + "interval": [ + { + "field": "hours", + "hoursInterval": 4 + } + ] + } + }, + "id": "schedule-monitor", + "name": "A cada 4 horas", + "type": "n8n-nodes-base.scheduleTrigger", + "typeVersion": 1.2, + "position": [260, 300] + }, + { + "parameters": { + "method": "POST", + "url": "https://admanager.seureview.com.br/api/engine/cron", + "sendHeaders": true, + "headerParameters": { + "parameters": [ + { + "name": "Authorization", + "value": "Bearer COLE_SEU_CRON_SECRET" + } + ] + }, + "options": { + "timeout": 60000 + } + }, + "id": "http-monitor", + "name": "Rodar Engine", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4.2, + "position": [520, 300] + } + ], + "connections": { + "A cada 4 horas": { + "main": [ + [ + { + "node": "Rodar Engine", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "settings": {}, + "active": false +} diff --git a/docs/n8n/02-engine-summary.json b/docs/n8n/02-engine-summary.json new file mode 100644 index 0000000..accc795 --- /dev/null +++ b/docs/n8n/02-engine-summary.json @@ -0,0 +1,63 @@ +{ + "name": "ADsPRO — Resumo Diário (20h)", + "nodes": [ + { + "parameters": { + "rule": { + "interval": [ + { + "field": "cronExpression", + "expression": "0 20 * * *" + } + ] + } + }, + "id": "schedule-summary", + "name": "Todo dia 20h", + "type": "n8n-nodes-base.scheduleTrigger", + "typeVersion": 1.2, + "position": [260, 300] + }, + { + "parameters": { + "method": "POST", + "url": "https://admanager.seureview.com.br/api/engine/cron", + "sendHeaders": true, + "headerParameters": { + "parameters": [ + { + "name": "Authorization", + "value": "Bearer COLE_SEU_CRON_SECRET" + } + ] + }, + "sendBody": true, + "specifyBody": "json", + "jsonBody": "{\n \"summary\": true\n}", + "options": { + "timeout": 60000 + } + }, + "id": "http-summary", + "name": "Pedir Resumo", + "type": "n8n-nodes-base.httpRequest", + "typeVersion": 4.2, + "position": [520, 300] + } + ], + "connections": { + "Todo dia 20h": { + "main": [ + [ + { + "node": "Pedir Resumo", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "settings": {}, + "active": false +} diff --git a/docs/n8n/03-engine-alerts.json b/docs/n8n/03-engine-alerts.json new file mode 100644 index 0000000..07dbd29 --- /dev/null +++ b/docs/n8n/03-engine-alerts.json @@ -0,0 +1,63 @@ +{ + "name": "ADsPRO — Receber Alertas do Engine", + "nodes": [ + { + "parameters": { + "httpMethod": "POST", + "path": "adspro-alertas", + "responseMode": "onReceived", + "options": {} + }, + "id": "webhook-alerts", + "name": "Webhook (N8N_WEBHOOK_URL)", + "type": "n8n-nodes-base.webhook", + "typeVersion": 2, + "position": [240, 300], + "webhookId": "adspro-alertas" + }, + { + "parameters": { + "jsCode": "const out = [];\nfor (const item of $input.all()) {\n const p = item.json.body || item.json;\n let message = '';\n if (p.type === 'daily_summary') {\n message = '📊 Resumo do dia — Festa Magica\\n💸 Gasto: R$' + p.spend + '\\n🛒 Compras: ' + p.purchases + '\\n🎯 CPA: R$' + p.cpa + '\\n📈 ROAS: ' + p.roas + '\\n👆 CTR: ' + p.ctr + '%';\n } else if (p.type === 'automation_run') {\n const acts = (p.actions || []).map(function (a) { return (a.executed ? '✅ EXECUTOU' : '⚠️ RECOMENDA') + ': ' + a.action + ' — ' + a.campaign + ' (' + a.rule + ')'; }).join('\\n');\n message = '🤖 Engine rodou (modo ' + p.mode + ')\\n' + (acts || 'Nada disparou.');\n } else {\n message = JSON.stringify(p);\n }\n out.push({ json: { message: message, payload: p } });\n}\nreturn out;" + }, + "id": "code-format", + "name": "Formatar mensagem", + "type": "n8n-nodes-base.code", + "typeVersion": 2, + "position": [480, 300] + }, + { + "parameters": {}, + "id": "noop-channel", + "name": "Enviar (conecte seu canal aqui)", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [720, 300] + } + ], + "connections": { + "Webhook (N8N_WEBHOOK_URL)": { + "main": [ + [ + { + "node": "Formatar mensagem", + "type": "main", + "index": 0 + } + ] + ] + }, + "Formatar mensagem": { + "main": [ + [ + { + "node": "Enviar (conecte seu canal aqui)", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "settings": {}, + "active": false +} diff --git a/docs/n8n/README.md b/docs/n8n/README.md new file mode 100644 index 0000000..2dd3bb1 --- /dev/null +++ b/docs/n8n/README.md @@ -0,0 +1,27 @@ +# Workflows n8n — Automação do ADsPRO + +3 fluxos prontos pra importar (n8n → **Import from File**). + +| Arquivo | O que faz | +|---|---| +| `01-engine-monitor.json` | A cada 4h: chama o engine pra avaliar campanhas e agir (modo do app). | +| `02-engine-summary.json` | Todo dia às 20h: pede o resumo (gasto/compras/CPA/ROAS). | +| `03-engine-alerts.json` | Recebe os alertas do engine (webhook) e formata a mensagem. | + +## Passo a passo + +1. **Importe os 3** no n8n. + +2. Nos fluxos **01** e **02**, abra o nó HTTP e troque `COLE_SEU_CRON_SECRET` pelo valor que você definiu em `CRON_SECRET` (env do Coolify). Confirme a URL (`https://admanager.seureview.com.br/api/engine/cron`). + +3. No fluxo **03**, abra o nó **Webhook**, copie a **Production URL** dele e cole na env `N8N_WEBHOOK_URL` do Coolify (e redeploy). Depois conecte o nó final ("Enviar...") ao seu canal (WhatsApp/Telegram/email). + +4. **Ative** os 3 workflows (toggle "Active"). + +## Testar sem esperar o horário +- Fluxo 01/02: clique em **Execute Workflow** (dispara o POST na hora). +- Fluxo 03: deixe ativo e rode o 01/02 — se algo disparar, o alerta chega. + +## Ajustes +- Mudar frequência: nó **Schedule** (ex: `hoursInterval: 2`). +- Modo de autonomia: env `AUTOMATION_MODE` (`mixed` | `auto` | `notify`), ou mande no body do HTTP `{ "mode": "notify" }`.