{
  "name": "sentinela-unifecaf-desafio-tech-david-incisi",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "documentId": {
          "__rl": true,
          "value": "1EQqNGFFgYboeIhDdGHOOEX7YtHOOVTxFRNs9nas4I6k",
          "mode": "list",
          "cachedResultName": "unifecaf-desafio-tech",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1EQqNGFFgYboeIhDdGHOOEX7YtHOOVTxFRNs9nas4I6k/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Feedbacks",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1EQqNGFFgYboeIhDdGHOOEX7YtHOOVTxFRNs9nas4I6k/edit#gid=0"
        },
        "options": {
          "dataLocationOnSheet": {
            "values": {
              "rangeDefinition": "specifyRange"
            }
          }
        }
      },
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "id": "314c32ac-54f3-402e-9184-d9b976bd6a72",
      "name": "Google Sheets Trigger",
      "credentials": {
        "googleSheetsTriggerOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-3.5-turbo",
          "mode": "list",
          "cachedResultName": "GPT-3.5-TURBO"
        },
        "responses": {
          "values": [
            {
              "content": "=Voc\u00ea \u00e9 um Analista de Customer Experience S\u00eanior da UniFECAF, especializado em classifica\u00e7\u00e3o de feedbacks educacionais para automa\u00e7\u00e3o de CRM.\nSua tarefa \u00e9 analisar o feedback cru, classificar o sentimento e determinar a a\u00e7\u00e3o operacional necess\u00e1ria.\n\n### DIRETRIZES DE SENTIMENTO\n1. Positivo: Elogios claros sem ressalvas graves.\n2. Neutro: Perguntas, d\u00favidas gerais, ou feedbacks mistos onde o elogio e a cr\u00edtica t\u00eam peso igual e baixa severidade.\n3. Negativo: Reclama\u00e7\u00f5es, den\u00fancias, solicita\u00e7\u00f5es de reembolso, ou feedbacks mistos onde a cr\u00edtica afeta a infraestrutura ou metodologia (mesmo que haja elogios pontuais). Na d\u00favida, se houver um problema a ser resolvido, classifique como Negativo.\n\n### DIRETRIZES DO BOT\u00c3O DE A\u00c7\u00c3O\n- Deve ser imperativo, curto (max 4 palavras) e padronizado.\n- Use verbos de a\u00e7\u00e3o fortes: \"Contatar\", \"Verificar\", \"Escalar\", \"Arquivar\", \"Agradecer\".\n\n### EXEMPLOS\nFeedback: \"A professora Maria \u00e9 excelente, mas o projetor da sala 302 nunca funciona.\"\nSa\u00edda: {\"sentimento\": \"Negativo\", \"justificativa\": \"Elogio \u00e0 doc\u00eancia, mas falha recorrente de infraestrutura que exige reparo.\", \"acao_sugerida\": \"Verificar Manuten\u00e7\u00e3o\"}\n\nFeedback: \"Gostaria de saber quando saem as notas.\"\nSa\u00edda: {\"sentimento\": \"Neutro\", \"justificativa\": \"D\u00favida administrativa sem teor qualitativo.\", \"acao_sugerida\": \"Responder Aluno\"}\n\nFeedback: \"Amei a metodologia da aula de hoje!\"\nSa\u00edda: {\"sentimento\": \"Positivo\", \"justificativa\": \"Elogio direto \u00e0 metodologia.\", \"acao_sugerida\": \"Registrar Elogio\"}\n\n### FORMATO DE RESPOSTA\nRetorne APENAS um objeto JSON v\u00e1lido. N\u00e3o inclua blocos de c\u00f3digo markdown (```json), explica\u00e7\u00f5es ou texto introdut\u00f3rio.\n\n#\nTEXTO DO FEEDBACK:\n\"\"\"\n{{ $json.feedback }}\n\"\"\""
            }
          ]
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        416,
        0
      ],
      "id": "cc3d48ec-6e8d-4108-9d34-99181c5c4fb1",
      "name": "Message a model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const filteredData = $('Filter').all(); \n\nconst results = [];\n\nfor (let i = 0; i < $input.all().length; i++) {\n  const item = $input.all()[i];\n  \n  try {\n    const id = filteredData[i].json.id; \n    let rawText = \"\";\n    \n    if (item.json.output && item.json.output[0]?.content?.[0]?.text) rawText = item.json.output[0].content[0].text;\n    else if (item.json.message?.content) rawText = item.json.message.content;\n    else if (item.json.text) rawText = item.json.text;\n    else rawText = \"Conte\u00fado vazio\";\n\n    const cleanContent = rawText.replace(/^```json\\s*|\\s*```$/g, '').trim();\n    const parsedData = JSON.parse(cleanContent);\n\n    results.push({\n      json: {\n        id: id, \n        sentimento: parsedData.sentimento || \"Erro\",\n        justificativa: parsedData.justificativa || \"N\u00e3o identificado\",\n        acao_sugerida: parsedData.acao_sugerida || \"Revisar\"\n      }\n    });\n\n  } catch (error) {\n    let errorMsg = \"Erro desconhecido\";\n\n    if (error instanceof Error) {\n        errorMsg = error.message;\n    } else {\n        errorMsg = String(error);\n    }\n    \n     const id = filteredData[i] ? filteredData[i].json.id : \"Desconhecido\";\n    \n     results.push({\n      json: {\n        id: id,\n        error: errorMsg\n      }\n    });\n  }\n}\n\nreturn results;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        768,
        0
      ],
      "id": "59103b1b-e9aa-4e11-8a7b-bf8af99cad20",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1EQqNGFFgYboeIhDdGHOOEX7YtHOOVTxFRNs9nas4I6k",
          "mode": "list",
          "cachedResultName": "unifecaf-desafio-tech",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1EQqNGFFgYboeIhDdGHOOEX7YtHOOVTxFRNs9nas4I6k/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Feedbacks",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1EQqNGFFgYboeIhDdGHOOEX7YtHOOVTxFRNs9nas4I6k/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "sentimento": "={{ $json.sentimento }}",
            "justificativa": "={{ $json.justificativa }}",
            "acao_sugerida": "={{ $json.acao_sugerida }}",
            "id": "={{ $('Filter').item.json.id }}",
            "row_number": 0
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "id",
              "displayName": "id",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "feedback",
              "displayName": "feedback",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "sentimento",
              "displayName": "sentimento",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "justificativa",
              "displayName": "justificativa",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "acao_sugerida",
              "displayName": "acao_sugerida",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        976,
        0
      ],
      "id": "e0b32e0d-9e9a-443f-ba93-de9f4e4bece3",
      "name": "Update row in sheet",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "d7daf8e0-fef1-488b-bcc4-2f0bb8a3e3d4",
              "leftValue": "={{ $json.sentimento }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.3,
      "position": [
        208,
        0
      ],
      "id": "f51eefff-bbd8-462f-9103-490a819933bb",
      "name": "Filter"
    }
  ],
  "connections": {
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Update row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": false
  },
  "versionId": "8a99eecd-66b5-485c-946b-67f9f67a1049",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "NKiXSzXH49-SgjVif1N1p",
  "tags": []
}