AutomationFlowsAI & RAG › Intellix.ai - Editorial Automatizado V2

Intellix.ai - Editorial Automatizado V2

IntelliX.AI - Editorial Automatizado v2. Uses postgres, rssFeedRead, openAi, httpRequest. Event-driven trigger; 62 nodes.

Event trigger★★★★★ complexityAI-powered62 nodesPostgresRSS Feed ReadOpenAIHTTP RequestPerplexityN8N Nodes SerpapiGmail
AI & RAG Trigger: Event Nodes: 62 Complexity: ★★★★★ AI nodes: yes Added:

This workflow follows the Gmail → HTTP Request 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 →

Download .json
{
  "updatedAt": "2026-02-12T17:34:27.347Z",
  "createdAt": "2026-02-09T21:33:31.025Z",
  "id": "rZnSwaW1xF7JVq-2MaVRf",
  "name": "IntelliX.AI - Editorial Automatizado v2",
  "description": null,
  "active": true,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1440,
        176
      ],
      "name": "Manual Trigger",
      "id": "0578fc7e-0439-4254-8105-e2209aec0313"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 7 * * *"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -1440,
        384
      ],
      "name": "Schedule Trigger",
      "id": "f8d90344-3f9c-48dd-ab54-a9b9e2f77155"
    },
    {
      "parameters": {
        "jsCode": "const now = new Date();\nconst dayOfWeek = now.getDay();\nconst days = ['Domingo', 'Segunda', 'Ter\u00e7a', 'Quarta', 'Quinta', 'Sexta', 'S\u00e1bado'];\nconst dayName = days[dayOfWeek];\n\nlet contentType;\nif (dayOfWeek === 0) {\n  contentType = 'resumo_semanal';\n} else if ([1, 2, 4, 6].includes(dayOfWeek)) {\n  contentType = 'editorial';\n} else {\n  contentType = 'promocional';\n}\n\nreturn [{\n  json: {\n    contentType,\n    dayName,\n    dayOfWeek,\n    timestamp: now.toISOString(),\n    executionId: $execution.id\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1168,
        272
      ],
      "name": "Content Calendar Router",
      "id": "5344717b-9104-44a9-af46-96467355c641"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true
                },
                "combinator": "and",
                "conditions": [
                  {
                    "leftValue": "={{ $json.contentType }}",
                    "rightValue": "editorial",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true
                },
                "combinator": "and",
                "conditions": [
                  {
                    "leftValue": "={{ $json.contentType }}",
                    "rightValue": "promocional",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true
                },
                "combinator": "and",
                "conditions": [
                  {
                    "leftValue": "={{ $json.contentType }}",
                    "rightValue": "resumo_semanal",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        -880,
        272
      ],
      "name": "Content Type Switch",
      "id": "fa3679ec-0898-4330-ac5b-cac382395269"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT chave, valor FROM brand_config;",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        -880,
        32
      ],
      "name": "Fetch Brand Config",
      "id": "53788d4b-edd6-4570-9520-23ad2f19d3f0",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT id, nome, url, categoria, prioridade FROM rss_feeds WHERE ativa = true ORDER BY prioridade DESC;",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        -592,
        80
      ],
      "name": "Fetch RSS Config",
      "id": "260b3833-e000-4ee7-9763-87c8765aae44",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT keyword, categoria, prioridade FROM keywords_config WHERE ativa = true ORDER BY prioridade DESC LIMIT 10;",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        -592,
        336
      ],
      "name": "Fetch Keywords",
      "id": "4835e9d9-b0f1-4b23-8f1f-657da9a29b36",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {}
      },
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1.1,
      "position": [
        -320,
        80
      ],
      "name": "RSS Feed Reader",
      "id": "89e375bb-9626-43ae-817d-a00884239ec4",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        -32,
        176
      ],
      "name": "Merge RSS + Perplexity",
      "id": "831782a3-1da6-4854-b774-50649d512b07"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        240,
        320
      ],
      "name": "Merge All Sources",
      "id": "309c705d-626b-4339-a4c7-1b41082cf270"
    },
    {
      "parameters": {
        "jsCode": "const allItems = $input.all();\nconst normalized = [];\nconst seenUrls = new Set();\n\nfor (const item of allItems) {\n  const d = item.json;\n  let entries = [];\n\n  // Itens RSS\n  if (d.title && d.link) {\n    entries.push({\n      titulo: d.title,\n      url_fonte: d.link,\n      fonte: d.creator || d.source || 'RSS',\n      fonte_tipo: 'rss',\n      resumo_bruto: d.contentSnippet || d.content || d.description || '',\n      data_noticia: d.isoDate || d.pubDate || new Date().toISOString()\n    });\n  }\n\n  // Resultados do Perplexity - formato HTTP Request (choices[0].message.content)\n  if (d.choices && d.choices[0] && d.choices[0].message) {\n    try {\n      const parsed = JSON.parse(d.choices[0].message.content);\n      const arr = Array.isArray(parsed) ? parsed : (parsed.news || parsed.articles || [parsed]);\n      for (const a of arr) {\n        entries.push({\n          titulo: a.title || a.titulo || '',\n          url_fonte: a.url || a.link || '',\n          fonte: a.source || a.fonte || 'Perplexity',\n          fonte_tipo: 'perplexity',\n          resumo_bruto: a.summary || a.resumo || '',\n          data_noticia: a.date || a.data || new Date().toISOString()\n        });\n      }\n    } catch (e) {}\n  }\n\n  // Resultados do Perplexity nativo (n8n-nodes-base.perplexity)\n  // O node nativo retorna: { content: \"...\", model: \"...\", ... } ou { message: { content: \"...\" } }\n  if (d.content && typeof d.content === 'string' && !d.title && !d.choices) {\n    try {\n      const parsed = JSON.parse(d.content);\n      const arr = Array.isArray(parsed) ? parsed : (parsed.news || parsed.articles || [parsed]);\n      for (const a of arr) {\n        entries.push({\n          titulo: a.title || a.titulo || '',\n          url_fonte: a.url || a.link || '',\n          fonte: a.source || a.fonte || 'Perplexity',\n          fonte_tipo: 'perplexity',\n          resumo_bruto: a.summary || a.resumo || '',\n          data_noticia: a.date || a.data || new Date().toISOString()\n        });\n      }\n    } catch (e) {}\n  }\n\n  // Resultados do SerpAPI\n  if (d.news_results && Array.isArray(d.news_results)) {\n    for (const n of d.news_results) {\n      entries.push({\n        titulo: n.title || '',\n        url_fonte: n.link || '',\n        fonte: n.source?.name || n.source || 'Google News',\n        fonte_tipo: 'serpapi',\n        resumo_bruto: n.snippet || '',\n        data_noticia: n.date || new Date().toISOString()\n      });\n    }\n  }\n\n  // Resultados do SerpAPI (formato alternativo: organic_results do Google News)\n  if (d.organic_results && Array.isArray(d.organic_results)) {\n    for (const n of d.organic_results) {\n      entries.push({\n        titulo: n.title || '',\n        url_fonte: n.link || '',\n        fonte: n.source || 'Google News',\n        fonte_tipo: 'serpapi',\n        resumo_bruto: n.snippet || '',\n        data_noticia: n.date || new Date().toISOString()\n      });\n    }\n  }\n\n  // Itens de newsletters Gmail (pr\u00e9-normalizados pelo Parse Gmail News)\n  if (d.fonte_tipo === 'gmail' && d.titulo) {\n    entries.push({\n      titulo: d.titulo,\n      url_fonte: d.url_fonte || '',\n      fonte: d.fonte || 'Newsletter Gmail',\n      fonte_tipo: 'gmail',\n      resumo_bruto: d.resumo_bruto || '',\n      data_noticia: d.data_noticia || new Date().toISOString()\n    });\n  }\n\n  for (const entry of entries) {\n    const key = entry.url_fonte || entry.titulo;\n    if (key && !seenUrls.has(key)) {\n      seenUrls.add(key);\n      normalized.push({ json: entry });\n    }\n  }\n}\n\nreturn normalized.length > 0 ? normalized : [{ json: { error: 'Nenhum artigo encontrado', timestamp: new Date().toISOString() } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        528,
        176
      ],
      "name": "Normalize Data",
      "id": "7f7d07aa-d36c-4119-8d56-b07019fd5ed6"
    },
    {
      "parameters": {
        "resource": "chat",
        "model": "gpt-4o-mini",
        "options": {
          "maxTokens": 500,
          "temperature": 0.2
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        800,
        176
      ],
      "name": "AI Curation",
      "id": "a9336ec4-69e2-42f4-8f2e-d7df2a1f865b",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\nconst results = [];\n\nfor (let i = 0; i < items.length; i++) {\n  const item = items[i];\n  try {\n    const curation = JSON.parse(item.json.choices[0].message.content);\n    const score_total = (curation.score_impacto * 0.30) + (curation.score_novidade * 0.25) + (curation.score_relevancia * 0.30) + (curation.score_engajamento * 0.15);\n\n    results.push({\n      json: {\n        ...($('Normalize Data').all()[i]?.json || {}),\n        score_impacto: curation.score_impacto,\n        score_novidade: curation.score_novidade,\n        score_relevancia: curation.score_relevancia,\n        score_engajamento: curation.score_engajamento,\n        score_total: Math.round(score_total * 100) / 100,\n        categoria: curation.categoria,\n        palavras_chave: curation.palavras_chave,\n        motivo: curation.motivo\n      }\n    });\n  } catch (e) {\n    // skip items that fail to parse\n  }\n}\n\nresults.sort((a, b) => b.json.score_total - a.json.score_total);\nreturn results;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1088,
        176
      ],
      "name": "Parse Curation Results",
      "id": "e872326c-17b4-498a-b01e-ead293935cb0"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true
          },
          "combinator": "and",
          "conditions": [
            {
              "leftValue": "={{ $json.score_total }}",
              "rightValue": 7,
              "operator": {
                "type": "number",
                "operation": "gte"
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1360,
        176
      ],
      "name": "Score Filter",
      "id": "aa3b5933-32a5-4925-929a-79dec46f965f"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `SELECT COUNT(*) as count FROM ai_news WHERE url_fonte = '${$json.url_fonte.replace(/'/g, \"''\")}'` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        1648,
        176
      ],
      "name": "Check Dedup",
      "id": "cd19e14d-ff63-4d3a-a51d-b371bf13f9b8",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true
          },
          "combinator": "and",
          "conditions": [
            {
              "leftValue": "={{ $json.count }}",
              "rightValue": "0",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1920,
        176
      ],
      "name": "Is New?",
      "id": "57e7faea-0cd7-45f2-8b09-232a18f09b30"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `INSERT INTO ai_news (titulo, fonte, fonte_tipo, url_fonte, resumo_bruto, data_noticia, categoria, palavras_chave, score_impacto, score_novidade, score_relevancia, score_engajamento, score_total, status) VALUES ('${$('Parse Curation Results').item.json.titulo.replace(/'/g, \"''\")}', '${$('Parse Curation Results').item.json.fonte.replace(/'/g, \"''\")}', '${$('Parse Curation Results').item.json.fonte_tipo}', '${$('Parse Curation Results').item.json.url_fonte.replace(/'/g, \"''\")}', '${$('Parse Curation Results').item.json.resumo_bruto.replace(/'/g, \"''\")}', '${$('Parse Curation Results').item.json.data_noticia}', '${$('Parse Curation Results').item.json.categoria}', '${JSON.stringify($('Parse Curation Results').item.json.palavras_chave).replace(/'/g, \"''\")}', ${$('Parse Curation Results').item.json.score_impacto}, ${$('Parse Curation Results').item.json.score_novidade}, ${$('Parse Curation Results').item.json.score_relevancia}, ${$('Parse Curation Results').item.json.score_engajamento}, ${$('Parse Curation Results').item.json.score_total}, 'aprovado') RETURNING id;` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        2208,
        176
      ],
      "name": "Insert Article",
      "id": "83fc911f-69f3-47fb-97ad-618a0804e422",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT id, titulo, fonte, url_fonte, resumo_bruto, categoria, palavras_chave, score_total FROM ai_news WHERE status = 'aprovado' ORDER BY score_total DESC, created_at ASC LIMIT 1;",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        2480,
        176
      ],
      "name": "Select Best Article",
      "id": "38fcdfd5-a739-4476-8586-906573b831c2",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `UPDATE ai_news SET status = 'em_producao' WHERE id = '${$json.id}'` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        2768,
        176
      ],
      "name": "Update Status",
      "id": "230a1e31-9d2e-46d2-b810-bbfc401998f3",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "chat",
        "model": "gpt-4o",
        "options": {
          "maxTokens": 2500,
          "temperature": 0.4
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        3040,
        176
      ],
      "name": "AI Researcher",
      "id": "f7c7239f-be2f-4451-a44e-8eab9763b6dc",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "chat",
        "model": "gpt-4o",
        "options": {
          "maxTokens": 4000,
          "temperature": 0.6
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        3328,
        176
      ],
      "name": "AI Writer",
      "id": "2d5d3cb2-5166-43b0-b259-210ee1204fcc",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "chat",
        "model": "gpt-4o",
        "options": {
          "maxTokens": 4000,
          "temperature": 0.3
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        3600,
        176
      ],
      "name": "AI Editor",
      "id": "dd90186d-7703-47f5-b53c-f9dd2a84a867",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "chat",
        "model": "gpt-4o-mini",
        "options": {
          "maxTokens": 1500,
          "temperature": 0.3
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        3888,
        176
      ],
      "name": "AI SEO",
      "id": "75f8877c-32ac-47ab-9fff-be6bbd323c75",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const editorRaw = $('AI Editor').item.json.choices[0].message.content;\nconst seoRaw = $('AI SEO').item.json.choices[0].message.content;\nconst editor = JSON.parse(editorRaw);\nconst seo = JSON.parse(seoRaw);\nconst articleId = $('Select Best Article').item.json.id;\n\nconst esc = (s) => (s || '').replace(/'/g, \"''\");\n\nconst query = `UPDATE ai_news SET\n  titulo = '${esc(editor.titulo)}',\n  conteudo_blog = '${esc(editor.conteudo_blog)}',\n  conteudo_resumo = '${esc(editor.conteudo_resumo)}',\n  ponto_vista_intellix = '${esc(editor.ponto_vista_intellix)}',\n  tempo_leitura = '${esc(String(editor.tempo_leitura))}',\n  meta_title = '${esc(seo.meta_title)}',\n  meta_description = '${esc(seo.meta_description)}',\n  slug = '${esc(seo.slug)}',\n  keywords = '${esc(JSON.stringify(seo.keywords))}',\n  legenda_instagram = '${esc(seo.legenda_instagram)}',\n  hashtags = '${esc(JSON.stringify(seo.hashtags))}',\n  qualidade_aprovada = ${editor.qualidade_aprovada || false},\n  status = 'revisao'\nWHERE id = '${articleId}'`;\n\nreturn [{ json: { query, articleId } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        4160,
        176
      ],
      "name": "Save Final Content",
      "id": "1336c19e-68ba-45e1-b5c2-16c0dd818ad1"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ $json.query }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        4448,
        176
      ],
      "name": "Execute Save Content",
      "id": "2240ed1c-5f16-407d-86ba-a2a451e470ee",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const articleId = $('Save Final Content').item.json.articleId;\nconst titulo = $('Select Best Article').item.json.titulo;\n\nconst prompt = `Professional tech blog cover image. Theme: ${titulo}. Style: Futuristic minimalist, deep indigo (#1e1b4b), electric purple (#6366f1), warm amber (#f59e0b). Abstract tech elements, neural patterns. No text, no people. HD quality.`;\n\nreturn [{ json: { prompt, articleId, titulo } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        4720,
        176
      ],
      "name": "Generate Image Prompt",
      "id": "bc0ebb36-46d7-4786-91cb-d7afbf28b3d7"
    },
    {
      "parameters": {
        "resource": "image",
        "prompt": "={{ 'Professional tech blog cover image for a Brazilian AI consultancy. Theme: ' + $json.titulo + '. Style: Futuristic minimalist with IntelliX.AI brand colors - deep indigo (#1e1b4b), electric purple (#6366f1), warm amber (#f59e0b). Abstract tech elements, neural network patterns, data visualization aesthetics. Brazilian tech market feel. No text, no people, no logos. HD quality, clean composition.' }}",
        "options": {
          "n": 1,
          "size": "1792x1024"
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        5008,
        176
      ],
      "name": "DALL-E 3 Generate",
      "id": "efa3b564-3fff-49c3-8e49-ca444bdab6b1",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true
          },
          "combinator": "and",
          "conditions": [
            {
              "leftValue": "={{ $json.data }}",
              "rightValue": "",
              "operator": {
                "type": "array",
                "operation": "notEmpty"
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        5280,
        176
      ],
      "name": "Image Generated?",
      "id": "a04dfd9a-342f-4a70-8cb3-fcfd4859b92b"
    },
    {
      "parameters": {
        "url": "https://api.unsplash.com/search/photos",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "query",
              "value": "={{ $('Generate Image Prompt').item.json.titulo }}"
            },
            {
              "name": "per_page",
              "value": "1"
            },
            {
              "name": "orientation",
              "value": "landscape"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        5280,
        432
      ],
      "name": "Unsplash Fallback",
      "id": "dbf07b3a-04f9-418b-a089-b5d9ac305e06",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\nconst articleId = $('Generate Image Prompt').item.json.articleId;\nlet imageUrl = '';\nlet isFallback = false;\n\nfor (const item of items) {\n  // Try DALL-E result\n  if (item.json.data && item.json.data[0] && item.json.data[0].url) {\n    imageUrl = item.json.data[0].url;\n    break;\n  }\n  // Try Unsplash result\n  if (item.json.results && item.json.results[0] && item.json.results[0].urls) {\n    imageUrl = item.json.results[0].urls.regular;\n    isFallback = true;\n    break;\n  }\n}\n\nif (!imageUrl) {\n  imageUrl = 'https://intellix.ai/placeholder-cover.jpg';\n  isFallback = true;\n}\n\nreturn [{ json: { articleId, imageUrl, isFallback } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        5568,
        272
      ],
      "name": "Merge Image Result",
      "id": "2c27ac9c-bdf0-4e15-b61d-47d73d5cbd80"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `UPDATE ai_news SET imagem_capa_url = '${$json.imageUrl.replace(/'/g, \"''\")}', imagem_feed_url = '${$json.imageUrl.replace(/'/g, \"''\")}', imagem_fallback = ${$json.isFallback}, status = 'agendado', checklist_imagens = true WHERE id = '${$json.articleId}'` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        5840,
        272
      ],
      "name": "Save Image URL",
      "id": "f26cc001-61b9-46ff-9241-4cbba2f6374c",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `SELECT id, titulo, conteudo_blog, conteudo_resumo, ponto_vista_intellix, meta_title, meta_description, slug, keywords, legenda_instagram, hashtags, imagem_capa_url, imagem_feed_url, categoria, tempo_leitura FROM ai_news WHERE id = '${$('Merge Image Result').item.json.articleId}'` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        6128,
        272
      ],
      "name": "Fetch Final Article",
      "id": "ec79ef83-8de0-47a3-bd6d-e0c04a9e5ed0",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `INSERT INTO blog_posts (title, slug, excerpt, content, cover_image, category, author, published, published_at) VALUES ('${$json.titulo.replace(/'/g, \"''\")}', '${($json.slug || '').replace(/'/g, \"''\")}', '${($json.conteudo_resumo || $json.meta_description || '').replace(/'/g, \"''\")}', '${($json.conteudo_blog || '').replace(/'/g, \"''\")}', '${($json.imagem_capa_url || '').replace(/'/g, \"''\")}', '${($json.categoria || 'Geral').replace(/'/g, \"''\")}', 'IntelliX.AI', true, NOW()) ON CONFLICT (slug) DO UPDATE SET title = EXCLUDED.title, excerpt = EXCLUDED.excerpt, content = EXCLUDED.content, cover_image = EXCLUDED.cover_image, category = EXCLUDED.category, published = EXCLUDED.published, published_at = NOW() RETURNING id, slug;` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        6400,
        208
      ],
      "name": "Publish to Blog",
      "id": "23567a73-da49-46f7-8f32-0a2f020f4014",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true
          },
          "combinator": "and",
          "conditions": [
            {
              "leftValue": "={{ $json.error }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notExists"
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        6688,
        208
      ],
      "name": "Blog Published?",
      "id": "95d424cd-d4a2-48ba-96e3-7af3c9baff3f"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `UPDATE ai_news SET url_blog = '${($json.url || $json.slug || '').replace(/'/g, \"''\")}', publicado_em = NOW(), status = 'publicado' WHERE id = '${$('Merge Image Result').item.json.articleId}'; INSERT INTO publication_log (article_id, plataforma, status, url, publicado_em) VALUES ('${$('Merge Image Result').item.json.articleId}', 'blog', 'success', '${($json.url || $json.slug || '').replace(/'/g, \"''\")}', NOW());` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        6960,
        128
      ],
      "name": "Log Blog Success",
      "id": "90efde8f-521e-4f09-bf11-16ecd370b56c",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `UPDATE ai_news SET status = 'erro', erro_mensagem = '${($json.error || $json.message || 'Unknown error').replace(/'/g, \"''\")}', erro_etapa = 'publish_blog' WHERE id = '${$('Merge Image Result').item.json.articleId}'; INSERT INTO publication_log (article_id, plataforma, status, erro_mensagem, publicado_em) VALUES ('${$('Merge Image Result').item.json.articleId}', 'blog', 'failed', '${($json.error || $json.message || 'Unknown error').replace(/'/g, \"''\")}', NOW());` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        6960,
        368
      ],
      "name": "Log Blog Failure",
      "id": "fa47c4da-29a1-439b-a5f4-f57584e812ff",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Prepara dados do carrossel a partir do artigo\nconst article = $('Fetch Final Article').item.json;\n\n// Monta legenda\nlet caption = article.legenda_instagram || article.conteudo_resumo || '';\nconst cta = '\\n\\n\ud83d\udd17 Link na bio para ler o artigo completo!\\n\\n';\nconst fixedHashtags = '#InteligenciaArtificial #IA #AutomacaoInteligente #IntelliXAI #TechBrasil';\nlet articleHashtags = '';\ntry {\n  const tags = JSON.parse(article.hashtags || '[]');\n  articleHashtags = tags.map(t => t.startsWith('#') ? t : '#' + t).join(' ');\n} catch (e) { articleHashtags = ''; }\n\nlet fullCaption = caption + cta + articleHashtags + ' ' + fixedHashtags;\nif (fullCaption.length > 2200) {\n  fullCaption = fullCaption.substring(0, 2197) + '...';\n}\n\n// Extrai palavras-chave para busca de imagens no Unsplash\nlet keywords = [];\ntry {\n  keywords = JSON.parse(article.keywords || '[]');\n} catch (e) { keywords = []; }\n\n// Seleciona 4 palavras-chave diversas para slides do carrossel\nconst searchTerms = [];\nif (keywords.length >= 4) {\n  searchTerms.push(keywords[0], keywords[1], keywords[2], keywords[3]);\n} else {\n  const titleWords = (article.titulo || 'intelig\u00eancia artificial tecnologia').split(' ')\n    .filter(w => w.length > 3);\n  for (let i = 0; i < 4; i++) {\n    searchTerms.push(keywords[i] || titleWords[i] || ['intelig\u00eancia artificial', 'aprendizado de m\u00e1quina', 'ci\u00eancia de dados', 'inova\u00e7\u00e3o digital'][i]);\n  }\n}\n\nreturn [{\n  json: {\n    caption: fullCaption,\n    coverImageUrl: article.imagem_feed_url || article.imagem_url || '',\n    articleId: article.id,\n    titulo: article.titulo,\n    searchTerms: searchTerms,\n    igAccountId: '1176594747652660'\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        6400,
        656
      ],
      "name": "Prepare Instagram Caption",
      "id": "f6626f5d-a670-41a9-9068-98a453403956"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `UPDATE ai_news SET url_instagram = '${($json.id || '').replace(/'/g, \"''\")}' WHERE id = '${$('Prepare Instagram Caption').item.json.articleId}'; INSERT INTO publication_log (article_id, plataforma, status, url, publicado_em) VALUES ('${$('Prepare Instagram Caption').item.json.articleId}', 'instagram', 'success', '${($json.id || '').replace(/'/g, \"''\")}', NOW());` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        8592,
        656
      ],
      "name": "Log Instagram Success",
      "id": "6e93e103-8253-4e13-8df8-eeaa0bfadbf5",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `INSERT INTO workflow_metrics (execution_id, content_type, articles_found, articles_curated, articles_published, execution_date) VALUES ('${$('Content Calendar Router').item.json.executionId}', '${$('Content Calendar Router').item.json.contentType}', 0, 0, 1, NOW());` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        7232,
        128
      ],
      "name": "Record Metrics",
      "id": "9a94500f-452c-4a6d-9e8c-d35957c69bb0",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT id, nome, descricao, problema, solucao, resultados, prioridade, total_publicacoes FROM promo_content WHERE status = 'ativo' ORDER BY total_publicacoes ASC, prioridade DESC LIMIT 1;",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        -592,
        720
      ],
      "name": "Fetch Promo Content",
      "id": "40d252fc-2313-4dfd-b913-96dcb6fb1b1f",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `UPDATE promo_content SET total_publicacoes = total_publicacoes + 1, ultima_publicacao = NOW() WHERE id = '${$json.id}'` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        -320,
        720
      ],
      "name": "Update Promo Usage",
      "id": "9703ed72-0990-4089-8bfe-8de580dfa07c",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "={{ `INSERT INTO ai_news (titulo, fonte, fonte_tipo, url_fonte, resumo_bruto, categoria, status) VALUES ('${$('Fetch Promo Content').item.json.nome.replace(/'/g, \"''\")}', 'IntelliX.AI', 'manual', 'https://intellix.ai/cases/${$('Fetch Promo Content').item.json.id}', '${$('Fetch Promo Content').item.json.descricao.replace(/'/g, \"''\")}', 'case_study', 'em_producao') RETURNING id;` }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        -32,
        720
      ],
      "name": "Insert Promo as News",
      "id": "556c70d1-0de0-45d4-959f-87696118cf00",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "chat",
        "model": "gpt-4o",
        "options": {
          "maxTokens": 3500,
          "temperature": 0.5
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        240,
        720
      ],
      "name": "AI Promo Writer",
      "id": "9e462201-696f-4936-831d-756262a3569d",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const raw = $('AI Promo Writer').item.json.choices[0].message.content;\nconst content = JSON.parse(raw);\nconst articleId = $('Insert Promo as News').item.json.id;\n\nconst esc = (s) => (s || '').replace(/'/g, \"''\");\n\nconst query = `UPDATE ai_news SET\n  titulo = '${esc(content.titulo)}',\n  conteudo_blog = '${esc(content.conteudo_blog)}',\n  conteudo_resumo = '${esc(content.conteudo_resumo)}',\n  ponto_vista_intellix = '${esc(content.ponto_vista_intellix)}',\n  meta_title = '${esc(content.meta_title)}',\n  meta_description = '${esc(content.meta_description)}',\n  slug = '${esc(content.slug)}',\n  legenda_instagram = '${esc(content.legenda_instagram)}',\n  hashtags = '${esc(JSON.stringify(content.hashtags))}',\n  tempo_leitura = '${esc(String(content.tempo_leitura))}',\n  status = 'revisao'\nWHERE id = '${articleId}'`;\n\nreturn [{ json: { query, articleId } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        528,
        720
      ],
      "name": "Save Promo Content",
      "id": "b7044638-b766-4a50-a23e-2e2c8d2f8c50"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT id, titulo, fonte, url_fonte, resumo_bruto, categoria, palavras_chave, score_total, publicado_em FROM ai_news WHERE status = 'publicado' AND publicado_em >= NOW() - INTERVAL '7 days' ORDER BY score_total DESC LIMIT 10;",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        -592,
        1072
      ],
      "name": "Fetch Week Articles",
      "id": "91c3c644-bd34-4628-969d-cc9d96377fe2",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const articles = $input.all();\nconst now = new Date();\nconst weekStart = new Date(now);\nweekStart.setDate(now.getDate() - 7);\n\nconst articleIds = articles.map(a => a.json.id).filter(Boolean);\nconst topArticles = articles.slice(0, 5);\n\nconst summaryData = {\n  semana_inicio: weekStart.toISOString().split('T')[0],\n  semana_fim: now.toISOString().split('T')[0],\n  total_artigos: articles.length,\n  top_article_ids: JSON.stringify(articleIds.slice(0, 5)),\n  articles: topArticles.map(a => ({\n    titulo: a.json.titulo,\n    categoria: a.json.categoria,\n    score: a.json.score_total\n  }))\n};\n\nreturn [{ json: summaryData }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -320,
        1072
      ],
      "name": "Insert Weekly Summary",
      "id": "de2c775b-bc14-4af7-874f-3741f53fdb7f"
    },
    {
      "parameters": {
        "resource": "chat",
        "model": "gpt-4o",
        "options": {
          "maxTokens": 3500,
          "temperature": 0.5
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        -32,
        1072
      ],
      "name": "AI Summary Writer",
      "id": "d40f54eb-983e-439f-be43-7099ff285ae3",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const raw = $('AI Summary Writer').item.json.choices[0].message.content;\nconst content = JSON.parse(raw);\nconst summaryData = $('Insert Weekly Summary').item.json;\n\nconst esc = (s) => (s || '').replace(/'/g, \"''\");\n\nconst query = `INSERT INTO weekly_summary (semana_inicio, semana_fim, total_artigos, top_article_ids, titulo_resumo, introducao, conteudo_resumo, conclusao, ponto_vista_semanal, legenda_instagram, carrossel_slides, hashtags, meta_title, meta_description, slug, status) VALUES ('${summaryData.semana_inicio}', '${summaryData.semana_fim}', ${summaryData.total_artigos}, '${esc(summaryData.top_article_ids)}', '${esc(content.titulo_resumo)}', '${esc(content.introducao)}', '${esc(content.conteudo_resumo)}', '${esc(content.conclusao)}', '${esc(content.ponto_vista_semanal)}', '${esc(content.legenda_instagram)}', '${esc(JSON.stringify(content.carrossel_slides))}', '${esc(JSON.stringify(content.hashtags))}', '${esc(content.meta_title)}', '${esc(content.meta_description)}', '${esc(content.slug)}', 'agendado')`;\n\nreturn [{ json: { query } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        1072
      ],
      "name": "Save Summary Content",
      "id": "4796f4fc-b4ed-4ec0-a71c-ab48d413d925"
    },
    {
      "parameters": {
        "model": "sonar-pro",
        "messages": {
          "message": [
            {
              "content": "Voc\u00ea \u00e9 um pesquisador de not\u00edcias especializado em Intelig\u00eancia Artificial e tecnologia no Brasil. Retorne as 5 not\u00edcias mais importantes de IA das \u00faltimas 24 horas de fontes brasileiras e em portugu\u00eas. Foque em: lan\u00e7amentos de novos modelos de IA, an\u00fancios de grandes empresas de tecnologia, regulamenta\u00e7\u00e3o de IA no Brasil, artigos de pesquisa relevantes e parcerias que impactam o mercado brasileiro. Responda APENAS com um array JSON v\u00e1lido onde cada item tem: titulo (em portugu\u00eas), url, fonte, resumo (2-3 frases em portugu\u00eas). Priorize not\u00edcias de sites como Canaltech, Tecnoblog, Olhar Digital, StartSe, MIT Technology Review Brasil, e outros ve\u00edculos brasileiros de tecnologia.",
              "role": "system"
            },
            {
              "content": "={{ 'Encontre as \u00faltimas not\u00edcias de IA e tecnologia sobre: ' + $input.all().map(i => i.json.keyword).join(', ') + '. Foque em not\u00edcias das \u00faltimas 24 horas de fontes brasileiras e em portugu\u00eas.' }}"
            }
          ]
        },
        "options": {
          "maxTokens": 2000,
          "temperature": 0.2
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.perplexity",
      "typeVersion": 1,
      "position": [
        -320,
        288
      ],
      "name": "Message a model",
      "id": "867538a3-4b61-4c48-867a-f12eec992d86",
      "credentials": {
        "perplexityApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "google_news",
        "q": "={{ $input.all().map(i => i.json.keyword).join(' OR ') }}",
        "additionalFields": {
          "gl": "br",
          "hl": "pt"
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-serpapi.serpApi",
      "typeVersion": 1,
      "position": [
        -320,
        528
      ],
      "name": "Google_news search",
      "id": "473a25d1-a45a-4ab5-b35d-93dedf83c71b",
      "credentials": {
        "serpApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// ===========================================\n// NEWSLETTERS BRASILEIRAS DE TECH/IA PARA MONITORAR\n// Adicione ou remova endere\u00e7os conforme necess\u00e1rio\n// ===========================================\nconst senders = [\n  // --- Newsletters brasileiras de tecnologia ---\n  'newsletter@startse.com',\n  'contato@startse.com.br',\n  'inventormiguel@substack.com>'\n  // --- Newsletters de IA/dados em portugu\u00eas ---\n  \n  // --- Newsletters internacionais de IA (refer\u00eancia) ---\n  \n];\n\nconst query = 'from:(' + senders.join(' OR ') + ') newer_than:1d';\nreturn [{ json: { searchQuery: query, senders, senderCount: senders.length } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -592,
        -176
      ],
      "name": "Gmail Newsletter Config",
      "id": "c5165089-e596-4335-92d8-09d13a511a38"
    },
    {
      "parameters": {
        "operation": "getAll",
        "limit": 20,
        "filters": {
          "q": "={{ $json.searchQuery }}"
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        -320,
        -176
      ],
      "name": "Gmail Read Newsletters",
      "id": "f4982deb-af1e-4634-9ca0-2cbd75f63ce1",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const emails = $input.all();\nconst articles = [];\nconst seen = new Set();\n\nfor (const email of emails) {\n  const e = email.json;\n  const subject = e.subject || '';\n  const from = (e.from && typeof e.from === 'object' && e.from.value && e.from.value[0])\n    ? e.from.value[0].address\n    : (typeof e.from === 'string' ? e.from : 'Unknown');\n  const date = e.date || e.internalDate || new Date().toISOString();\n  const body = e.textPlain || e.snippet || '';\n  const html = e.textHtml || '';\n\n  const urlRegex = /https?:\\/\\/[^\\s<>\"'\\)\\]]+/g;\n  const allUrls = (html || body).match(urlRegex) || [];\n\n  const articleUrls = allUrls.filter(function(url) {\n    var lower = url.toLowerCase();\n    return lower.indexOf('unsubscribe') === -1 &&\n           lower.indexOf('manage-preferences') === -1 &&\n           lower.indexOf('click.') === -1 &&\n           lower.indexOf('tracking') === -1 &&\n           lower.indexOf('beacon') === -1 &&\n           lower.indexOf('mailchimp') === -1 &&\n           lower.indexOf('list-manage') === -1 &&\n           lower.indexOf('emailoctopus') === -1 &&\n           lower.indexOf('convertkit') === -1 &&\n           url.length < 300;\n  });\n\n  var uniqueUrls = [];\n  var urlPaths = new Set();\n  for (var u of articleUrls) {\n    try {\n      var parsed = new URL(u);\n      var key = parsed.hostname + parsed.pathname;\n      if (!urlPaths.has(key)) { urlPaths.add(key); uniqueUrls.push(u); }\n    } catch(ex) {}\n  }\n\n  if (uniqueUrls.length > 0) {\n    for (var url of uniqueUrls.slice(0, 5)) {\n      if (!seen.has(url)) {\n        seen.add(url);\n        articles.push({ json: {\n          titulo: subject,\n          url_fonte: url,\n          fonte: from,\n          fonte_tipo: 'gmail',\n          resumo_bruto: body.substring(0, 800),\n          data_noticia: date\n        }});\n      }\n    }\n  } else if (subject && !seen.has(subject)) {\n    seen.add(subject);\n    articles.push({ json: {\n      titulo: subject,\n      url_fonte: 'gmail://' + (e.id || Date.now()),\n      fonte: from,\n      fonte_tipo: 'gmail',\n      resumo_bruto: body.substring(0, 800),\n      data_noticia: date\n    }});\n  }\n}\n\nreturn articles.length > 0\n  ? articles\n  : [{ json: { titulo: '', url_fonte: '', fonte: 'gmail', fonte_tipo: 'gmail', resumo_bruto: '', data_noticia: new Date().toISOString() } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -32,
        -176
      ],
      "name": "Parse Gmail News",
      "id": "cbd0e616-031f-4c4f-a4f2-3e97480ef57d"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        256,
        176
      ],
      "name": "Merge With Gmail",
      "id": "f763913b-458d-41ef-942d-60983a5d57e8"
    },
    {
      "parameters": {
        "jsCode": "// Gera 4 itens, um por palavra-chave para busca no Unsplash\nconst data = $input.first().json;\nconst terms = data.searchTerms || ['intelig\u00eancia artificial', 'aprendizado de m\u00e1quina', 'ci\u00eancia de dados', 'inova\u00e7\u00e3o digital'];\n\nreturn terms.map((term, i) => ({\n  json: {\n    searchTerm: term,\n    slideIndex: i + 1,\n    coverImageUrl: data.coverImageUrl,\n    caption: data.caption,\n    articleId: data.articleId,\n    titulo: data.titulo\n  }\n}));"
      },
      "id": "carousel_keywords",
      "name": "Prepare Carousel Keywords",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        6688,
        656
      ]
    },
    {
      "parameters": {
        "url": "https://api.unsplash.com/search/photos",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "query",
              "value": "={{ $json.searchTerm }}"
            },
            {
              "name": "per_page",
              "value": "1"
            },
            {
              "name": "orientation",
              "value": "squarish"
            }
          ]
        },
        "options": {}
      },
      "id": "carousel_unsplash",
      "name": "Unsplash Carousel Search",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        6960,
        656
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Coleta todos os resultados do Unsplash + imagem de capa no formato carrossel\nconst unsplashResults = $input.all();\n\n// URL da imagem de capa (DALL-E/Unsplash)\nconst coverUrl = $('Prepare Carousel Keywords').first().json.coverImageUrl;\nconst caption = $('Prepare Carousel Keywords').first().json.caption;\nconst articleId = $('Prepare Carousel Keywords').first().json.articleId;\n\n// Monta array de itens do carrossel\nconst items = [];\n\n// Slide 1: Imagem de capa do DALL-E/Unsplash (imagem principal do artigo)\nitems.push({\n  json: {\n    image_url: coverUrl,\n    slideIndex: 0,\n    isCover: true,\n    caption: caption,\n    articleId: articleId\n  }\n});\n\n// Slides 2-5: Imagens do Unsplash\nfor (const result of unsplashResults) {\n  const photos = result.json.results || [];\n  if (photos.length > 0) {\n    // Usa tamanho regular (1080w) para Instagram\n    const url = photos[0].urls.regular || photos[0].urls.small;\n    items.push({\n      json: {\n        image_url: url,\n        slideIndex: items.length,\n        isCover: false,\n        caption: caption,\n        articleId: articleId\n      }\n    });\n  }\n}\n\n// Garante m\u00ednimo de 2 itens (m\u00ednimo para carrossel)\nif (items.length < 2) {\n  return [items[0]];\n}\n\nreturn items;"
      },
      "id": "carousel_build",
      "name": "Build Carousel Items",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        7232,
        656
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://graph.facebook.com/v21.0/1176594747652660/media",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "facebookGraphAppApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "image_url",
              "value": "={{ $json.image_url }}"
            },
            {
              "name": "is_carousel_item",
              "value": "true"
            }
          ]
        },
        "options": {}
      },
      "id": "carousel_upload",
      "name": "Instagram Upload Item",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        7504,
        656
      ],
      "credentials": {
        "facebookGraphAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Coleta todos os IDs de upload para criar o container do carrossel\nconst uploads = $input.all();\nconst childrenIds = uploads.map(u => u.json.id).filter(Boolean);\nconst caption = $('Build Carousel Items').first().json.caption;\nconst articleId = $('Build Carousel Items').first().json.articleId;\n\n// Se s\u00f3 tem 1 item, ser\u00e1 post simples (n\u00e3o carrossel)\nconst isCarousel = childrenIds.length >= 2;\n\nreturn [{\n  json: {\n    children: childrenIds,\n    childrenString: childrenIds.join(','),\n    caption: caption,\n    articleId: articleId,\n    isCarousel: isCarousel,\n    mediaCount: childrenIds.length\n  }\n}];"
      },
      "id": "carousel_collect",
      "name": "Collect Carousel IDs",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        7776,
        656
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://graph.facebook.com/v21.0/1176594747652660/media",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "facebookGraphAppApi",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "media_type",
              "value": "CAROUSEL"
            },
            {
              "name": "caption",
              "value": "={{ $json.caption }}"
            },
            {
              "name": "children",
              "value": "={{ $json.childrenString }}"
            }
          ]
        },
        "options": {}
      },
      "id": "carousel_create",
      "name": "Instagram Create Carousel",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        8048,
        656
      ],
      "credentials": {
        "facebookGraphAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://graph.facebook.com/v21.0/1176594747652660/media_publish",
        "authentication": "predefinedCredentialType",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "creation_id",
              "value": "={{ $json.id }}"
            }
          ]
        },
        "options": {},
        "nodeCredentialType": "facebookGraphAppApi"
      },
      "id": "carousel_publish",
      "name": "Instagram Publish Carousel",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        8320,
        656
      ],
      "credentials": {
        "facebookGraphAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "\n-- Desativar feeds em ingl\u00eas\nUPDATE rss_feeds SET ativa = false WHERE url LIKE '%openai.com%';\nUPDATE rss_feeds SET ativa = false WHERE url LIKE '%technologyreview.com%';\nUPDATE rss_feeds SET ativa = false WHERE url LIKE '%venturebeat.com%';\nUPDATE rss_feeds SET ativa = false WHERE url LIKE '%techcrunch.com%';\nUPDATE rss_feeds SET ativa = false WHERE url LIKE '%blog.google%';\nUPDATE rss_feeds SET ativa = false WHERE url LIKE '%wired.com%';\nUPDATE rss_feeds SET ativa = false WHERE url LIKE '%theverge.com%';\nUPDATE rss_feeds SET ativa = false WHERE url LIKE '%artificialintelligence-news.com%';\n\n-- Inserir feeds brasileiros de tecnologia/IA\nINSERT INTO rss_feeds (nome, url, categoria, prioridade, ativa) VALUES\n  ('Canaltech', 'https://canaltech.com.br/rss/', 'lancamentos', 10, true),\n  ('Tecnoblog', 'https://tecnoblog.net/feed/', 'lancamentos', 10, true),\n  ('Olhar Digital', 'https://olhardigital.com.br/feed/', 'lancamentos', 9, true),\n  ('TecMundo', 'https://www.tecmundo.com.br/rss', 'lancamentos', 9, true),\n  ('Gizmodo Brasil', 'https://gizmodo.uol.com.br/feed/', 'mercado', 8, true),\n  ('Startupi', 'https://startupi.com.br/feed/', 'mercado', 8, true),\n  ('Convergencia Digital', 'https://www.convergenciadigital.com.br/rss.xml', 'mercado', 7, true),\n  ('Inovacao Tecnologica', 'https://www.inovacaotecnologica.com.br/noticias/meta_rss.php', 'pesquisa', 7, true)\nON CONFLICT (url) DO UPDATE SET nome = EXCLUDED.nome, categoria = EXCLUDED.categoria, prioridade = EXCLUDED.prioridade, ativa = EXCLUDED.ativa;\n\n-- Verificar resultado\nSELECT nome, url, categoria, prioridade, ativa FROM rss_feeds ORDER BY prioridade DESC;",
        "options": {}
      },
      "id": "setup_rss_feeds",
      "name": "Setup RSS Feeds BR",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        -1440,
        -200
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Content Calendar Router",
            "type": "main",
            "index": 0
          },
          {
            "node": "Setup RSS Feeds BR",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Content Calendar Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Content Calendar Router": {
      "main": [
        [
          {
            "node": "Content Type Switch",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Brand Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Content Type Switch": {
      "main": [
        [
          {
            "node": "Fetch RSS Config",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Keywords",
            "type": "main",
            "index": 0
          },
          {
            "node": "Gmail Newsletter Config",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fetch Promo Content",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fetch Week Articles",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch RSS Config": {
      "main": [
        [
          {
            "node": "RSS Feed Reader",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Keywords": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          },
          {
            "node": "Google_news search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RSS Feed Reader": {
      "main": [
        [
          {
            "node": "Merge RSS + Perplexity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge RSS + Perplexity": {
      "main": [
        [
          {
            "node": "Merge All Sources",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge All Sources": {
      "main": [
        [
          {
            "node": "Merge With Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Data": {
      "main": [
        [
          {
            "node": "AI Curation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Curation": {
      "main": [
        [
          {
            "node": "Parse Curation Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Curation Results": {
      "main": [
        [
          {
            "node": "Score Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score Filter": {
      "main": [
        [
          {
            "node": "Check Dedup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Dedup": {
      "main": [
        [
          {
            "node": "Is New?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is New?": {
      "main": [
        [
          {
            "node": "Insert Article",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Article": {
      "main": [
        [
          {
            "node": "Select Best Article",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select Best Article": {
      "main": [
        [
          

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.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

IntelliX.AI - Editorial Automatizado v2. Uses postgres, rssFeedRead, openAi, httpRequest. Event-driven trigger; 62 nodes.

Source: https://github.com/fmbp1981-hash/intellixai/blob/8302af528cbc5516518420e1424e56e0a873bba3/n8n/workflow_v2.json — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This workflow auto-generates a personalized research report on any prospect who books a call with you—using their LinkedIn profile and advanced web research.

OpenAI, Gmail, Cal Trigger +3
AI & RAG

This workflow is for content creators, marketers, and agencies who want to use Veed.io’s AI avatar technology to produce short, engaging TikTok videos automatically. It’s ideal for creators who want t

Telegram Trigger, Perplexity, OpenAI +4
AI & RAG

Lead Research & Qualification - Phase 1. Uses httpRequest, openAi, googleSheets, gmail. Event-driven trigger; 22 nodes.

HTTP Request, OpenAI, Google Sheets +1
AI & RAG

Submit one or more Apple Podcast episode URLs via the built-in n8n form The workflow queries the iTunes API to retrieve each podcast's public RSS feed, then parses the XML to locate the matching episo

HTTP Request, Form Trigger, OpenAI +1
AI & RAG

This workflow scans an RSS blog feed on a schedule, logs newly found posts to Google Sheets, uses OpenAI to generate role-based LinkedIn drafts, and emails approval links via Gmail; approved drafts ar

Execute Workflow Trigger, Gmail, RSS Feed Read +4