{
  "id": "qZqUptGaNRJhpCSL",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "FAQ Communities in Whatsapp",
  "tags": [],
  "nodes": [
    {
      "id": "ef68ee0b-f945-44fe-85d9-30007d67c0b9",
      "name": "Get row(s) in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        80,
        -112
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "user@example.com",
              "lookupColumn": "RemoteJid Grupo"
            },
            {
              "lookupValue": "user@example.com",
              "lookupColumn": "RemoteJid Grupo"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1WNX4TNB0AEFXGnBbGYJqz0by9TcHcUd5Z5cH4GsGZ6g/edit#gid=0",
          "cachedResultName": "Log1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1WNX4TNB0AEFXGnBbGYJqz0by9TcHcUd5Z5cH4GsGZ6g",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1WNX4TNB0AEFXGnBbGYJqz0by9TcHcUd5Z5cH4GsGZ6g/edit?usp=drivesdk",
          "cachedResultName": "Log - Resumo de Grupos Staage"
        },
        "combineFilters": "OR"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "128a027b-e1a7-4771-97dd-71a4342c1c1e",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        336,
        -112
      ],
      "parameters": {
        "jsCode": "// Supondo que o input \u00e9 uma lista de mensagens no formato N8N (items)\nconst items = $input.all();\n\n// Fun\u00e7\u00e3o para converter '25/07/2025' em um Date JS\nfunction parseDate(dateStr) {\n  const [day, month, year] = dateStr.split('/');\n  return new Date(`${year}-${month}-${day}`);\n}\n\n// Fun\u00e7\u00e3o para obter o n\u00famero da semana (ISO 8601)\nfunction getWeek(date) {\n  const tempDate = new Date(date.getTime());\n  tempDate.setHours(0, 0, 0, 0);\n  tempDate.setDate(tempDate.getDate() + 4 - (tempDate.getDay() || 7));\n  const yearStart = new Date(tempDate.getFullYear(), 0, 1);\n  const weekNo = Math.ceil((((tempDate - yearStart) / 86400000) + 1) / 7);\n  return `${tempDate.getFullYear()}-W${weekNo}`;\n}\n\n// Agrupar mensagens por semana\nconst weeks = {};\n\nfor (const item of items) {\n  const dataStr = item.json.Data;\n  if (!dataStr) continue;\n  const date = parseDate(dataStr);\n  const week = getWeek(date);\n  if (!weeks[week]) weeks[week] = [];\n  weeks[week].push(item.json.mensagem);\n}\n\n// Compilar blocos por semana\nconst result = Object.entries(weeks).map(([week, mensagens]) => {\n  return {\n    json: {\n      semana: week,\n      bloco: mensagens.join('\\n')\n    }\n  };\n});\n\nreturn result;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "cf249385-49e9-45db-82cc-2eeccadc07a5",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        560,
        -112
      ],
      "parameters": {
        "text": "=Semana que est\u00e1 sendo analisada: {{ $json.semana }}\n\nBloco de Mensagens a ser tratado e analisado: {{ $json.bloco }}",
        "options": {
          "systemMessage": "=Identifica\u00e7\u00e3o de D\u00favidas Frequentes\n\nVoc\u00ea \u00e9 um agente de Intelig\u00eancia Artificial especializado em analisar blocos de mensagens de alunos. Sua miss\u00e3o \u00e9 identificar as **principais d\u00favidas, perguntas e questionamentos que se repetem ao longo das conversas**, especialmente aquelas relacionadas a temas recorrentes, como funcionamento do curso, acesso \u00e0 plataforma, grava\u00e7\u00e3o das aulas, entre outros.\n\nAo receber o bloco de mensagens, siga este passo a passo:\n\n1. **Leia atentamente todas as mensagens** buscando identificar padr\u00f5es, perguntas frequentes, repeti\u00e7\u00f5es ou d\u00favidas recorrentes.\n2. **Liste as principais d\u00favidas e perguntas** que apareceram mais de uma vez ou que claramente demonstram ser temas de interesse comum do grupo.\n3. Para cada d\u00favida identificada, escreva:\n    - **Pergunta recorrente** (como ela normalmente aparece na conversa)\n    - **Breve explica\u00e7\u00e3o sobre o tema da d\u00favida**\n    - (Opcional) **Sugest\u00e3o de resposta objetiva** que possa ser utilizada para o FAQ ou comunica\u00e7\u00e3o com alunos.\n\nSeu objetivo \u00e9 gerar uma lista clara e organizada das principais d\u00favidas do grupo, ajudando a equipe a antecipar perguntas e aprimorar a comunica\u00e7\u00e3o.\n\n### Exemplo de sa\u00edda esperada:\n\n**D\u00favida recorrente:** \"Quando a aula vai ser lan\u00e7ada na plataforma?\"\n- Tema: Disponibiliza\u00e7\u00e3o das aulas.\n- Sugest\u00e3o de resposta: \"As aulas ficam dispon\u00edveis na plataforma at\u00e9 24h ap\u00f3s o ao vivo.\"\n\n**D\u00favida recorrente:** \"Onde acesso a Staage One?\"\n- Tema: Acesso \u00e0 plataforma Staage One.\n- Sugest\u00e3o de resposta: \"Voc\u00ea recebe seu acesso por e-mail; procure por 'Seu acesso \u00e0 Staage One chegou!'.\"\n\n**D\u00favida recorrente:** \"A aula de hoje vai ficar gravada?\"\n- Tema: Grava\u00e7\u00e3o das aulas.\n- Sugest\u00e3o de resposta: \"Sim, todas as aulas ao vivo s\u00e3o gravadas e disponibilizadas para reassistir quando quiser.\"\n\n---\n\n**Aja como um analista preciso e organize a resposta sempre em t\u00f3picos, priorizando clareza e objetividade.**\n"
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "64e0948a-9449-4087-9f1f-2bcc31eb2752",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        576,
        80
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e5100ac4-7428-4fd9-9ebb-7fe70ed02770",
      "name": "Update a document",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        1024,
        -112
      ],
      "parameters": {
        "actionsUi": {
          "actionFields": [
            {
              "text": "={{ $('AI Agent').item.json.output }}",
              "action": "insert"
            }
          ]
        },
        "operation": "update",
        "documentURL": "={{ $json.id }}"
      },
      "credentials": {
        "googleDocsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "0d25df0d-e668-4387-aad4-c1fae9dfaa5e",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -176,
        -112
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 6
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fc505d69-fc20-4d1c-a628-1c46f13be249",
      "name": "Copy file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        864,
        -112
      ],
      "parameters": {
        "name": "Extraction FAQ - Whatsapp Group",
        "fileId": {
          "__rl": true,
          "mode": "list",
          "value": "1hAStPci4ZgaXMPbpLRh4U8MxeJUIkul_iYwYzhQVaus",
          "cachedResultUrl": "https://docs.google.com/document/d/1hAStPci4ZgaXMPbpLRh4U8MxeJUIkul_iYwYzhQVaus/edit?usp=drivesdk",
          "cachedResultName": "[TEMPLATE] - AN\u00c1LISE V\u00cdDEO"
        },
        "options": {},
        "operation": "copy"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "9ff1927e-ddae-440b-b8b0-da9846d577c8",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -192
      ],
      "parameters": {
        "height": 224,
        "content": "## Run Every Week\n**Every Monday 6am**"
      },
      "typeVersion": 1
    },
    {
      "id": "2ca1ffc3-ff3c-4ca1-9db2-99d0894438cc",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        -192
      ],
      "parameters": {
        "color": 3,
        "height": 224,
        "content": "### Find all messages of that last week\n"
      },
      "typeVersion": 1
    },
    {
      "id": "0aef6072-fcec-4658-9d99-d45b38f6a0df",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        -192
      ],
      "parameters": {
        "color": 5,
        "height": 224,
        "content": "### Do \"messages blocks\" and identify the week of those messages\n"
      },
      "typeVersion": 1
    },
    {
      "id": "c8455655-5d4e-41e3-90c3-5cce56a3aa01",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        -192
      ],
      "parameters": {
        "color": 4,
        "width": 288,
        "height": 400,
        "content": "### The AI Agent separates de questions and the context about these questions\n"
      },
      "typeVersion": 1
    },
    {
      "id": "3877f1c5-49c5-46da-a516-6ba5c17a5d07",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        -192
      ],
      "parameters": {
        "color": 6,
        "width": 320,
        "height": 256,
        "content": "### Copy the template doc. file and create new after that"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "359da1d0-4f41-497d-b5b0-c31a9c97f97e",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Copy file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Copy file": {
      "main": [
        [
          {
            "node": "Update a document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}