{
  "name": "Fluxo gerente",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.3,
      "position": [
        -944,
        416
      ],
      "id": "dffbdc4f-4781-4e01-9c88-caa8da6bec81",
      "name": "Telegram Trigger",
      "retryOnFail": false,
      "maxTries": 2,
      "alwaysOutputData": false,
      "executeOnce": false,
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "24c69abe-2f78-426d-83c9-20d5ab1579f9",
              "leftValue": "={{ $json.message.text }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        -736,
        416
      ],
      "id": "cbf5c99d-d753-4021-a23d-0c43e906513f",
      "name": "If"
    },
    {
      "parameters": {
        "resource": "file",
        "fileId": "={{ $json.message.voice.file_id }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -528,
        512
      ],
      "id": "f4501938-8d75-4c7e-827f-5c62004ba3bf",
      "name": "Get a file",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "audio",
        "modelId": {
          "__rl": true,
          "value": "models/gemini-2.5-flash",
          "mode": "list",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "inputType": "binary",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "typeVersion": 1.2,
      "position": [
        -320,
        512
      ],
      "id": "b5aad8b9-6dc0-4a4d-8369-942031db9d9a",
      "name": "Transcribe a recording",
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a7661372-0350-486f-9b35-51225547394a",
              "name": "Mensagem",
              "value": "={{ $json.message.text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -528,
        320
      ],
      "id": "f788d925-e6a7-4a96-934d-372f6fe8b2e1",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a7661372-0350-486f-9b35-51225547394a",
              "name": "Mensagem",
              "value": "={{ $json.content.parts[0].text }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -128,
        512
      ],
      "id": "d57f3ee3-1171-4ea3-82c9-8d68595d2088",
      "name": "Edit Fields1"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.Mensagem }}",
        "options": {
          "systemMessage": "# Identidade\nVoc\u00ea \u00e9 a Sofia, Gerente de Atendimento da Hashtag Capital, um escrit\u00f3rio de assessoria de investimentos de alta performance.\n\nSua fun\u00e7\u00e3o \u00e9 EXCLUSIVAMENTE:\n1. Classificar a inten\u00e7\u00e3o do cliente com base na mensagem.\n2. Acionar a ferramenta (especialista) correspondente.\n3. Atuar como um espelho: A ferramenta vai gerar uma resposta. O seu trabalho \u00e9 pegar essa resposta e entreg\u00e1-la ao usu\u00e1rio exatamente como ela veio, sem tirar nem por.\n\n# Regra de Ouro (CR\u00cdTICO - Roteador Invis\u00edvel)\n- NUNCA responda com frases pr\u00f3prias como \"Vou verificar com o setor...\" ou \"Aguarde um momento\".\n- NUNCA narre o que voc\u00ea est\u00e1 fazendo.\n- NUNCA tente resolver o problema sozinho (exceto em sauda\u00e7\u00f5es simples).\n\nO cliente deve sentir que foi atendido imediatamente pelo especialista da \u00e1rea.\n\n# Seus Especialistas (Tools)\n1. AgenteFinanceiro:\n   - Assuntos: Financeiro, 2\u00aa via de boleto, pagamentos pendentes.\n   - A\u00e7\u00e3o: Use para quest\u00f5es operacionais e burocr\u00e1ticas (pagamentos).\n\n2. AgenteSuporte:\n   - Assuntos: D\u00favidas T\u00c9CNICAS e TE\u00d3RICAS de mercado financeiro. \"O que \u00e9 Selic?\", \"Como funciona FII?\", \"Diferen\u00e7a de CDB e LCI\", etc\n   - A\u00e7\u00e3o: Use para educa\u00e7\u00e3o financeira, tirar d\u00favidas de conceitos.\n\n3. AgenteCS:\n   - Assuntos: RELACIONAMENTO e AGENDAMENTO. \"Quero investir\", \"Marcar reuni\u00e3o\", \"Revisar carteira\", \"Falar com assessor\", \"Perfil de investidor\".\n   - A\u00e7\u00e3o: Use quando o cliente demonstra inten\u00e7\u00e3o de agir, investir ou quer contato humano.\n\n# Procedimento de Resposta\n1. Sauda\u00e7\u00e3o (Apenas \"Oi/Ol\u00e1\"): Se o usu\u00e1rio disser APENAS uma sauda\u00e7\u00e3o, responda: \"Ol\u00e1! Sou a Sofia, Gerente de Atendimento da Hashtag Capital. Posso te direcionar pra Assuntos Financeiros, D\u00favidas de Mercado (Suporte) ou Agendamento com Assessor. Como posso te ajudar hoje?\"\n\n2. Solicita\u00e7\u00e3o Espec\u00edfica: Se o usu\u00e1rio j\u00e1 enviou a d\u00favida, acione a ferramenta correspondente imediatamente.\n   - IMPORTANTE: O seu output final deve ser estritamente o texto retornado pela ferramenta.\n\n3. D\u00favida: Se n\u00e3o souber classificar, chame o `AgenteCS`.\n\n# TRATAMENTO DE ERRO (IMPORTANTE) Se a ferramenta (sub-agente) retornar a mensagem exata `##RESET##`, isso significa que ela n\u00e3o conseguiu resolver o pedido. NESSE CASO, N\u00c3O ENVIE `##RESET##` PARA O USU\u00c1RIO. Em vez disso, assuma o controle e responda: \"Desculpe, poderia explicar melhor sua d\u00favida?\"\n\nIMPORTANTE: Sua resposta final SEMPRE deve ser o texto retornado pelos seus Especialistas (Tools). Nunca responda com texto vazio.\n\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        80,
        176
      ],
      "id": "0e41543d-1c11-4a20-b977-eb869756a0ac",
      "name": "AI Agent",
      "retryOnFail": true,
      "maxTries": 2
    },
    {
      "parameters": {
        "modelName": "models/gemini-2.5-flash",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1.1,
      "position": [
        80,
        336
      ],
      "id": "28ec0787-9c16-48c0-89a4-94d7d7b06bb5",
      "name": "Google Gemini Chat Model",
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "contextWindowLength": 50
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.4,
      "position": [
        176,
        480
      ],
      "id": "aeaf4e37-4d26-4cf5-98be-dd62ea216316",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "description": "Especialista T\u00e9cnico e Tutor. Use para d\u00favidas t\u00e9cnicas",
        "workflowId": {
          "__rl": true,
          "value": "JrrvrUNJd2awJMDP",
          "mode": "list",
          "cachedResultUrl": "/workflow/JrrvrUNJd2awJMDP",
          "cachedResultName": "SubAgente Suporte a Duvidas"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "mensagem": "={{ $json.Mensagem }}",
            "ChatID": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "mensagem",
              "displayName": "mensagem",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            },
            {
              "id": "ChatID",
              "displayName": "ChatID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string",
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        0,
        0
      ],
      "id": "dcbee9bd-ac3e-44b6-848a-e7855700eaf2",
      "name": "Agente Suporte"
    },
    {
      "parameters": {
        "description": "Especialista em Financeiro. Use para boletos, 2a via, regulariza\u00e7\u00e3o de pagamento.",
        "workflowId": {
          "__rl": true,
          "value": "rhEitn6sk3Bb7yGq",
          "mode": "list",
          "cachedResultUrl": "/workflow/rhEitn6sk3Bb7yGq",
          "cachedResultName": "SubAgente FInanceiro"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "mensagem": "={{ $json.Mensagem }}",
            "ChatID": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "mensagem",
              "displayName": "mensagem",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            },
            {
              "id": "ChatID",
              "displayName": "ChatID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        160,
        0
      ],
      "id": "44e04faa-ec5d-44e8-983b-e00215982d26",
      "name": "Agente FInanceiro"
    },
    {
      "parameters": {
        "description": "Especialista em Sucesso do Cliente. Use para agendamentos e d\u00favidas institucionais.",
        "workflowId": {
          "__rl": true,
          "value": "jYvSCTpasAVzo7BQ",
          "mode": "list",
          "cachedResultUrl": "/workflow/jYvSCTpasAVzo7BQ",
          "cachedResultName": "SubAgente CS"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "mensagem": "={{ $json.Mensagem }}",
            "ChatID": "={{ $('Telegram Trigger').item.json.message.chat.id }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "mensagem",
              "displayName": "mensagem",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            },
            {
              "id": "ChatID",
              "displayName": "ChatID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        320,
        0
      ],
      "id": "1b2fad4a-c262-4104-943f-123f8e9896a3",
      "name": "SubAgente CS"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {
          "appendAttribution": false,
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        432,
        160
      ],
      "id": "f2b6e128-21d1-48cc-b78a-4e69d23c896a",
      "name": "Send a text message",
      "retryOnFail": true,
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get a file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a file": {
      "main": [
        [
          {
            "node": "Transcribe a recording",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe a recording": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Agente Suporte": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Agente FInanceiro": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "SubAgente CS": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "69a5f471-79cd-4e14-8362-2d950a779daf",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodeGroups": [],
  "id": "CTdW9YdgSWaUv9h7",
  "tags": [
    {
      "updatedAt": "2026-06-09T23:52:15.221Z",
      "createdAt": "2026-06-09T23:52:15.221Z",
      "id": "B4ukWVnwIRin4fDM",
      "name": "Hashtag"
    }
  ]
}