{
  "name": "Ngọc - Phương - Tele (done 2) copy",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 1
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        20,
        120
      ],
      "id": "781ccdb0-6b9f-4cad-8d3a-a48d95f7bc8c",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1tLfLzWayD8RSazavSSsQFnEFq4QOAgNcTkAoBRSit_Y",
          "mode": "list",
          "cachedResultName": "iNET - Telegram Chanel Auto",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1tLfLzWayD8RSazavSSsQFnEFq4QOAgNcTkAoBRSit_Y/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Telegram",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1tLfLzWayD8RSazavSSsQFnEFq4QOAgNcTkAoBRSit_Y/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        220,
        120
      ],
      "id": "6f110bd7-cf14-44d3-bb8f-e8e27798e360",
      "name": "Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "cBXvSOFmflmdaYlF",
          "name": "Ngoc sheet "
        }
      }
    },
    {
      "parameters": {
        "operation": "sendPhoto",
        "file": "={{ $json.Image }}",
        "additionalFields": {
          "caption": "={{ $json.Content }}",
          "parse_mode": "HTML"
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        800,
        120
      ],
      "id": "8bbca513-4a5a-411d-8c9e-862c2b0a1b76",
      "name": "Telegram2",
      "webhookId": "79e3a28d-ae20-4194-961d-286577fb7feb",
      "credentials": {
        "telegramApi": {
          "id": "YgmWgzlP60XiVcFQ",
          "name": "Bot Ngọc MKT"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1tLfLzWayD8RSazavSSsQFnEFq4QOAgNcTkAoBRSit_Y",
          "mode": "list",
          "cachedResultName": "iNET - Telegram Chanel Auto",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1tLfLzWayD8RSazavSSsQFnEFq4QOAgNcTkAoBRSit_Y/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Telegram",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1tLfLzWayD8RSazavSSsQFnEFq4QOAgNcTkAoBRSit_Y/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "row_number": "={{ $('Time_Now').item.json.id }}",
            "Status": "Hoàn thành"
          },
          "matchingColumns": [
            "row_number"
          ],
          "schema": [
            {
              "id": "Thời gian ",
              "displayName": "Thời gian ",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Title",
              "displayName": "Title",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Content AI",
              "displayName": "Content AI",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "ContentFinal",
              "displayName": "ContentFinal",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Image",
              "displayName": "Image",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Status",
              "displayName": "Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "PostTime",
              "displayName": "PostTime",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1000,
        120
      ],
      "id": "f92ed9c0-03fa-41ec-b1e0-04e2bd13e57a",
      "name": "Google Sheets1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "cBXvSOFmflmdaYlF",
          "name": "Ngoc sheet "
        }
      }
    },
    {
      "parameters": {
        "jsCode": "return items.map(item => {\n  console.log(\"Input from Google Sheets:\", JSON.stringify(item));\n\n  const output = {\n    json: {\n      id: item.json.row_number || \"\",\n      Title: item.json.Title || \"\",\n      Image: item.json.Image || \"\",\n      Content: item.json.ContentFinal || \"\",\n      \"Post Time\": item.json.PostTime || \"\",\n      Status: item.json.Status === \"To do\"\n    }\n  };\n\n  console.log(\"Function Node 1 Output:\", JSON.stringify(output));\n  return output;\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        120
      ],
      "id": "02d9fd40-7bf9-4344-af21-1a3451a2d141",
      "name": "Funtion_Data1",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "jsCode": "const nowRaw = new Date();\nconst nowTimestamp = nowRaw.getTime();\n\nreturn items.filter(item => {\n  console.log(\"Input Item in Function Node 2:\", JSON.stringify(item));\n\n  if (!item.json || !item.json[\"Post Time\"] || !item.json.Status) {\n    console.log(\"Missing Post Time or Status:\", JSON.stringify(item.json));\n    return false;\n  }\n\n  const postTime = new Date(item.json[\"Post Time\"].replace(\" \", \"T\") + \"+07:00\");\n  const postTimeTimestamp = postTime.getTime();\n\n  const diff = Math.abs(nowTimestamp - postTimeTimestamp) / 1000 / 60;\n\n  console.log(\"Raw Post Time:\", item.json[\"Post Time\"]);\n  console.log(\"Post Time Timestamp:\", postTimeTimestamp);\n  console.log(\"Post Time (GMT+0700):\", new Date(postTimeTimestamp).toLocaleString(\"en-US\", { timeZone: \"Asia/Ho_Chi_Minh\" }));\n  console.log(\"Now Raw Timestamp (GMT+0700):\", nowTimestamp);\n  console.log(\"Now (GMT+0700):\", nowRaw.toLocaleString(\"en-US\", { timeZone: \"Asia/Ho_Chi_Minh\" }));\n  console.log(\"Time difference (minutes):\", diff);\n\n  if (isNaN(postTimeTimestamp)) {\n    console.log(\"Invalid Post Time Timestamp\");\n    return false;\n  }\n\n  return diff <= 1;\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        640,
        120
      ],
      "id": "11fb7a5f-046e-48ab-9b4a-3a3a1cd9ec03",
      "name": "Time_Now",
      "alwaysOutputData": false
    }
  ],
  "pinData": {
    "Schedule Trigger": [
      {
        "json": {
          "timestamp": "2025-04-26T09:25:44.006+07:00",
          "Readable date": "April 26th 2025, 9:25:44 am",
          "Readable time": "9:25:44 am",
          "Day of week": "Saturday",
          "Year": "2025",
          "Month": "April",
          "Day of month": "26",
          "Hour": "09",
          "Minute": "25",
          "Second": "44",
          "Timezone": "Asia/Ho_Chi_Minh (UTC+07:00)"
        }
      }
    ]
  },
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Funtion_Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram2": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Funtion_Data1": {
      "main": [
        [
          {
            "node": "Time_Now",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Time_Now": {
      "main": [
        [
          {
            "node": "Telegram2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets1": {
      "main": [
        []
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "2693c99c-360e-4336-8ae8-520814ac989e",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "26d4932d441ca34892bd491418334feee4abea83c904852aefca49ce530634e0"
  },
  "id": "fTtI77FnNS2fpA8Q",
  "tags": []
}