{
  "name": "Daily Currency Exchange Rate Alert",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 1,10 * * 1-5"
            }
          ]
        }
      },
      "id": "6917af19-058b-4fc0-a0df-9e47ddc08bc0",
      "name": "\u5b9a\u6642\u89f8\u767c\u5668",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        400,
        -160
      ]
    },
    {
      "parameters": {
        "url": "=https://v6.exchangerate-api.com/v6/{{$env.EXCHANGE_API_KEY}}/latest/TWD",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      },
      "id": "8e1c3e0e-8ac2-4ff2-a3e9-3fb7c354e636",
      "name": "\u53d6\u5f97\u5373\u6642\u532f\u7387",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        620,
        -160
      ]
    },
    {
      "parameters": {
        "jsCode": "// \u751f\u6210\u7c21\u5316\u7248\u532f\u7387\u5831\u544a\nconst data = $input.first().json;\nconst now = new Date();\n\n// \u5224\u65b7\u662f\u65e9\u76e4\u9084\u662f\u665a\u76e4 (\u57fa\u65bc UTC \u6642\u9593)\nconst utcHour = now.getUTCHours();\nconst isEveningReport = utcHour >= 10; // UTC 10\u9ede = \u53f0\u531718\u9ede\nconst timeLabel = isEveningReport ? '\u665a\u76e4 18:00' : '\u65e9\u76e4 9:00';\n\nconsole.log(`\u751f\u6210${timeLabel}\u5831\u544a`);\nconsole.log('\u7576\u524d UTC \u6642\u9593:', utcHour + ':' + now.getUTCMinutes());\n\nconst rates = data.conversion_rates;\nif (!rates) {\n  throw new Error('\u627e\u4e0d\u5230\u532f\u7387\u8cc7\u6599');\n}\n\n// \u76ee\u6a19\u8ca8\u5e63\u532f\u7387\u8a08\u7b97\uff08\u65e5\u5713\u6539\u70ba1\u65e5\u5713\u55ae\u4f4d\uff09\nconst currencies = {\n  'USD': { name: '\u7f8e\u5143', flag: '\ud83c\uddfa\ud83c\uddf8', rate: (1/rates.USD).toFixed(2), unit: '1 \u7f8e\u5143' },\n  'JPY': { name: '\u65e5\u5713', flag: '\ud83c\uddef\ud83c\uddf5', rate: (1/rates.JPY).toFixed(4), unit: '1 \u65e5\u5713' },\n  'AUD': { name: '\u6fb3\u5e63', flag: '\ud83c\udde6\ud83c\uddfa', rate: (1/rates.AUD).toFixed(2), unit: '1 \u6fb3\u5e63' },\n  'CAD': { name: '\u52a0\u5e63', flag: '\ud83c\udde8\ud83c\udde6', rate: (1/rates.CAD).toFixed(2), unit: '1 \u52a0\u5e63' }\n};\n\n// \u751f\u6210\u8a0a\u606f\uff08\u6578\u5b57\u66f4\u5927\u66f4\u9192\u76ee\uff09\nconst message = `\ud83d\udcb1 \u53f0\u5e63\u532f\u7387\u5831\u544a \u2502 ${timeLabel}\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n\ud83d\udcca *\u5373\u6642\u532f\u7387 (TWD \u57fa\u6e96)*\n\n${Object.entries(currencies).map(([code, info]) => {\n  return `${info.flag} *${code}*\\t\\t*\\`${info.rate}\\`* \u5143`;\n}).join('\\n')}\n\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n\ud83d\udca1 *\u532f\u7387\u8aaa\u660e\uff1a*\n- ${currencies.USD.unit} = *\\`${currencies.USD.rate}\\`* \u53f0\u5e63\n- ${currencies.JPY.unit} = *\\`${currencies.JPY.rate}\\`* \u53f0\u5e63  \n- ${currencies.AUD.unit} = *\\`${currencies.AUD.rate}\\`* \u53f0\u5e63\n- ${currencies.CAD.unit} = *\\`${currencies.CAD.rate}\\`* \u53f0\u5e63\n\n\ud83d\udd58 *\u4e0b\u6b21\u66f4\u65b0\uff1a* ${isEveningReport ? '\u660e\u65e5\u65e9\u76e4 9:00' : '\u665a\u76e4 18:00'}\n\n\ud83d\udcdd \u8cc7\u6599\u4f86\u6e90\uff1aExchangeRate-API\n\ud83e\udd16 \u7531\u7cfb\u7d71\u81ea\u52d5\u66f4\u65b0`;\n\nconst taiwanTime = new Date(now.getTime() + 8 * 60 * 60 * 1000);\nconsole.log('\u53f0\u5317\u6642\u9593:', taiwanTime.toLocaleString('zh-TW'));\nconsole.log('\u8a0a\u606f\u9577\u5ea6:', message.length);\n\nreturn {\n  json: {\n    message: message,\n    timeLabel: timeLabel,\n    updateTime: taiwanTime.toISOString(),\n    currencies: currencies\n  }\n};"
      },
      "id": "ec99d152-d3e7-4840-9b14-ec0cbeaddb92",
      "name": "\u751f\u6210\u7c21\u5316\u5831\u544a",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        840,
        -160
      ]
    },
    {
      "parameters": {
        "channel": "#n8n-currency",
        "text": "={{$json.message}}",
        "otherOptions": {},
        "attachments": []
      },
      "id": "fc101e68-a029-4421-835a-f760087e5f6a",
      "name": "\u767c\u9001\u5230 Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 1,
      "position": [
        1060,
        -160
      ],
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "\u5b9a\u6642\u89f8\u767c\u5668": {
      "main": [
        [
          {
            "node": "\u53d6\u5f97\u5373\u6642\u532f\u7387",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u53d6\u5f97\u5373\u6642\u532f\u7387": {
      "main": [
        [
          {
            "node": "\u751f\u6210\u7c21\u5316\u5831\u544a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u751f\u6210\u7c21\u5316\u5831\u544a": {
      "main": [
        [
          {
            "node": "\u767c\u9001\u5230 Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "75bbb8b7-18ce-4cf5-9847-b3b2d77e8525",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "6dxyoDlrqpZYcYnY",
  "tags": [
    {
      "createdAt": "2025-06-22T02:38:50.887Z",
      "updatedAt": "2025-06-22T02:38:50.887Z",
      "id": "zqsdwQAC8uguoId9",
      "name": "\u532f\u7387"
    },
    {
      "createdAt": "2025-06-22T02:38:50.890Z",
      "updatedAt": "2025-06-22T02:38:50.890Z",
      "id": "d6lkB0bGQ583pWQt",
      "name": "\u53f0\u5e63"
    }
  ]
}