{
  "name": "AI Sales Development Representative for WhatsApp Leads",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "agente-sdr-aula",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "id": "eabb60eb-c6d5-403c-bdc7-217f88df976d",
      "name": "Webhook"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e24f58e4-1091-41fa-95f7-cff0e11cf528",
              "name": "cliente.nome",
              "value": "={{ $json.body.data.pushName }}",
              "type": "string"
            },
            {
              "id": "d20d8242-b2d4-4a06-bba4-d25d2e8c2d26",
              "name": "cliente.telefone",
              "value": "={{ $json.body.data.key.remoteJid }}",
              "type": "string"
            },
            {
              "id": "27ee2201-1965-4bdb-8b53-abbee5b16286",
              "name": "wpp.intancia",
              "value": "={{ $json.body.instance }}",
              "type": "string"
            },
            {
              "id": "c0c64901-60d5-482f-9742-bc385140e33a",
              "name": "wpp.apikey",
              "value": "={{ $json.body.apikey }}",
              "type": "string"
            },
            {
              "id": "4b337932-d2dc-400c-acd1-83adcbf378e4",
              "name": "wpp.url",
              "value": "={{ $json.body.server_url }}",
              "type": "string"
            },
            {
              "id": "eb1932ca-060d-48af-9f14-3f6ece31e4be",
              "name": "empresa.nome",
              "value": "GgNocode",
              "type": "string"
            },
            {
              "id": "381487a6-772f-4bc1-a6af-d42df0d2bf64",
              "name": "empresa.docid",
              "value": "",
              "type": "string"
            },
            {
              "id": "798183f6-caf3-4611-bab0-38913ccdb22b",
              "name": "content.tipoMensagem",
              "value": "={{ $json.body.data.messageType }}",
              "type": "string"
            },
            {
              "id": "9f07798b-2b48-4b86-9143-06eac60b7744",
              "name": "content.mensagem",
              "value": "={{    $json.body?.content ||     $json.body?.data?.message?.extendedTextMessage?.text ||    $json.body?.data?.message?.imageMessage?.caption ||    $json.body?.data?.message?.conversation ||    $json?.message?.text ||    $json?.message?.caption ||    null  }}",
              "type": "string"
            },
            {
              "id": "e162b5ef-e7a3-4db1-aa65-5cb8f6f62c7f",
              "name": "content.idmensagem",
              "value": "={{ $json.body.data.key.id }}",
              "type": "string"
            },
            {
              "id": "9b440c0f-f590-4061-80c7-26d710c51215",
              "name": "Digitando",
              "value": 1500,
              "type": "number"
            },
            {
              "id": "f900ce72-edef-4826-86b0-c502c8c3bd9c",
              "name": "debouncerTime",
              "value": "4",
              "type": "string"
            },
            {
              "id": "c1c329f2-2686-4c0d-917b-44c1338564fb",
              "name": "linkpreview",
              "value": false,
              "type": "boolean"
            },
            {
              "id": "fd9e68ae-2f2f-4a64-a043-d575b7b3f184",
              "name": "fromMe",
              "value": "={{ $json.body.data.key.fromMe }}",
              "type": "boolean"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        500,
        0
      ],
      "id": "52532daa-31be-41c5-946d-0e335ad7fcf2",
      "name": "setData"
    },
    {
      "parameters": {
        "content": "## SUPABASE - CRIAR CLIENTE",
        "height": 920,
        "width": 1580,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1580,
        -220
      ],
      "typeVersion": 1,
      "id": "38f012f4-7251-4408-ba09-c27a181a0abc",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "bad2727f-0bac-45ae-9c60-33151d25bb36",
              "leftValue": "={{ $json.fromMe }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            },
            {
              "id": "aea6ee11-cde5-4514-b4e1-f54488f7ab89",
              "leftValue": "={{ $json.cliente.telefone }}",
              "rightValue": "553195495346@s.whatsapp.net",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1060,
        20
      ],
      "id": "71d41996-4beb-409a-bc2e-bfed060f17e0",
      "name": "If"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1220,
        320
      ],
      "id": "f1ebe8e0-38f2-4c1b-9b32-dff680d6dc60",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "operation": "get",
        "tableId": "SDR - LEADS",
        "filters": {
          "conditions": [
            {
              "keyName": "telefone",
              "keyValue": "={{ $json.cliente.telefone }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        1760,
        0
      ],
      "id": "7c35fdd4-96f2-4fea-b4d6-dc0a6a8ab074",
      "name": "buscarCliente",
      "alwaysOutputData": true,
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "tableId": "SDR - LEADS",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "created_at",
              "fieldValue": "={{ $now.setZone('America/Sao_Paulo') }}"
            },
            {
              "fieldId": "nome",
              "fieldValue": "={{ $('setData').item.json.cliente.nome }}"
            },
            {
              "fieldId": "telefone",
              "fieldValue": "={{ $('setData').item.json.cliente.telefone }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        2280,
        400
      ],
      "id": "c98a76de-0112-4e1b-845a-6405f2217b81",
      "name": "criarCliente",
      "alwaysOutputData": true,
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "92e64e75-2da4-4c10-8582-332bf99faa7c",
              "leftValue": "={{ $json.telefone }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2100,
        0
      ],
      "id": "0ac899fd-1ecf-4a66-a49b-0e263a5ab25d",
      "name": "If1"
    },
    {
      "parameters": {
        "operation": "get",
        "tableId": "SDR - LEADS",
        "filters": {
          "conditions": [
            {
              "keyName": "telefone",
              "keyValue": "={{ $item(\"0\").$node[\"setData\"].json[\"cliente\"][\"telefone\"] }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        2480,
        -20
      ],
      "id": "32790424-987f-41a2-98e5-6ffbe5ca2d49",
      "name": "verificaHumano",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "6df5a03e-fa3f-4d60-bcc5-c73e48541b5c",
              "leftValue": "={{ $json.atende_humano }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2900,
        -20
      ],
      "id": "3b531ad2-b5ce-417e-91fd-2d1c63d50426",
      "name": "If2"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        2920,
        500
      ],
      "id": "c5fd6a11-eb16-42b8-9fc0-7fd728ffca1f",
      "name": "No Operation, do nothing1"
    },
    {
      "parameters": {
        "content": "## FILTRO MENSAGEM",
        "height": 680,
        "width": 1560,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3200,
        -220
      ],
      "typeVersion": 1,
      "id": "c4ce81e9-e28d-4def-9397-8ec844c46eac",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $('setData').item.json.content.tipoMensagem }}",
                    "rightValue": "audioMessage",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "\u00c1udio"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "f2624b9f-9f23-44b4-9058-ae409a348edb",
                    "leftValue": "={{ $('setData').item.json.content.tipoMensagem }}",
                    "rightValue": "conversation",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Texto"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "dbdd84a4-fb78-4cff-9af6-997c42a77710",
                    "leftValue": "={{ $('setData').item.json.content.tipoMensagem }}",
                    "rightValue": "imageMessage",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Imagem"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        3300,
        40
      ],
      "id": "9f50a687-fd9b-42cb-8049-95a29672f359",
      "name": "Switch"
    },
    {
      "parameters": {
        "operation": "push",
        "list": "={{ $('setData').item.json.cliente.telefone }}",
        "messageData": "={{ $('setData').item.json.content.mensagem }}"
      },
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        3700,
        40
      ],
      "id": "13f4048e-bb9b-4974-b861-36212a765108",
      "name": "memoriaTexto",
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "get",
        "key": "={{ $('setData').item.json.cliente.telefone }}",
        "options": {}
      },
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        3920,
        40
      ],
      "id": "dbeabf59-73db-4041-acd9-eed5fc1f0c0e",
      "name": "pegaMemoria1",
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "amount": 1
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        4180,
        40
      ],
      "id": "554306f7-ac15-450f-a462-c41d3889ceac",
      "name": "Wait"
    },
    {
      "parameters": {
        "operation": "get",
        "key": "={{ $('setData').item.json.cliente.telefone }}",
        "options": {}
      },
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        4420,
        40
      ],
      "id": "650425c1-9def-476e-9e2f-1f6b58e9dbb1",
      "name": "pegaMemoria2",
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## SETAR MEMORIA",
        "height": 680,
        "width": 1180,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4840,
        -220
      ],
      "typeVersion": 1,
      "id": "4e9c85b5-19fc-4e3a-8f53-2314870c40a3",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "42d005b6-2275-48d4-afe3-06051a3f5a7a",
              "name": "Redis1",
              "value": "={{ $('pegaMemoria1').item.json.propertyName }}",
              "type": "string"
            },
            {
              "id": "a6a21ccf-bb0f-42cb-97d2-db0a069a0672",
              "name": "Redis2",
              "value": "={{ $json.propertyName }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        5000,
        40
      ],
      "id": "24c658a4-6a89-45dd-910c-6b117d194091",
      "name": "setarMemoria"
    },
    {
      "parameters": {
        "jsCode": "const data = $item(0).$node[\"comparaMemoria\"].json[\"Redis2\"]; // Obt\u00e9m o valor de Redis2 do n\u00f3 \"If\"\n\n// Verifica se o dado \u00e9 uma string que representa um array, e converte se necess\u00e1rio\nlet array = Array.isArray(data) ? data : JSON.parse(data);\n\n// Junta os elementos do array com um espa\u00e7o entre eles\nconst mensagem_completa = array.join(\" \");\n\n// Retorna o resultado com o nome da vari\u00e1vel \"mensagem_completa\"\nreturn [{ json: { mensagem_completa } }];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        5760,
        40
      ],
      "id": "889a88c1-861e-4178-8d97-9cdcb384b8e5",
      "name": "Code"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "5ce40b6a-5b2c-462f-ad60-2676bd8cba16",
              "leftValue": "={{ $json.Redis2 }}",
              "rightValue": "={{ $json.Redis1 }}",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        5380,
        40
      ],
      "id": "b61f73a0-d732-4d27-98e5-d113ab347513",
      "name": "comparaMemoria"
    },
    {
      "parameters": {
        "content": "## AGENTE DE IA",
        "height": 1420,
        "width": 2360,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6140,
        -220
      ],
      "typeVersion": 1,
      "id": "ac213c5e-b578-4039-b037-b6fa55d54f0a",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "74d7598b-4d50-4e32-b4f5-25085cf80eea",
              "name": "mensagem",
              "value": "={{ $json.mensagem_completa }}",
              "type": "string"
            },
            {
              "id": "a74fe73b-8a53-4a59-9d75-0caebf4adb9c",
              "name": "sessionId",
              "value": "={{ $('setData').item.json.cliente.telefone }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        6360,
        20
      ],
      "id": "aa28690d-c9ba-427b-ba1e-032615b5dbaa",
      "name": "setarAgente"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.mensagem }}",
        "options": {
          "systemMessage": "=<AgentInstructions>\n    <Role>\n        <Name>Fernanda</Name>\n        <Description>Sou Fernanda, assistente virtual da GGnocode. Meu papel \u00e9 qualificar leads interessados em automa\u00e7\u00e3o e direcion\u00e1-los para os setores adequados da empresa.</Description>\n        <currentDate>{{$now.setZone('America/Sao_Paulo')}}</currentDate>\n    </Role>\n    \n    <Goal>\n        <Primary>Qualificar leads usando o m\u00e9todo BANT e encaminh\u00e1-los corretamente para agendamento de reuni\u00e3o ou outro setor respons\u00e1vel.</Primary>\n    </Goal>\n    \n    <Instructions>\n        <Instruction> SEMPRE INICIAR A CONVERSA com a seguinte mensagem de sauda\u00e7\u00e3o: \"Oi Germano, sou a Fernanda, assistente da GGnocode! Notei que voc\u00ea quer saber mais sobre nossos servi\u00e7os de automa\u00e7\u00e3o. \ud83d\ude80 A equipe pediu para eu entrar em contato com voc\u00ea para fazer algumas perguntas r\u00e1pidas e ajud\u00e1-lo a se preparar da melhor forma poss\u00edvel para uma sess\u00e3o estrat\u00e9gica com um dos nossos especialistas. Voc\u00ea tem um tempinho para uma conversa r\u00e1pida?\"</Instruction>\n        <Instruction>Perguntar sobre o or\u00e7amento dispon\u00edvel para automa\u00e7\u00e3o e informar que os servi\u00e7os come\u00e7am a partir de R$ 3.000.</Instruction>\n        <Instruction>Verificar quem toma a decis\u00e3o na empresa e sugerir a presen\u00e7a do(s) decisor(es) na reuni\u00e3o.</Instruction>\n        <Instruction>Entender a necessidade espec\u00edfica do lead e qual desafio ele quer resolver com automa\u00e7\u00e3o.</Instruction>\n        <Instruction>Questionar sobre o prazo para implementa\u00e7\u00e3o e urg\u00eancia do projeto.</Instruction>\n        <Instruction>Se o lead for qualificado (aceita o or\u00e7amento e tem necessidade real), usar a ferramenta de agendamento para marcar a reuni\u00e3o com um especialista.</Instruction>\n        <Instruction>Se o lead n\u00e3o for qualificado, utilizar a ferramenta para atualizar o cadastro no Supabase e encaminhar para o setor apropriado.</Instruction>\n    </Instructions>\n\n<Tools>\n    <Tool> Atendimento Humano: Utilize esta tool APENAS COMO \u00daLTIMA OP\u00c7\u00c3O quando o cliente pedir por um atendente ou atendimento humano.</Tool>\n\n    <Tool> Criar Card Trello: Utilize esta tool ao final da conversa depois que tiver todos os dados do cliente prontos para reuni\u00e3o.</Tool>\n\n    <Tool> Atualizar Cadastro: Utilize esta tool para atualizar o cadastro do cliente no nosso banco de dados inserindo o email e tipo de automa\u00e7\u00e3o do cliente quando ele disponibilizar estes dados.</Tool>\n</AgentInstructions>\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        6940,
        20
      ],
      "id": "c00292f4-b755-4d67-8e53-26f70ce0ddb9",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        6280,
        620
      ],
      "id": "9f654d84-b03d-4d2c-9bee-287b980b8a2f",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ (() => {\n  const sessionId = $('setarAgente').item.json.sessionId; // Pega o valor do sessionId do n\u00f3 \"setarAgente\"\n  return sessionId ? sessionId : \"session-id-padrao\"; // Retorna sessionId ou valor padr\u00e3o\n})() }}\n",
        "contextWindowLength": 30
      },
      "type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
      "typeVersion": 1.4,
      "position": [
        6660,
        660
      ],
      "id": "3c062fc4-281f-4804-9506-9c7259fd0c4a",
      "name": "Redis Chat Memory",
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('setData').item.json.wpp.url }}/message/sendText/{{ $('setData').item.json.wpp.intancia }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{ $('setData').item.json.cliente.telefone }}"
            },
            {
              "name": "text",
              "value": "={{ $json.output }}"
            },
            {
              "name": "linkPreview",
              "value": "={{ $('setData').item.json.linkpreview }}"
            },
            {
              "name": "delay",
              "value": "={{ $('setData').item.json.Digitando }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        7760,
        0
      ],
      "id": "0e214a2c-4933-4548-a4e8-6bc0a32fbbd8",
      "name": "RESPOSTA AGENTE",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "delete",
        "key": "={{ $('setData').item.json.cliente.telefone }}"
      },
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        8280,
        0
      ],
      "id": "87a53ead-eb4b-4f88-bcf3-eda7b37ee8b5",
      "name": "Redis",
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Quando o usu\u00e1rio solicitar atendimento humano voc\u00ea deve ativar esta tool e alterar o campo de \"atende_humano\" do supabase para \"true\"",
        "operation": "update",
        "tableId": "SDR - LEADS",
        "filters": {
          "conditions": [
            {
              "keyName": "telefone",
              "condition": "eq",
              "keyValue": "={{ $('setData').item.json.cliente.telefone }}"
            }
          ]
        },
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "atende_humano",
              "fieldValue": "={{ $fromAI('atendimento_humano', 'identifica se o cliente precisa de atendimento humano e alterar o campo boolean para true') }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabaseTool",
      "typeVersion": 1,
      "position": [
        7080,
        640
      ],
      "id": "035aeae0-f3bb-44a9-ba66-01f28dced8dd",
      "name": "Atendimento Humano",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## WEBHOOK + TRATAMENTO DE DADOS",
        "height": 500,
        "width": 840,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -60,
        -220
      ],
      "typeVersion": 1,
      "id": "45f54421-c1a9-4d5c-a792-bb845a3e9ff0",
      "name": "Sticky Note4"
    },
    {
      "parameters": {
        "content": "### ALTERE O NOME E INFORMA\u00c7\u00d5ES DA EMPRESA",
        "height": 260,
        "width": 280,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        -100
      ],
      "typeVersion": 1,
      "id": "262912d4-3f67-4a06-a3a5-8f2bdf2f544c",
      "name": "Sticky Note5"
    },
    {
      "parameters": {
        "content": "## FILTRO PARA SOMENTE 1 N\u00daMERO FALAR COM O AGENTE\n\n### Se for utilizar para produ\u00e7\u00e3o tire ou desative este passo.\n### Voc\u00ea tamb\u00e9m pode utilizar este filtro para travar o agente manualmente.",
        "height": 740,
        "width": 600
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        840,
        -220
      ],
      "typeVersion": 1,
      "id": "5463291e-4479-4498-a3ff-d1ffdadf4562",
      "name": "Sticky Note6"
    },
    {
      "parameters": {
        "content": "### BUSCAR CLIENTE",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1680,
        -80
      ],
      "typeVersion": 1,
      "id": "73fde3a1-67da-4228-ac8f-3cc21b4eec96",
      "name": "Sticky Note7"
    },
    {
      "parameters": {
        "content": "### CRIAR CLIENTE",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2200,
        320
      ],
      "typeVersion": 1,
      "id": "75f3d10a-18f6-46cf-ad1e-69bcacfeb8bf",
      "name": "Sticky Note8"
    },
    {
      "parameters": {
        "content": "### VERIFICA O ATENDE_HUMANO",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2380,
        -80
      ],
      "typeVersion": 1,
      "id": "b322e76d-af64-4302-8be0-50162108db5b",
      "name": "Sticky Note9"
    },
    {
      "parameters": {
        "content": "### AGUARDA PARA VER SE O USU\u00c1RIO ENVIA MAIS DE UMA MENSAGEM",
        "height": 260,
        "width": 1000,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3600,
        -40
      ],
      "typeVersion": 1,
      "id": "63fdc4ca-26da-4694-8e53-7c65d1dbe77d",
      "name": "Sticky Note10"
    },
    {
      "parameters": {
        "content": "### TRATAMENTO DE DADOS",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4920,
        -40
      ],
      "typeVersion": 1,
      "id": "afad8fb8-8efc-460d-9207-0a6dcf898aaa",
      "name": "Sticky Note11"
    },
    {
      "parameters": {
        "content": "### COMPARA MEM\u00d3RIA 1 E 2",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5300,
        -40
      ],
      "typeVersion": 1,
      "id": "477efe0b-5529-45e0-9be4-8825c169bd0c",
      "name": "Sticky Note12"
    },
    {
      "parameters": {
        "content": "### TIRA DUPLICA\u00c7\u00c3O E PREPARA PARA O AGENTE",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5680,
        -40
      ],
      "typeVersion": 1,
      "id": "7e911773-acc8-45dd-9321-4b0e8c5ae35d",
      "name": "Sticky Note13"
    },
    {
      "parameters": {
        "content": "### LLM - GPT",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6180,
        540
      ],
      "typeVersion": 1,
      "id": "0325604d-bba1-4ceb-b7be-ccf4363d5ede",
      "name": "Sticky Note14"
    },
    {
      "parameters": {
        "content": "### MEM\u00d3RIA",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6560,
        580
      ],
      "typeVersion": 1,
      "id": "2635cafd-7449-46fc-b47c-5bab91ea3e6f",
      "name": "Sticky Note15"
    },
    {
      "parameters": {
        "content": "### TOOL 1",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6980,
        560
      ],
      "typeVersion": 1,
      "id": "15922c52-1db9-470b-af71-023abf4ed9e7",
      "name": "Sticky Note16"
    },
    {
      "parameters": {
        "content": "### RESPONDE WHATSAPP",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7680,
        -60
      ],
      "typeVersion": 1,
      "id": "7444616a-575a-4d72-a28d-29ad7c48064a",
      "name": "Sticky Note17"
    },
    {
      "parameters": {
        "content": "```\n....###.....######...########.##....##.########.########.....######..########..########.\n...##.##...##....##..##.......###...##....##....##..........##....##.##.....##.##.....##\n..##...##..##........##.......####..##....##....##..........##.......##.....##.##.....##\n.##.....##.##...####.######...##.##.##....##....######.......######..##.....##.########.\n.#########.##....##..##.......##..####....##....##................##.##.....##.##...##..\n.##.....##.##....##..##.......##...###....##....##..........##....##.##.....##.##....##.\n.##.....##..######...########.##....##....##....########.....######..########..##.....##\n```",
        "width": 920,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3300,
        -620
      ],
      "typeVersion": 1,
      "id": "c03c36ca-e46b-46ef-8114-c723a8424165",
      "name": "Sticky Note18"
    },
    {
      "parameters": {
        "content": "```\n_____/\\\\\\\\\\\\\\\\\\\\\\\\_____/\\\\\\\\\\\\\\\\\\\\\\\\____________/\\\\\\\\\\_____/\\\\\\_______/\\\\\\\\\\_____________/\\\\\\\\\\\\\\\\\\_______/\\\\\\\\\\_______/\\\\\\\\\\\\\\\\\\\\\\\\_____/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_        \n ___/\\\\\\//////////____/\\\\\\//////////____________\\/\\\\\\\\\\\\___\\/\\\\\\_____/\\\\\\///\\\\\\________/\\\\\\////////______/\\\\\\///\\\\\\____\\/\\\\\\////////\\\\\\__\\/\\\\\\///////////__       \n  __/\\\\\\______________/\\\\\\_______________________\\/\\\\\\/\\\\\\__\\/\\\\\\___/\\\\\\/__\\///\\\\\\____/\\\\\\/_____________/\\\\\\/__\\///\\\\\\__\\/\\\\\\______\\//\\\\\\_\\/\\\\\\_____________      \n   _\\/\\\\\\____/\\\\\\\\\\\\\\_\\/\\\\\\____/\\\\\\\\\\\\\\___________\\/\\\\\\//\\\\\\_\\/\\\\\\__/\\\\\\______\\//\\\\\\__/\\\\\\______________/\\\\\\______\\//\\\\\\_\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\\\\\\\\\\\\\\\\\_____     \n    _\\/\\\\\\___\\/////\\\\\\_\\/\\\\\\___\\/////\\\\\\___________\\/\\\\\\\\//\\\\\\\\/\\\\\\_\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\_____________\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\///////______    \n     _\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\_______\\/\\\\\\___________\\/\\\\\\_\\//\\\\\\/\\\\\\_\\//\\\\\\______/\\\\\\__\\//\\\\\\____________\\//\\\\\\______/\\\\\\__\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\_____________   \n      _\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\_______\\/\\\\\\___________\\/\\\\\\__\\//\\\\\\\\\\\\__\\///\\\\\\__/\\\\\\_____\\///\\\\\\___________\\///\\\\\\__/\\\\\\____\\/\\\\\\_______/\\\\\\__\\/\\\\\\_____________  \n       _\\//\\\\\\\\\\\\\\\\\\\\\\\\/__\\//\\\\\\\\\\\\\\\\\\\\\\\\/____________\\/\\\\\\___\\//\\\\\\\\\\____\\///\\\\\\\\\\/________\\////\\\\\\\\\\\\\\\\\\____\\///\\\\\\\\\\/_____\\/\\\\\\\\\\\\\\\\\\\\\\\\/___\\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_ \n        __\\////////////_____\\////////////______________\\///_____\\/////_______\\/////_____________\\/////////_______\\/////_______\\////////////_____\\///////////////__\n```",
        "width": 1580,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3160,
        900
      ],
      "typeVersion": 1,
      "id": "e4fc2e53-6510-4109-b616-5f7c5e905f6e",
      "name": "Sticky Note19"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        100,
        1000
      ],
      "id": "6d5e21ae-670a-4d3f-b1c8-09e2a337aaa3",
      "name": "When clicking \u2018Test workflow\u2019",
      "disabled": true
    },
    {
      "parameters": {
        "content": "## LIMPAR MEM\u00d3RIA\n",
        "height": 420,
        "width": 840
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        880
      ],
      "typeVersion": 1,
      "id": "c041530e-c984-4b99-8a56-d63a128e80b2",
      "name": "Sticky Note20"
    },
    {
      "parameters": {
        "operation": "delete",
        "key": "id_que_quer_limpar"
      },
      "type": "n8n-nodes-base.redis",
      "typeVersion": 1,
      "position": [
        500,
        1000
      ],
      "id": "8739a48c-ca43-42d6-b22e-d3a6e2a2b730",
      "name": "Redis1",
      "credentials": {
        "redis": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "tableId": "SDR - HISTORICO",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "created_at",
              "fieldValue": "={{ $now.setZone('America/Sao_Paulo') }}"
            },
            {
              "fieldId": "id_cliente",
              "fieldValue": "={{ $('setarAgente').item.json.sessionId }}"
            },
            {
              "fieldId": "msg_cliente",
              "fieldValue": "={{ $('setarAgente').item.json.mensagem }}"
            },
            {
              "fieldId": "respota_agente",
              "fieldValue": "={{ $('AI Agent').item.json.output }}"
            },
            {
              "fieldId": "nome_cliente",
              "fieldValue": "={{ $('setData').item.json.cliente.nome }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        8780,
        0
      ],
      "id": "79261b6c-8850-4430-b9f1-94f7313de09b",
      "name": "historico",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "### TOOL 2",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7380,
        520
      ],
      "typeVersion": 1,
      "id": "0b24c816-7f8e-4cf8-ac62-dd4af50e781b",
      "name": "Sticky Note21"
    },
    {
      "parameters": {
        "content": "### TOOL 3",
        "height": 260,
        "width": 280,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7780,
        480
      ],
      "typeVersion": 1,
      "id": "719b5b38-2a97-448a-9bf2-128b2ba2fd2a",
      "name": "Sticky Note22"
    },
    {
      "parameters": {
        "operation": "update",
        "tableId": "SDR - LEADS",
        "filters": {
          "conditions": [
            {
              "keyName": "telefone",
              "condition": "eq",
              "keyValue": "={{ $('setData').item.json.cliente.telefone }}"
            }
          ]
        },
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "email",
              "fieldValue": "={{ $fromAI('email_cliente', 'captar o email do cliente ao final da conversa para agendar a reuniao') }}"
            },
            {
              "fieldId": "tipo_automacao",
              "fieldValue": "={{ $fromAI('tipo_automacao', 'verificar qual tipo de automacao que o cliente precisa') }}"
            },
            {
              "fieldId": "prazo",
              "fieldValue": "={{ $fromAI('prazo', 'prazo que o cliente pode aguardar para implementa\u00e7\u00e3o dos servi\u00e7os') }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabaseTool",
      "typeVersion": 1,
      "position": [
        7860,
        580
      ],
      "id": "864a66b6-f87a-4a0c-ab2c-921f53b62e82",
      "name": "atualizar_cadastro",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Utilize est\u00e1 tool quando passar por todos os passos da estrat\u00e9gia BANT, para criar um card da reuni\u00e3o com o cliente no trello.",
        "listId": "67902cfe8b3e1daefa239f4b",
        "name": "=Call Marcada - {{ $('setData').item.json.cliente.nome }}",
        "description": "=Telefone: {{ $('setData').item.json.cliente.telefone.split(\"@\").first() }}\nEmail: {{ $fromAI('email_cliente', 'captar o email do cliente ao final da conversa para agendar a reuniao') }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.trelloTool",
      "typeVersion": 1,
      "position": [
        7480,
        620
      ],
      "id": "0786bd98-e2bb-4f34-9883-bcda2dde7201",
      "name": "criar_card_trello",
      "credentials": {
        "trelloApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "setData",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setData": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "buscarCliente",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "buscarCliente": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "verificaHumano",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "criarCliente",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "criarCliente": {
      "main": [
        [
          {
            "node": "buscarCliente",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "verificaHumano": {
      "main": [
        [
          {
            "node": "If2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If2": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [],
        [
          {
            "node": "memoriaTexto",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "memoriaTexto": {
      "main": [
        [
          {
            "node": "pegaMemoria1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "pegaMemoria1": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "pegaMemoria2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "pegaMemoria2": {
      "main": [
        [
          {
            "node": "setarMemoria",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setarMemoria": {
      "main": [
        [
          {
            "node": "comparaMemoria",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "comparaMemoria": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "setarAgente",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "setarAgente": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Redis Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "RESPOSTA AGENTE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RESPOSTA AGENTE": {
      "main": [
        [
          {
            "node": "Redis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Atendimento Humano": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Test workflow\u2019": {
      "main": [
        [
          {
            "node": "Redis1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Redis": {
      "main": [
        [
          {
            "node": "historico",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "atualizar_cadastro": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "criar_card_trello": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f24e492c-74f6-4994-b497-b0f70465fcdc",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "YFJkOZgmeQTUt36H",
  "tags": []
}