{
  "name": "Social Media Content Auto-Poster",
  "nodes": [
    {
      "parameters": {
        "rule": { "interval": [{ "field": "days", "daysInterval": 1, "triggerAtHour": 9 }] }
      },
      "id": "daily-trigger",
      "name": "Daily at 9 AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [250, 300]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": { "__rl": true, "value": "YOUR_SPREADSHEET_ID" },
        "sheetName": "Content Calendar",
        "options": {
          "range": "A:F"
        }
      },
      "id": "get-content",
      "name": "Get Today's Content",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [470, 300]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.scheduled_date }}",
              "operation": "equal",
              "value2": "={{ $now.format('yyyy-MM-dd') }}"
            }
          ]
        }
      },
      "id": "is-today",
      "name": "Scheduled for Today?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [690, 300]
    },
    {
      "parameters": {
        "url": "https://api.openai.com/v1/chat/completions",
        "method": "POST",
        "authentication": "genericHeader",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\n  \"model\": \"gpt-4o-mini\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are a healthcare social media content creator. Create engaging, educational posts for {{ $json.platform }}. Include relevant hashtags. Keep posts HIPAA-compliant — use general health tips, never reference specific patients. Match the tone: professional yet approachable. Output JSON: { caption, hashtags, cta }\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Topic: {{ $json.topic }}\\nPlatform: {{ $json.platform }}\\nContent Type: {{ $json.content_type }}\\nKey Message: {{ $json.key_message }}\"\n    }\n  ],\n  \"temperature\": 0.8\n}",
        "options": {}
      },
      "id": "ai-create-caption",
      "name": "AI Create Caption",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [910, 300]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.platform }}",
              "operation": "contains",
              "value2": "facebook"
            }
          ]
        }
      },
      "id": "check-platform",
      "name": "Which Platform?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 2,
      "position": [1130, 300]
    },
    {
      "parameters": {
        "url": "https://graph.facebook.com/v18.0/YOUR_PAGE_ID/feed",
        "method": "POST",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            { "name": "message", "value": "={{ $json.caption }}\n\n{{ $json.hashtags }}\n\n{{ $json.cta }}" },
            { "name": "access_token", "value": "YOUR_FB_TOKEN" }
          ]
        },
        "options": {}
      },
      "id": "post-facebook",
      "name": "Post to Facebook",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [1350, 150]
    },
    {
      "parameters": {
        "url": "https://graph.facebook.com/v18.0/YOUR_IG_ACCOUNT_ID/media",
        "method": "POST",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            { "name": "caption", "value": "={{ $json.caption }}\n\n{{ $json.hashtags }}" },
            { "name": "image_url", "value": "={{ $json.image_url }}" },
            { "name": "access_token", "value": "YOUR_IG_TOKEN" }
          ]
        },
        "options": {}
      },
      "id": "post-instagram",
      "name": "Post to Instagram",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [1350, 350]
    },
    {
      "parameters": {
        "channel": "#social-media",
        "text": "📱 Auto-Posted to {{ $json.platform }}:\n\n{{ $json.caption }}\n\nHashtags: {{ $json.hashtags }}",
        "otherOptions": {}
      },
      "id": "notify-posted",
      "name": "Notify Team",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [1570, 250]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": { "__rl": true, "value": "YOUR_SPREADSHEET_ID" },
        "sheetName": "Content Calendar",
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Status": "Posted",
            "Posted At": "={{ $now.toISO() }}",
            "Generated Caption": "={{ $json.caption }}"
          }
        }
      },
      "id": "update-sheet",
      "name": "Update Sheet Status",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [1570, 450]
    }
  ],
  "connections": {
    "Daily at 9 AM": { "main": [[{ "node": "Get Today's Content", "type": "main", "index": 0 }]] },
    "Get Today's Content": { "main": [[{ "node": "Scheduled for Today?", "type": "main", "index": 0 }]] },
    "Scheduled for Today?": { "main": [[{ "node": "AI Create Caption", "type": "main", "index": 0 }]] },
    "AI Create Caption": { "main": [[{ "node": "Which Platform?", "type": "main", "index": 0 }]] },
    "Which Platform?": {
      "main": [
        [{ "node": "Post to Facebook", "type": "main", "index": 0 }],
        [{ "node": "Post to Instagram", "type": "main", "index": 0 }]
      ]
    },
    "Post to Facebook": { "main": [[{ "node": "Notify Team", "type": "main", "index": 0 }]] },
    "Post to Instagram": { "main": [[{ "node": "Notify Team", "type": "main", "index": 0 }]] },
    "Notify Team": { "main": [[{ "node": "Update Sheet Status", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "meta": {
    "templateCredsSetupCompleted": false,
    "instanceId": "nexhealth-social-autoposter"
  },
  "tags": [{ "name": "Healthcare" }, { "name": "Social Media" }, { "name": "AI Content" }, { "name": "Marketing" }]
}
