{
  "name": "Freelanly Video Social Posting v12",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 30
            }
          ]
        }
      },
      "id": "schedule-trigger",
      "name": "Every 30 min",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://freelanly.com/api/cron/post-video-to-social",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "get-video-post",
      "name": "Get Video Post",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        220,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "has-post",
              "leftValue": "={{ $json.hasPost }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "if-has-post",
      "name": "Has Post?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://198.12.73.168:3123/api/short-video",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ scenes: $json.body.scenes, config: $json.body.config }) }}",
        "options": {}
      },
      "id": "create-video",
      "name": "Create Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        -100
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "vid",
              "name": "videoId",
              "value": "={{ $json.videoId }}",
              "type": "string"
            },
            {
              "id": "queueItemId",
              "name": "queueItemId",
              "value": "={{ $('Get Video Post').item.json.body.queueItemId }}",
              "type": "string"
            },
            {
              "id": "jobUrl",
              "name": "jobUrl",
              "value": "={{ $('Get Video Post').item.json.body.jobUrl }}",
              "type": "string"
            },
            {
              "id": "socialCaption",
              "name": "socialCaption",
              "value": "={{ $('Get Video Post').item.json.body.socialCaption }}",
              "type": "string"
            },
            {
              "id": "retry",
              "name": "retryCount",
              "value": "0",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "init-retry",
      "name": "Init Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        880,
        -100
      ]
    },
    {
      "parameters": {
        "amount": 2,
        "unit": "minutes"
      },
      "id": "wait-2min",
      "name": "Wait 2 min",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        1100,
        -100
      ]
    },
    {
      "parameters": {
        "method": "HEAD",
        "url": "=http://198.12.73.168:3123/api/short-video/{{ $json.videoId }}",
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "id": "check-status",
      "name": "Check Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        -100
      ]
    },
    {
      "parameters": {
        "jsCode": "const statusCode = $input.first().json.statusCode || 404;\nconst prev = $('Init Data').item.json;\nconst retryCount = $('Increment Retry').item?.json?.retryCount ?? prev.retryCount ?? 0;\n\nreturn [{\n  json: {\n    isReady: statusCode === 200,\n    videoId: prev.videoId,\n    queueItemId: prev.queueItemId,\n    jobUrl: prev.jobUrl,\n    socialCaption: prev.socialCaption,\n    retryCount: retryCount\n  }\n}];"
      },
      "id": "merge-status",
      "name": "Check Status",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1540,
        -100
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "ready-check",
              "leftValue": "={{ $json.isReady }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "if-ready",
      "name": "Ready?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1760,
        -100
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=http://198.12.73.168:3123/api/short-video/{{ $json.videoId }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "download-video",
      "name": "Download Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1980,
        -200
      ]
    },
    {
      "parameters": {
        "chatId": "@PCFTI",
        "text": "={{ $('Check Status').item.json.socialCaption }}\n\nMore jobs: {{ $('Check Status').item.json.jobUrl }}",
        "additionalFields": {
          "appendAttribution": false
        },
        "operation": "sendVideo"
      },
      "id": "telegram-post",
      "name": "Post to Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2200,
        -300
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "communityManagement",
        "postAs": "organization",
        "organization": "53520294",
        "text": "={{ $('Check Status').item.json.socialCaption }}\n\nApply here: {{ $('Check Status').item.json.jobUrl }}\n\nMore jobs at freelanly.com",
        "additionalFields": {}
      },
      "id": "linkedin-post",
      "name": "Post to LinkedIn",
      "type": "n8n-nodes-base.linkedIn",
      "typeVersion": 1,
      "position": [
        2200,
        -100
      ],
      "credentials": {
        "linkedInCommunityManagementOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "https://freelanly.com/api/cron/post-video-to-social",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ queueItemId: $('Check Status').item.json.queueItemId, status: 'posted', videoId: $('Check Status').item.json.videoId, videoUrl: 'http://198.12.73.168:3123/api/short-video/' + $('Check Status').item.json.videoId }) }}",
        "options": {}
      },
      "id": "mark-posted",
      "name": "Mark Posted",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2420,
        -200
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "retry-check",
              "leftValue": "={{ $json.retryCount }}",
              "rightValue": 10,
              "operator": {
                "type": "number",
                "operation": "lt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "if-can-retry",
      "name": "Can Retry?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1980,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "vid",
              "name": "videoId",
              "value": "={{ $json.videoId }}",
              "type": "string"
            },
            {
              "id": "queueItemId",
              "name": "queueItemId",
              "value": "={{ $json.queueItemId }}",
              "type": "string"
            },
            {
              "id": "jobUrl",
              "name": "jobUrl",
              "value": "={{ $json.jobUrl }}",
              "type": "string"
            },
            {
              "id": "socialCaption",
              "name": "socialCaption",
              "value": "={{ $json.socialCaption }}",
              "type": "string"
            },
            {
              "id": "retry",
              "name": "retryCount",
              "value": "={{ $json.retryCount + 1 }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "increment-retry",
      "name": "Increment Retry",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2200,
        0
      ]
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "https://freelanly.com/api/cron/post-video-to-social",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ queueItemId: $json.queueItemId, status: 'failed', error: 'Video generation timed out after 10 retries (20 min)' }) }}",
        "options": {}
      },
      "id": "mark-failed",
      "name": "Mark Failed",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2200,
        150
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "id": "done",
      "name": "Done",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        2640,
        -200
      ]
    },
    {
      "parameters": {},
      "id": "no-post",
      "name": "No Post",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        660,
        100
      ]
    }
  ],
  "connections": {
    "Every 30 min": {
      "main": [
        [
          {
            "node": "Get Video Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Video Post": {
      "main": [
        [
          {
            "node": "Has Post?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Post?": {
      "main": [
        [
          {
            "node": "Create Video",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Video": {
      "main": [
        [
          {
            "node": "Init Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Init Data": {
      "main": [
        [
          {
            "node": "Wait 2 min",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 2 min": {
      "main": [
        [
          {
            "node": "Check Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Video": {
      "main": [
        [
          {
            "node": "Check Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Status": {
      "main": [
        [
          {
            "node": "Ready?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ready?": {
      "main": [
        [
          {
            "node": "Download Video",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Can Retry?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Video": {
      "main": [
        [
          {
            "node": "Post to Telegram",
            "type": "main",
            "index": 0
          },
          {
            "node": "Post to LinkedIn",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post to Telegram": {
      "main": [
        [
          {
            "node": "Mark Posted",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark Posted": {
      "main": [
        [
          {
            "node": "Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Can Retry?": {
      "main": [
        [
          {
            "node": "Increment Retry",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mark Failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Increment Retry": {
      "main": [
        [
          {
            "node": "Wait 2 min",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 1,
  "updatedAt": "2026-01-03T20:00:00.000Z",
  "versionId": "12"
}