{
  "name": "[Template]",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "4d7b9ec1-3859-48ea-ba68-42f664780844",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -920,
        400
      ],
      "id": "4f9477a8-fc51-40bd-96c5-2d1ca0a4f3b7",
      "name": "Webhook",
      "webhookId": "4d7b9ec1-3859-48ea-ba68-42f664780844"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Webhook').item.json.body.messages.receivedMessage[0].body }}",
        "options": {
          "systemMessage": "Coloque aqui o comportamento que você quer para seu agente.\n\nPara utilizar a planilha, não esqueça de adicionar \"Use a ferramenta Google Sheets para acessar uma lista de perguntas ...\"."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        440,
        -20
      ],
      "id": "5229d3b6-c575-4b7d-8e89-10ea3ad57e40",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        480,
        360
      ],
      "id": "bf3f75cf-596c-45e6-9481-8ed78b2d5689",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "AjBcWZF1tb38WYc0",
          "name": "OpenAi account 2"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.huggy.app/v3/companies/{{ $('Webhook').item.json.body.messages.receivedMessage[0].company.id }}/chats/{{ $('Webhook').item.json.body.messages.receivedMessage[0].chat.id }}/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "text",
              "value": "={{ $json.output }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        980,
        60
      ],
      "id": "533c7a8e-adc5-4f54-9fa9-1840b9af26b2",
      "name": "HTTP Request",
      "credentials": {
        "httpHeaderAuth": {
          "id": "z31H2Cfb8WH2hDDA",
          "name": "Huggy API V3"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Webhook').item.json.body.messages.receivedMessage[0].chat.customer.id }}"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        680,
        340
      ],
      "id": "fc6572f7-3c54-4907-8d18-add1aa3a9775",
      "name": "Window Buffer Memory"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "coloque-a-url-da-planilha-aqui",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "",
          "mode": "list",
          "cachedResultName": "",
          "cachedResultUrl": ""
        }
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.5,
      "position": [
        880,
        360
      ],
      "id": "69b433c6-5348-498e-a498-8829ea2c8fe9",
      "name": "Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "KYJ9tnQIAJrU3q1I",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "1cc86f56-c071-4a33-ad2d-a46f4cc5ea26",
              "leftValue": "={{ $json.body.messages.receivedMessage[0].body }}",
              "rightValue": "coloque-a-palavra-chave-aqui",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -600,
        180
      ],
      "id": "82b84f05-dd2a-460f-9398-5524065396c0",
      "name": "If"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.huggy.app/v3/companies/{{ $json.body.messages.receivedMessage[0].company.id }}/chats/{{ $json.body.messages.receivedMessage[0].chat.id }}/flow",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "flowId",
              "value": "coloque-aqui-o-ID-do-Flow"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -380,
        460
      ],
      "id": "c7beb593-7d91-471a-af57-40e422c2b79a",
      "name": "HTTP Request1",
      "credentials": {
        "httpHeaderAuth": {
          "id": "z31H2Cfb8WH2hDDA",
          "name": "Huggy API V3"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://api.huggy.app/v3/companies/{{ $json.body.messages.receivedMessage[0].company.id }}/chats/{{ $json.body.messages.receivedMessage[0].chat.id }}/tags\n",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -280,
        40
      ],
      "id": "a9392c72-cd11-4f10-a384-39cd78f6aecf",
      "name": "HTTP Request3",
      "credentials": {
        "httpHeaderAuth": {
          "id": "z31H2Cfb8WH2hDDA",
          "name": "Huggy API V3"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "13261efc-2fa8-4aec-a1fc-8ffc40a00f2a",
              "leftValue": "={{ $json.name }}",
              "rightValue": "tag-que-sinaliza-processamento-de-ia",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        40,
        180
      ],
      "id": "02a285e7-fd54-452b-abd8-494f37c0b04c",
      "name": "If1"
    }
  ],
  "pinData": {},
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "HTTP Request3",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request3": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a2ed7840-bfdc-419a-81cc-f2b4832fc690",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "74317567a44cc73b1b2e783de7d2d6b9d37a0a23fa1505ef58dd1f936833e538"
  },
  "id": "KiHVET3fURnTaeUi",
  "tags": []
}