{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "empresa-research",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "id": "86ea7ff9-442a-45b2-945d-a294dff9b68f",
      "name": "Webhook"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n        \"success\": true,\n        \"message\": \"An\u00e1lise iniciada com sucesso\",\n        \"empresa\": \"={{ $('Edit Fields').item.json['\"empresa\"'] }}\",\n        \"documentUrl\": \"https://docs.google.com/document/d/{{ $('Google Docs').item.json.id }}/edit\",\n        \"documentId\": \"={{ $('Google Docs').item.json.id }}\",\n        \"timestamp\": \"={{ $('Edit Fields').item.json['\"timestamp\"'] }}\"\n      }",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        2040,
        0
      ],
      "id": "ff9b5364-13ae-46b1-aec8-f505fe8ee57e",
      "name": "Respond to Webhook"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "31c0b619-a3a5-4178-93af-b3611c5dbf51",
              "name": "\"empresa\"",
              "value": "={{ $json.body.empresa }}",
              "type": "string"
            },
            {
              "id": "9eb60aab-fdbb-48e8-8946-a065086011f1",
              "name": "\"timestamp\"",
              "value": "={{ $json.body.timestamp }}",
              "type": "string"
            },
            {
              "id": "7c500e36-9cd0-43ab-bea6-71a09c12692c",
              "name": "\"documentTitle\"",
              "value": "=An\u00e1lise -  {{ $json.body.empresa }} - {{ $now.format('DD HH:mm') }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ],
      "id": "98a2be06-f408-4c5d-9f7f-77bae149bae4",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "8f47ec9a-ea12-4960-8633-f358c73f7975",
              "name": "geminiAnalysis",
              "value": "=={{ $json.candidates[0].content.parts[0].text }}",
              "type": "string"
            },
            {
              "id": "312d859b-3ff4-49e1-884e-13659a70d42b",
              "name": "empresa",
              "value": "={{ $('Edit Fields').item.json.empresa }}",
              "type": "string"
            },
            {
              "id": "ab0c82f3-e2ae-476f-98ad-e6725099b72a",
              "name": "documentTitle",
              "value": "={{ $('Edit Fields').item.json.documentTitle }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1340,
        0
      ],
      "id": "9a5df26d-1e3c-44a6-b32f-8068c66b5059",
      "name": "Edit Fields1"
    },
    {
      "parameters": {
        "driveId": "=myDrive",
        "folderId": "={{ $json.id }}",
        "title": "={{ $('Edit Fields').item.json['\"documentTitle\"'] }}"
      },
      "type": "n8n-nodes-base.googleDocs",
      "typeVersion": 2,
      "position": [
        1680,
        0
      ],
      "id": "73687994-9507-4691-b164-897b794c29e8",
      "name": "Google Docs",
      "credentials": {
        "googleDocsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentURL": "={{ $json.id }}",
        "actionsUi": {
          "actionFields": [
            {
              "action": "insert",
              "text": "={{ $('Edit Fields1').item.json.geminiAnalysis }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.googleDocs",
      "typeVersion": 2,
      "position": [
        1860,
        0
      ],
      "id": "788247b4-160d-4c6b-b913-389b9f01a955",
      "name": "Google Docs1",
      "credentials": {
        "googleDocsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=<redacted-credential>",
        "sendHeaders": true,
        "specifyHeaders": "json",
        "jsonHeaders": "{\n  \n}",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "contents",
              "value": "={{ $('Edit Fields2').item.json.contents }}"
            },
            {
              "name": "generationConfig",
              "value": "={{ $('Edit Fields2').item.json.generationConfig[0] }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1160,
        0
      ],
      "id": "229e38ca-c925-4b57-a674-429628c67f53",
      "name": "HTTP Request"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "74b68604-4064-412f-b208-2e0ffb25975b",
              "name": "contents",
              "value": "={{   [         {           \"parts\": [             {               \"text\": \"Voc\u00ea \u00e9 um analista s\u00eanior de Investment Banking especializado no mercado brasileiro de capitais.Voc\u00ea receber\u00e1 dados, que devem ser analisados e tratados, sobre uma empresa brasileira listada na B3, incluindo:\\n1. **Dados Sobre a empresa** - Informa\u00e7\u00f5es sobre a empresa\\n2. **Dados de Cota\u00e7\u00e3o** (formatacaoQuote) - Informa\u00e7\u00f5es financeiras e de mercado\\n3. **Dados de Not\u00edcias** (formatacaoNews) - Not\u00edcias recentes sobre a empresa \\n---\\n\\n## DADOS RECEBIDOS:\\n ### \ud83d\udcca INFORMA\u00c7\u00d5ES DE COTA\u00c7\u00c3O:\\n '\"+ $json.formatacaoQuote + \"' \\n ### \ud83d\udcf0 NOT\u00cdCIAS COLETADAS: \\n '\"+ $json.formatacaoNews + \"'\\n\\n---\\n\\n## INSTRU\u00c7\u00d5ES DE PROCESSAMENTO:\\n\\n### \ud83d\udd0d An\u00e1lise das Not\u00edcias:\\n1. Avalie TODAS as not\u00edcias fornecidas no array articles\\n2. Selecione as 3 MAIS RELEVANTES baseado nos crit\u00e9rios:\\n   - Impacto financeiro direto na empresa\\n   - Relev\u00e2ncia operacional (resultados, projetos, mudan\u00e7as estrat\u00e9gicas)\\n   - Atualidade (priorize not\u00edcias mais recentes)\\n   - Fonte confi\u00e1vel (InfoMoney, Valor, Reuters, etc.)\\n3. Descarte not\u00edcias sobre:\\n   - Mercado geral sem men\u00e7\u00e3o espec\u00edfica da empresa\\n   - An\u00e1lises t\u00e9cnicas gen\u00e9ricas do Ibovespa\\n   - Not\u00edcias repetitivas ou similares\\n\\n### \ud83d\udcc8 An\u00e1lise da Cota\u00e7\u00e3o:\\n1. Extraia os dados mais relevantes do JSON de cota\u00e7\u00e3o\\n2. Calcule m\u00e9tricas importantes quando poss\u00edvel\\n3. Interprete os indicadores no contexto do mercado brasileiro\\n\\n---\\n\\n## ESTRUTURA OBRIGAT\u00d3RIA DO RELAT\u00d3RIO:\\n\\n# \ud83d\udcca AN\u00c1LISE EMPRESARIAL - {NOME_EMPRESA} ({TICKER})\\n\\n**Data da An\u00e1lise:** {DATA_ATUAL}  \\n**Ticker:** {TICKER}  \\n**Raz\u00e3o Social:** {NOME_COMPLETO}  \\n---\\n\\n## \ud83c\udfe2 PERFIL CORPORATIVO\\n\\n**Funda\u00e7\u00e3o:** {Ano e contexto}\\n**Sede:** {Localiza\u00e7\u00e3o}\\n**Principais Atividades:** {Core business detalhado}\\n**Posicionamento:** {Market share, ranking setorial}\\n**Modelo de Neg\u00f3cio:** {Revenue streams principais}\\n\\n---\\n\\n## \ud83d\udcb0 RESUMO FINANCEIRO\\n\\n**Pre\u00e7o Atual:** R$ {PRECO_ATUAL}  \\n**Varia\u00e7\u00e3o Di\u00e1ria:** {VARIACAO_PERCENTUAL}% ({VARIACAO_ABSOLUTA})  \\n**Abertura:** R$ {PRECO_ABERTURA}  \\n**M\u00e1xima do Dia:** R$ {MAXIMA_DIA}  \\n**M\u00ednima do Dia:** R$ {MINIMA_DIA}  \\n**Volume:** {VOLUME_FORMATADO}  \\n\\n**Varia\u00e7\u00e3o 52 Semanas:** R$ {MIN_52S} - R$ {MAX_52S}  \\n**Market Cap:** R$ {MARKET_CAP_FORMATADO}  \\n**P/L:** {PE_RATIO}  \\n**LPA:** R$ {EARNINGS_PER_SHARE}  \\n\\n---\\n\\n## \ud83d\udcc8 AN\u00c1LISE DE PERFORMANCE\\n\\n### Contexto Atual\\n{AN\u00c1LISE_DO_PRE\u00c7O_ATUAL_EM_RELA\u00c7\u00c3O_AOS_RANGES}\\n\\n### Indicadores T\u00e9cnicos\\n{INTERPRETA\u00c7\u00c3O_DOS_M\u00daLTIPLOS_E_M\u00c9TRICAS}\\n\\n---\\n\\n## \ud83d\udcf0 NOT\u00cdCIAS MAIS RELEVANTES\\n\\n### \ud83d\udd25 Not\u00edcia 1: {T\u00cdTULO_NOT\u00cdCIA_1}\\n**Data:** {DATA_NOT\u00cdCIA_1}  \\n**Link:** {LINK_NOT\u00cdCIA_1}  \\n**Resumo:** {RESUMO_EXECUTIVO_2_3_LINHAS}  \\n**Impacto:** {AN\u00c1LISE_DO_IMPACTO_PARA_INVESTIDORES}  \\n\\n### \ud83d\udcca Not\u00edcia 2: {T\u00cdTULO_NOT\u00cdCIA_2}  \\n**Data:** {DATA_NOT\u00cdCIA_2}  \\n**Link:** {LINK_NOT\u00cdCIA_2}  \\n**Resumo:** {RESUMO_EXECUTIVO_2_3_LINHAS}  \\n**Impacto:** {AN\u00c1LISE_DO_IMPACTO_PARA_INVESTIDORES}  \\n\\n### \ud83d\udcbc Not\u00edcia 3: {T\u00cdTULO_NOT\u00cdCIA_3}\\n**Data:** {DATA_NOT\u00cdCIA_3}  \\n**Link:** {LINK_NOT\u00cdCIA_3}  \\n**Resumo:** {RESUMO_EXECUTIVO_2_3_LINHAS}  \\n**Impacto:** {AN\u00c1LISE_DO_IMPACTO_PARA_INVESTIDORES}  \\n\\n---\\n\\n## \ud83c\udfaf AN\u00c1LISE INTEGRADA\\n\\n### S\u00edntese dos Dados\\n{COMBINE_INFORMA\u00c7\u00d5ES_DE_COTA\u00c7\u00c3O_E_NOT\u00cdCIAS_PARA_CRIAR_UMA_VIS\u00c3O_HOL\u00cdSTICA}\\n\\n### Pontos de Aten\u00e7\u00e3o\\n- {RISCOS_IDENTIFICADOS_NAS_NOT\u00cdCIAS}\\n- {OPORTUNIDADES_IDENTIFICADAS}\\n- {FATORES_T\u00c9CNICOS_RELEVANTES}\\n\\n### Catalisadores Potenciais\\n- {EVENTOS_FUTUROS_MENCIONADOS_NAS_NOT\u00cdCIAS}\\n- {MARCOS_T\u00c9CNICOS_IMPORTANTES}\\n\\n---\\n\\n##!DISCLAIMERS\\n\\n- **Dados de Mercado:** Baseados na \u00faltima sess\u00e3o dispon\u00edvel\\n- **Not\u00edcias:** Selecionadas por relev\u00e2ncia e impacto potencial  \\n- **N\u00e3o \u00e9 Recomenda\u00e7\u00e3o:** Este documento \u00e9 apenas informativo\\n- **Verifica\u00e7\u00e3o:** Recomenda-se confirma\u00e7\u00e3o em fontes oficiais\\n- **Risco:** Todo investimento envolve riscos\\n\\n---\\n\\n**Relat\u00f3rio Gerado por:** Sistema Automatizado de Investment Banking  \\n**Modelo:** Gemini 1.5 Flash  \\n**Timestamp:** {TIMESTAMP_GERACAO}\\n\\n---\\n\\n## REGRAS CR\u00cdTICAS:\\n\\n###**DEVE FAZER:**\\n- Usar APENAS dados fornecidos, excluindo a se\u00e7\u00e3o \\\"\ud83c\udfe2 PERFIL CORPORATIVO\\\" que deve buscar informa\u00e7\u00f5es sobre\\n- Formatar valores monet\u00e1rios em Real brasileiro (R$)\\n- Datar todas as informa\u00e7\u00f5es adequadamente\\n- Focar em aspectos relevantes para Investment Banking\\n- Manter linguagem t\u00e9cnica e profissional\\n- Quantificar impactos quando poss\u00edvel\\n\\n###**N\u00c3O DEVE FAZER:**\\n- Inventar dados n\u00e3o presentes\\n- Fazer recomenda\u00e7\u00f5es de compra/venda\\n- Usar informa\u00e7\u00f5es de fontes externas aos dados fornecidos\\n- Repetir not\u00edcias com conte\u00fado similar\\n- Incluir an\u00e1lises especulativas sem base nos dados\\n\\n### **CRIT\u00c9RIOS PARA SELE\u00c7\u00c3O DE NOT\u00cdCIAS:**\\n\\n**Prioridade Alta:**\\n- Resultados trimestrais/anuais\\n- Dividendos e proventos\\n- Mudan\u00e7as na gest\u00e3o\\n- Grandes investimentos/desinvestimentos\\n- Aquisi\u00e7\u00f5es/fus\u00f5es\\n- Aprova\u00e7\u00f5es regulat\u00f3rias importantes\\n\\n**Prioridade M\u00e9dia:**\\n- An\u00e1lises de bancos de investimento\\n- Mudan\u00e7as de rating\\n- Not\u00edcias setoriais espec\u00edficas\\n- Parcerias estrat\u00e9gicas\\n\\n**Prioridade Baixa:**\\n- Not\u00edcias do mercado geral\\n- An\u00e1lises t\u00e9cnicas do Ibovespa\\n- Coment\u00e1rios gen\u00e9ricos sobre o setor\\n\\n---\\n\\n## EXEMPLO DE FORMATA\u00c7\u00c3O DE VALORES:\\n\\n- **Monetary:** R$ 32,53 (n\u00e3o $32.53)\\n- **Percentage:** +2,46% (n\u00e3o 2.46%)\\n- **Volume:** 74,8 milh\u00f5es (n\u00e3o 74819900)\\n- **Market Cap:** R$ 400,6 bilh\u00f5es (n\u00e3o 400583262534)\\n\\n---\\n\\n**EXECUTE A AN\u00c1LISE AGORA COM OS DADOS FORNECIDOS.** Caso os dados n\u00e3o aparecem de forma clara, apresente no final do documento como eles foram apresentados\"             }           ]         }       ] }}",
              "type": "array"
            },
            {
              "id": "11f406b1-7cfa-43c4-9aa4-ad611699aff6",
              "name": "=generationConfig",
              "value": "={{ [{         \"temperature\": 0.3,         \"maxOutputTokens\": 2048,         \"topP\": 0.8,         \"topK\": 40       }] }}",
              "type": "array"
            },
            {
              "id": "305a0600-d10c-4590-9b85-47dc2727c1c2",
              "name": "teste",
              "value": "={{ $json.formatacaoNews }}",
              "type": "string"
            },
            {
              "id": "1717a0e8-42bd-4bdc-9b76-024ad7cec2de",
              "name": "teste",
              "value": "={{ $json.formatacaoQuote }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        980,
        0
      ],
      "id": "af1a6685-d118-4a44-8d1b-131878de20cd",
      "name": "Edit Fields2"
    },
    {
      "parameters": {
        "url": "https://generativelanguage.googleapis.com/v1beta/models?key=<redacted-credential>",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1140,
        320
      ],
      "id": "8e1ad557-59ee-498c-b165-704ddf4776f4",
      "name": "HTTP Request1"
    },
    {
      "parameters": {
        "resource": "folder",
        "name": "={{ $('Edit Fields').item.json['\"empresa\"'] }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "value": "1H2kob3X-wW5IUp2C11yngi4_zplU6hT-",
          "mode": "list",
          "cachedResultName": "projetoEstagio",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1H2kob3X-wW5IUp2C11yngi4_zplU6hT-"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1500,
        0
      ],
      "id": "97de815a-efc1-42c7-a06e-2dd8ded95a83",
      "name": "Google Drive",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "= https://brapi.dev/api/quote/{{ $('Edit Fields').item.json['\"empresa\"'] }}",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "token",
              "value": "=75n89yAs7bAXEnv3qhUmYG"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ],
      "id": "9a618cb4-cdd0-41f0-8494-224528de3348",
      "name": "BRAPI-QUOTE"
    },
    {
      "parameters": {
        "url": "=https://newsapi.org/v2/everything",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "q",
              "value": "={{ $('Edit Fields').item.json['\"empresa\"'] }}"
            },
            {
              "name": "language",
              "value": "=pt"
            },
            {
              "name": "sortBy",
              "value": "publishedAt"
            },
            {
              "name": "apiKey",
              "value": "435135c72b464258b4f0d8ccff7906cf"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        640,
        0
      ],
      "id": "c7197e56-a5ce-4313-9de1-9605d772106b",
      "name": "NEWSAPI-NEWS"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "cef7bd22-ee59-4379-b8cd-3a1265e6ee6d",
              "name": "formatacaoNews",
              "value": "={{ $json.articles }}",
              "type": "string"
            },
            {
              "id": "e334ec39-e94d-4ad7-bef7-25c30b2485a6",
              "name": "formatacaoQuote",
              "value": "={{ $('BRAPI-QUOTE').item.json.results }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        820,
        0
      ],
      "id": "492e7c9d-654a-484c-adf6-601299b33fa6",
      "name": "Edit Fields3"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "BRAPI-QUOTE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Docs": {
      "main": [
        [
          {
            "node": "Google Docs1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Docs1": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields2": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        []
      ]
    },
    "Google Drive": {
      "main": [
        [
          {
            "node": "Google Docs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "BRAPI-QUOTE": {
      "main": [
        [
          {
            "node": "NEWSAPI-NEWS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NEWSAPI-NEWS": {
      "main": [
        [
          {
            "node": "Edit Fields3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields3": {
      "main": [
        [
          {
            "node": "Edit Fields2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e608c1c4-f1cb-4752-abad-5d737da39203",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "J5XzbIICEwZTFscv",
  "tags": []
}