This workflow follows the HTTP Request → Postgres recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"name": "OTTO - \u00c9pico 5: Escalada e Governan\u00e7a (Zona Vermelha)",
"nodes": [
{
"parameters": {
"content": "## \ud83d\udd34 \u00c9pico 5: Escalada e Governan\u00e7a\n\n**Regra**: Transbordo como prote\u00e7\u00e3o de receita, n\u00e3o puni\u00e7\u00e3o.\n\n**Tarefa 5.1**: Se alerta amarelo foi ignorado (sem novo state_version), zona vermelha aciona.\n**Tarefa 5.2**: OTTO injeta na fila da Fernanda via Webhook.\nSe cliente interagir positivamente, OTTO notifica vendedor com a prova.",
"height": 220,
"width": 420,
"color": 2
},
"id": "note-docs",
"name": "\ud83d\udccb Documenta\u00e7\u00e3o",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
40,
40
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "otto_zona_vermelha",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {}
},
"id": "webhook-vermelho",
"name": "Webhook: Zona Vermelha Ativada",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
260,
340
],
"credentials": {
"httpHeaderAuth": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "=SELECT l.id, l.nome_cliente, l.telefone, l.veiculo_interesse, l.estagio_atual, l.temperatura, l.state_version, l.metadata, l.tags, v.nome as vendedor_nome, v.whatsapp_id as vendedor_whatsapp, c.alerta_amarelo_at, c.alerta_amarelo_enviado, (SELECT ec.evidencia_ia->>'objecao_detectada' FROM eventos_comerciais ec WHERE ec.lead_id = l.id AND ec.evidencia_ia->>'objecao_detectada' IS NOT NULL ORDER BY ec.criado_em DESC LIMIT 1) as ultima_objecao, (SELECT ec.evidencia_ia->>'resumo_comercial' FROM eventos_comerciais ec WHERE ec.lead_id = l.id ORDER BY ec.criado_em DESC LIMIT 1) as ultimo_resumo FROM leads l INNER JOIN vendedores v ON v.id = l.vendedor_id INNER JOIN cronometros_otto c ON c.lead_id = l.id AND c.lead_state_version = l.state_version WHERE l.id = '{{ $json.lead_id }}';",
"options": {}
},
"id": "buscar-contexto-completo",
"name": "Buscar Contexto Completo",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.5,
"position": [
500,
340
],
"credentials": {
"postgres": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"jsCode": "// Verificar in\u00e9rcia comprovada: amarelo foi enviado MAS n\u00e3o gerou novo state_version\nconst d = $input.first().json;\n\n// Confirmar que o alerta amarelo foi enviado e ignorado\nconst inerciaComprovada = d.alerta_amarelo_enviado === true;\n\nif (!inerciaComprovada) {\n return [{ json: { ...d, acao: 'CANCELAR', motivo: 'Alerta amarelo n\u00e3o foi enviado ainda' } }];\n}\n\n// Preparar payload para a fila da Fernanda\nconst objecaoResumo = d.ultima_objecao || 'n\u00e3o identificada';\n\nreturn [{ json: {\n ...d,\n acao: 'ESCALAR',\n payload_fernanda: {\n lead_id: d.id,\n lead_nome: d.nome_cliente,\n lead_telefone: d.telefone,\n veiculo: d.veiculo_interesse,\n estagio: d.estagio_atual,\n objecao_principal: objecaoResumo,\n ultimo_resumo: d.ultimo_resumo,\n vendedor_original: d.vendedor_nome,\n vendedor_whatsapp: d.vendedor_whatsapp,\n instrucao: `Assuma o lead ${d.nome_cliente}, obje\u00e7\u00e3o: ${objecaoResumo}. Ve\u00edculo: ${d.veiculo_interesse || 'N/I'}.`\n }\n}}];"
},
"id": "verificar-inercia",
"name": "Verificar In\u00e9rcia Comprovada",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
740,
340
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "deve-escalar",
"leftValue": "={{ $json.acao }}",
"rightValue": "ESCALAR",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
}
},
"id": "if-escalar",
"name": "Deve Escalar?",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
980,
340
]
},
{
"parameters": {
"method": "POST",
"url": "={{ $env.FERNANDA_WEBHOOK_URL || 'https://webhook.dexidigital.com.br/webhook/fernanda_fila' }}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify($json.payload_fernanda) }}",
"options": {}
},
"id": "injetar-fila-fernanda",
"name": "Injetar na Fila da Fernanda",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1220,
240
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "=INSERT INTO eventos_comerciais (lead_id, vendedor_id, tipo_evento, evidencia_ia, state_version_at) SELECT '{{ $json.id }}', l.vendedor_id, 'ESCALADA_FERNANDA', '{{ JSON.stringify($json.payload_fernanda).replace(/'/g, \"''\") }}'::jsonb, l.state_version FROM leads l WHERE l.id = '{{ $json.id }}'; UPDATE cronometros_otto SET alerta_vermelho_enviado = TRUE, status_cronometro = 'escalado' WHERE lead_id = '{{ $json.id }}' AND lead_state_version = {{ $json.state_version }};",
"options": {}
},
"id": "registrar-escalada",
"name": "Registrar Evento de Escalada",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.5,
"position": [
1460,
240
],
"credentials": {
"postgres": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"method": "POST",
"url": "=https://graph.facebook.com/v18.0/{{ $env.WHATSAPP_PHONE_ID }}/messages",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"messaging_product\": \"whatsapp\",\n \"to\": \"{{ $json.vendedor_whatsapp }}\",\n \"type\": \"text\",\n \"text\": { \"body\": \"\ud83d\udd34 OTTO - Transbordo ativado\\n\\nO lead *{{ $json.nome_cliente }}* ({{ $json.veiculo_interesse || 'N/I' }}) foi encaminhado para a Fernanda.\\n\\nMotivo: Sem nova intera\u00e7\u00e3o ap\u00f3s alerta amarelo.\\nObje\u00e7\u00e3o identificada: {{ $json.ultima_objecao || 'N/I' }}\\n\\n_A Fernanda vai tentar reabrir a conversa. Se ela conseguir, voc\u00ea ser\u00e1 notificado._\" }\n}",
"options": {}
},
"id": "notificar-vendedor-escalada",
"name": "Notificar Vendedor (Transbordo)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1700,
240
],
"credentials": {
"httpHeaderAuth": {
"name": "<your credential>"
}
}
}
],
"connections": {
"Webhook: Zona Vermelha Ativada": {
"main": [
[
{
"node": "Buscar Contexto Completo",
"type": "main",
"index": 0
}
]
]
},
"Buscar Contexto Completo": {
"main": [
[
{
"node": "Verificar In\u00e9rcia Comprovada",
"type": "main",
"index": 0
}
]
]
},
"Verificar In\u00e9rcia Comprovada": {
"main": [
[
{
"node": "Deve Escalar?",
"type": "main",
"index": 0
}
]
]
},
"Deve Escalar?": {
"main": [
[
{
"node": "Injetar na Fila da Fernanda",
"type": "main",
"index": 0
}
],
[]
]
},
"Injetar na Fila da Fernanda": {
"main": [
[
{
"node": "Registrar Evento de Escalada",
"type": "main",
"index": 0
}
]
]
},
"Registrar Evento de Escalada": {
"main": [
[
{
"node": "Notificar Vendedor (Transbordo)",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"tags": [
{
"id": "otto-1",
"name": "OTTO"
},
{
"id": "otto-11",
"name": "Escalada"
},
{
"id": "otto-12",
"name": "\u00c9pico 5"
}
],
"triggerCount": 1,
"updatedAt": "2026-02-26T12:00:00.000Z",
"versionId": "1"
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
httpHeaderAuthpostgres
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
OTTO - Épico 5: Escalada e Governança (Zona Vermelha). Uses postgres, httpRequest. Webhook trigger; 8 nodes.
Source: https://github.com/paraisolorrayne/Attra/blob/6dd06914bf6be4654e2cb2b445995786aa402cd3/automations/epico-5-escalada-governanca.json — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Scraping. Uses httpRequest, postgres, @apify/n8n-nodes-apify, respondToWebhook. Webhook trigger; 61 nodes.
Workflow B — AI Listing Engine. Uses httpRequest, postgres, errorTrigger. Webhook trigger; 47 nodes.
Fluxo de voluntárias ZendeskXANXBD. Uses functionItem, zendesk, httpRequest, postgres. Webhook trigger; 25 nodes.
Fluxo de voluntárias ZendeskXANXBD. Uses functionItem, zendesk, httpRequest, postgres. Webhook trigger; 25 nodes.
Fluxo de voluntárias ZendeskXANXBD. Uses functionItem, zendesk, httpRequest, postgres. Webhook trigger; 25 nodes.