{
  "name": "Symcio \u00b7 SDG1 Poverty Digest",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 2 * * 1"
            }
          ]
        }
      },
      "id": "weekly-mon",
      "name": "Weekly Mon 10:00 Taipei",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "url": "=https://{{ $credentials.supabase.ref }}.supabase.co/rest/v1/news_items?sdg_number=eq.1&status=eq.published&order=published_at.desc&limit=5",
        "options": {}
      },
      "id": "fetch-sdg1",
      "name": "Fetch last week SDG1 items",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const items = Array.isArray($input.all()[0].json) ? $input.all()[0].json : [];\nif (!items.length) { return []; }\n\nconst bullets = items.slice(0, 5).map((n, i) =>\n  `${i + 1}. **${n.title_zh}** \u2014 ${n.summary_zh.slice(0, 120)}${n.summary_zh.length > 120 ? '\u2026' : ''}`\n).join('\\n\\n');\n\nconst today = new Date().toISOString().slice(0, 10);\nconst title = `SDG1 \u7d42\u7d50\u8ca7\u7aae \u00b7 \u672c\u9031\u65b0\u805e\u6458\u8981 ${today}`;\nconst bodyMedium = `UN / \u4e16\u754c\u9280\u884c / IISD \u672c\u9031\u5c0d SDG1\uff08\u7d42\u7d50\u8ca7\u7aae\uff09\u76f8\u95dc\u65b0\u805e\u91cd\u9ede\u3002\u9644 Symcio BCI \u8996\u89d2\uff1a\u54c1\u724c\u82e5\u6295\u5165 SDG1 \u884c\u52d5\uff0c\u5c0d\u54c1\u724c\u8cc7\u672c\u7684 F / V / E \u4e09\u8ef8\u5206\u5225\u6709\u4f55\u5f71\u97ff\u3002\\n\\n${bullets}`;\nconst bodyShort = `${items.length} \u5247 SDG1 \u65b0\u805e \u00b7 ${today}`;\n\nreturn [{ json: {\n  kind: 'sdg1_digest',\n  title,\n  body_short: bodyShort,\n  body_medium: bodyMedium,\n  body_long: bodyMedium,\n  link_path: '/news?sdg=1',\n  tags: ['SDG1', '\u7d42\u7d50\u8ca7\u7aae', 'ESG', 'BCI'],\n  channels: ['discord', 'linkedin', 'x', 'threads', 'facebook'],\n  campaign: `sdg1_digest_${today}`,\n} }];"
      },
      "id": "build",
      "name": "Build digest payload",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://symcio.tw/api/publish/broadcast",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $credentials.symcioBroadcast.secret }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyContentType": "json",
        "jsonBody": "={{ JSON.stringify($json) }}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "call-broadcast",
      "name": "Call Symcio broadcast API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "resource": "post",
        "text": "={{ $('Call Symcio broadcast API').item.json.results.linkedin.text }}"
      },
      "id": "linkedin",
      "name": "Post to LinkedIn",
      "type": "n8n-nodes-base.linkedIn",
      "typeVersion": 1,
      "position": [
        1120,
        200
      ],
      "credentials": {
        "linkedInOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "text": "={{ $('Call Symcio broadcast API').item.json.results.x.text }}"
      },
      "id": "x",
      "name": "Post to X",
      "type": "n8n-nodes-base.twitter",
      "typeVersion": 2,
      "position": [
        1120,
        340
      ],
      "credentials": {
        "twitterOAuth2Api": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Weekly Mon 10:00 Taipei": {
      "main": [
        [
          {
            "node": "Fetch last week SDG1 items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch last week SDG1 items": {
      "main": [
        [
          {
            "node": "Build digest payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build digest payload": {
      "main": [
        [
          {
            "node": "Call Symcio broadcast API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call Symcio broadcast API": {
      "main": [
        [
          {
            "node": "Post to LinkedIn",
            "type": "main",
            "index": 0
          },
          {
            "node": "Post to X",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "tags": [
    "symcio",
    "sdg1",
    "weekly"
  ]
}