{
  "name": "FB Groups Daily Report (Optimized)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 17 * * *"
            }
          ]
        }
      },
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "trigger-report",
        "responseMode": "onReceived",
        "options": {}
      },
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        460
      ]
    },
    {
      "parameters": {
        "operation": "readSheet",
        "spreadsheetId": "1dIrzcuyXufvqRrsI-8xlRz-xPEJdH4g29es_Nm0pe4E",
        "sheetName": "={{ 'FB_Posts_' + new Date().toISOString().split('T')[0] }}"
      },
      "name": "Read Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const today = new Date().toISOString().split('T')[0];\nreturn items.filter(item => item.json['Ng\u00e0y Thu Th\u1eadp']?.startsWith(today));"
      },
      "name": "Filter Today Posts",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "operation": "text",
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "field": "N\u1ed9i Dung"
            }
          ]
        },
        "options": {
          "joinBy": "\n---\n"
        }
      },
      "name": "Aggregate Posts",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "model": "models/gemini-2.5_flash",
        "prompt": "=H\u00e3y ph\u00e2n t\u00edch danh s\u00e1ch c\u00e1c b\u00e0i vi\u1ebft Facebook sau v\u00e0 t\u1ea1o m\u1ed9t b\u00e1o c\u00e1o chuy\u00ean s\u00e2u.\n\nChia th\u00e0nh 2 nh\u00f3m:\n1. NH\u00c0 TUY\u1ec2N D\u1ee4NG: Ghi r\u00f5 v\u1ecb tr\u00ed v\u00e0 y\u00eau c\u1ea7u.\n2. NG\u01af\u1edcI T\u00ccM VI\u1ec6C: Ghi r\u00f5 mong mu\u1ed1n v\u00e0 k\u1ef9 n\u0103ng.\n\nD\u1eef li\u1ec7u: \n{{ $json.text }}",
        "options": {}
      },
      "name": "Google Gemini",
      "type": "n8n-nodes-base.googleGemini",
      "typeVersion": 1,
      "position": [
        1120,
        300
      ]
    },
    {
      "parameters": {
        "chatId": "6452124662",
        "text": "=\ud83d\udcca B\u00c1O C\u00c1O C\u00d4NG VI\u1ec6C\n\n{{ $json.text }}",
        "additionalFields": {}
      },
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        1340,
        300
      ]
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Read Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Read Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Google Sheets": {
      "main": [
        [
          {
            "node": "Filter Today Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Today Posts": {
      "main": [
        [
          {
            "node": "Aggregate Posts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Posts": {
      "main": [
        [
          {
            "node": "Google Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}