{
  "name": "Content calendar check before posting",
  "nodes": [
    {
      "id": "d7cadb08-d012-409a-b303-df932c81f903",
      "name": "Read me first",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -688,
        -120
      ],
      "parameters": {
        "content": "## Content calendar check before posting\nEvery hour it checks the rows marked Ready for check: caption, time, accounts and media. Good rows turn Approved. The rest get a plain reason.\n\n### You need\n- The sprkly node: Settings, Community nodes, install `n8n-nodes-sprkly` (self-hosted n8n)\n- A sprkly API key: https://sprkly.app/docs/api?utm_source=n8n&utm_medium=workflow&utm_campaign=google-sheets-content-qa\n- A Google Sheets login and a Calendar tab with: Row ID, Status, Caption, Schedule Time, Accounts, Media URL, QA Notes\n- A Telegram bot and your chat ID, for the summary\n\n### Set it up\n1. Pick your sheet in **Read the calendar** and **Write the result to the row**.\n2. Add your sprkly key to **Get connected accounts**. Add your bot to **Send the summary**.\n3. In **Settings**, add your chat ID. Change the status words if your sheet uses others. Set your time zone in Workflow settings.\n4. Failure alert: put your chat ID in **Write the failure alert** and your bot in **Send the failure alert**. Then in Workflow settings, set Error workflow to this workflow.\n\n### Test it\n- Set one good row and one row with no caption to Ready for check. Click Test workflow.\n- The good row turns Approved. The other turns Needs fixing, with the reason in QA Notes. The Google Sheets calendar workflow then posts the Approved rows.",
        "height": 884,
        "width": 560,
        "color": 4
      }
    },
    {
      "id": "34e47fa5-8ad2-4538-9dd0-53f6348d74c7",
      "name": "Note: read",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -48,
        -120
      ],
      "parameters": {
        "content": "## Read the calendar\nOnly rows with the status in **Settings** are checked. The account list comes from sprkly, so a typo in Accounts is caught here.",
        "height": 560,
        "width": 1000,
        "color": 7
      }
    },
    {
      "id": "e8164575-4966-44ad-9530-e2aff2bbdc59",
      "name": "Note: check",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1032,
        -120
      ],
      "parameters": {
        "content": "## Check and write back\nEach row gets Approved or Needs fixing, with every reason in QA Notes. Nothing is posted here.",
        "height": 560,
        "width": 1000,
        "color": 7
      }
    },
    {
      "id": "0c032442-3dbf-46a5-8d07-34156f6b3ca7",
      "name": "Every hour",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 1
            }
          ]
        }
      }
    },
    {
      "id": "318a02b0-a919-4430-a9dc-ae9189ee807e",
      "name": "Check now",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        200
      ],
      "parameters": {}
    },
    {
      "id": "0e5af7e4-6d31-4314-978c-72db0d4f713b",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        100
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "checkStatus",
              "type": "string",
              "value": "Ready for check"
            },
            {
              "id": "f2",
              "name": "passStatus",
              "type": "string",
              "value": "Approved"
            },
            {
              "id": "f3",
              "name": "fixStatus",
              "type": "string",
              "value": "Needs fixing"
            },
            {
              "id": "f4",
              "name": "minutesAhead",
              "type": "number",
              "value": 30
            },
            {
              "id": "f5",
              "name": "telegramChatId",
              "type": "string",
              "value": "YOUR_CHAT_ID"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      }
    },
    {
      "id": "b2a5154f-15fc-414a-b461-f3956ee7c08f",
      "name": "Get connected accounts",
      "type": "n8n-nodes-sprkly.sprkly",
      "typeVersion": 1.1,
      "position": [
        480,
        100
      ],
      "parameters": {
        "resource": "account",
        "operation": "getAll",
        "returnAll": true
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "3b4d8203-1f6d-4750-9529-9b1db04a8130",
      "name": "Read the calendar",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        720,
        100
      ],
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Calendar",
          "mode": "name"
        },
        "options": {}
      },
      "executeOnce": true,
      "alwaysOutputData": true
    },
    {
      "id": "9a80e124-c39d-4c54-b362-3cababa38a95",
      "name": "Waiting for a check?",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        960,
        100
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ String($json.Status || '').trim().toLowerCase() === String($('Settings').first().json.checkStatus).trim().toLowerCase() }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      }
    },
    {
      "id": "eae20670-af06-44f6-9230-6e944fe740f2",
      "name": "Check each row",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1200,
        100
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// One result per row. Every problem is listed, so one pass fixes the row.\nconst s = $('Settings').first().json;\nconst accounts = $('Get connected accounts').all().map(a => a.json).filter(a => a.platform && a.handle);\nconst norm = v => String(v ?? '').trim().replace(/^@/, '').toLowerCase();\n// Caption limits in characters. Change them if a platform changes its limit.\nconst limits = { x: 280, bluesky: 300, threads: 500, instagram: 2200, tiktok: 2200, linkedin: 3000 };\nconst needsMedia = ['instagram', 'tiktok', 'youtube', 'pinterest'];\nconst rows = $input.all().map(i => i.json);\nconst count = new Map();\nfor (const r of rows) { const id = String(r['Row ID'] ?? '').trim(); if (id) count.set(id, (count.get(id) || 0) + 1); }\nreturn rows.map(r => {\n  const problems = [];\n  const id = String(r['Row ID'] ?? '').trim();\n  const caption = String(r.Caption ?? '').trim();\n  const raw = String(r['Schedule Time'] ?? '').trim();\n  const when = DateTime.fromISO(raw.replace(' ', 'T'), { zone: $now.zoneName });\n  const media = String(r['Media URL'] ?? '').split(/[\\s,]+/).filter(Boolean);\n  const refs = String(r.Accounts ?? '').split(',').map(v => v.trim()).filter(Boolean);\n  if (!id) problems.push('Row ID is empty.');\n  else if (count.get(id) > 1) problems.push('Row ID ' + id + ' is used more than once.');\n  if (!caption) problems.push('Caption is empty.');\n  if (!raw || !when.isValid) problems.push('Schedule Time is not a date and time. Write it like 2026-12-01 09:30.');\n  else if (when < $now.plus({ minutes: Number(s.minutesAhead) || 30 })) problems.push('Schedule Time has passed, or is too soon.');\n  if (refs.length === 0) problems.push('Accounts is empty. Write them like instagram:yourhandle.');\n  const platforms = [];\n  for (const ref of refs) {\n    const cut = ref.indexOf(':');\n    if (cut < 1) { problems.push('\"' + ref + '\" is not platform:handle.'); continue; }\n    const p = norm(ref.slice(0, cut)), h = norm(ref.slice(cut + 1));\n    platforms.push(p);\n    if (!accounts.some(a => norm(a.platform) === p && norm(a.handle) === h)) problems.push('No connected sprkly account is ' + ref + '.');\n  }\n  for (const p of [...new Set(platforms)]) {\n    if (limits[p] && caption.length > limits[p]) problems.push('Caption is ' + caption.length + ' characters. ' + p + ' takes ' + limits[p] + '.');\n    if (needsMedia.includes(p) && media.length === 0) problems.push(p + ' needs a photo or video in Media URL.');\n  }\n  for (const m of media) if (!/^https:\\/\\//i.test(m)) problems.push('Media URL ' + m.slice(0, 40) + ' must start with https://');\n  return { json: { row_number: r.row_number, rowId: id || 'row ' + r.row_number, passed: problems.length === 0, problems: problems.join(' ') } };\n});"
      }
    },
    {
      "id": "53787743-702d-47aa-9fb2-f20def28372b",
      "name": "Write the result to the row",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1440,
        0
      ],
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Calendar",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "row_number": "={{ $json.row_number }}",
            "Status": "={{ $json.passed ? $('Settings').first().json.passStatus : $('Settings').first().json.fixStatus }}",
            "QA Notes": "={{ $json.problems }}"
          },
          "matchingColumns": [
            "row_number"
          ],
          "schema": [
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false,
              "readOnly": true
            },
            {
              "id": "Status",
              "displayName": "Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "QA Notes",
              "displayName": "QA Notes",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "863d676a-6d00-42af-9b21-ce40f6e0202a",
      "name": "Write the summary",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1440,
        200
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const rows = $('Check each row').all().map(i => i.json);\nconst bad = rows.filter(r => !r.passed);\nconst lines = bad.slice(0, 15).map(r => '- ' + r.rowId + ': ' + r.problems);\nconst message = 'Calendar check: ' + rows.length + ' rows.\\nApproved: ' + (rows.length - bad.length) + '\\nNeeds fixing: ' + bad.length\n  + (lines.length ? '\\n\\n' + lines.join('\\n') + (bad.length > 15 ? '\\n...and ' + (bad.length - 15) + ' more' : '') : '');\nreturn [{ json: { message } }];"
      }
    },
    {
      "id": "287a9220-e58d-4dfc-a9df-37d9999d80d5",
      "name": "Send the summary",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1680,
        200
      ],
      "parameters": {
        "chatId": "={{ $('Settings').first().json.telegramChatId }}",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "8c733a26-99fe-46ec-bf7a-35194ff27989",
      "name": "When this workflow fails",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        -648,
        844
      ],
      "parameters": {}
    },
    {
      "id": "276fc24b-663b-4cb6-aa1f-ea0860fc2619",
      "name": "Write the failure alert",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -428,
        844
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "telegramChatId",
              "type": "string",
              "value": "YOUR_TELEGRAM_CHAT_ID"
            },
            {
              "id": "f2",
              "name": "message",
              "type": "string",
              "value": "={{ 'A workflow stopped.\\n\\nWorkflow: ' + (($json.workflow || {}).name || 'unknown') + '\\nFailed step: ' + (($json.execution || {}).lastNodeExecuted || 'unknown') + '\\nWhy: ' + String((($json.execution || {}).error || {}).message || 'n8n did not give a reason.').slice(0, 300) + (($json.execution || {}).url ? '\\nOpen the run: ' + $json.execution.url : '') }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "c4a29c74-f356-46d2-9ac4-95b89594a215",
      "name": "Send the failure alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -208,
        844
      ],
      "parameters": {
        "chatId": "={{ $json.telegramChatId }}",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "Every hour": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check now": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Get connected accounts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get connected accounts": {
      "main": [
        [
          {
            "node": "Read the calendar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read the calendar": {
      "main": [
        [
          {
            "node": "Waiting for a check?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Waiting for a check?": {
      "main": [
        [
          {
            "node": "Check each row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check each row": {
      "main": [
        [
          {
            "node": "Write the result to the row",
            "type": "main",
            "index": 0
          },
          {
            "node": "Write the summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the summary": {
      "main": [
        [
          {
            "node": "Send the summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When this workflow fails": {
      "main": [
        [
          {
            "node": "Write the failure alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the failure alert": {
      "main": [
        [
          {
            "node": "Send the failure alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}
