{
  "name": "Viteon \u2014 Tarefas do Dia no WhatsApp",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 8 * * *"
            }
          ]
        }
      },
      "id": "cron-trigger",
      "name": "Todo dia 8h",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const now = new Date();\nconst start = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0).getTime();\nconst end = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999).getTime();\n\nreturn [{ json: { due_date_gt: start, due_date_lt: end } }];"
      },
      "id": "calc-dates",
      "name": "Calcular Timestamps",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{ 'https://api.clickup.com/api/v2/team/90171187518/task?due_date_gt=' + $json.due_date_gt + '&due_date_lt=' + $json.due_date_lt + '&include_closed=false&subtasks=true' }}",
        "authentication": "none",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "pk_55106720_DO502GYVVUZJSIV1MYWSH7T4P7X2MK5G"
            }
          ]
        },
        "options": {}
      },
      "id": "clickup-get-tasks",
      "name": "Buscar Tarefas do Dia",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "check-tasks-exist",
              "leftValue": "={{ $json.tasks.length }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "check-tasks",
      "name": "Tem tarefas?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        880,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const tasks = $input.first().json.tasks;\n\nconst hoje = new Date().toLocaleDateString('pt-BR', {\n  weekday: 'long',\n  day: '2-digit',\n  month: '2-digit',\n  year: 'numeric',\n  timeZone: 'America/Sao_Paulo'\n});\n\nlet msg = `*VITEON \u2014 Tarefas de Hoje*\\n${hoje}\\n\\n`;\n\nconst groups = {};\ntasks.forEach(t => {\n  const listName = t.list?.name || t.folder?.name || 'Geral';\n  if (!groups[listName]) groups[listName] = [];\n  \n  const assignees = t.assignees?.map(a => a.username).join(', ') || 'Sem responsavel';\n  const priority = t.priority?.priority ? ` [${t.priority.priority.toUpperCase()}]` : '';\n  \n  groups[listName].push({\n    name: t.name,\n    assignees,\n    priority\n  });\n});\n\nfor (const [group, items] of Object.entries(groups)) {\n  msg += `*${group}*\\n`;\n  items.forEach(t => {\n    msg += `- ${t.name}${t.priority}\\n  ${t.assignees}\\n`;\n  });\n  msg += `\\n`;\n}\n\nmsg += `Total: ${tasks.length} tarefa(s)`;\n\nreturn [{ json: { message: msg, taskCount: tasks.length } }];"
      },
      "id": "format-message",
      "name": "Formatar Mensagem",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1100,
        200
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "YOUR_UAZAPI_URL/send-text",
        "authentication": "none",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "Bearer YOUR_UAZAPI_TOKEN"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ phone: 'GROUP_ID', message: $json.message }) }}",
        "options": {}
      },
      "id": "send-whatsapp",
      "name": "Enviar no WhatsApp",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        200
      ]
    },
    {
      "parameters": {},
      "id": "no-tasks",
      "name": "Sem tarefas hoje",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1100,
        400
      ]
    }
  ],
  "connections": {
    "Todo dia 8h": {
      "main": [
        [
          {
            "node": "Calcular Timestamps",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calcular Timestamps": {
      "main": [
        [
          {
            "node": "Buscar Tarefas do Dia",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Buscar Tarefas do Dia": {
      "main": [
        [
          {
            "node": "Tem tarefas?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tem tarefas?": {
      "main": [
        [
          {
            "node": "Formatar Mensagem",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Sem tarefas hoje",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Formatar Mensagem": {
      "main": [
        [
          {
            "node": "Enviar no WhatsApp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "America/Sao_Paulo"
  }
}