{
  "id": "8647Dl470mxxSj2Q",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "MS_CURRENCY",
  "tags": [],
  "nodes": [
    {
      "id": "8a30ec34-036d-4b20-b434-1e2d6cd27c98",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -360,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7082fdcf-2877-4f36-b90a-2178ca1505a4",
      "name": "Report: Prepare",
      "type": "n8n-nodes-base.code",
      "position": [
        560,
        0
      ],
      "parameters": {
        "jsCode": "// Input: JSON from exchangerate-api.com\nconst data = $json;\nconst baseCode = data.base_code; // e.g., 'EGP'\nconst rates = data.rates;\nconst lastUpdate = new Date(data.time_last_update_utc).toLocaleDateString('en-US', {\n  month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', hour12: true\n});\n\n// \ud83c\udfaf Choose which currencies you want to see in the report!\nconst targets = [\n  { code: 'USD', emoji: '\ud83c\uddfa\ud83c\uddf8' },\n  { code: 'EUR', emoji: '\ud83c\uddea\ud83c\uddfa' },\n  { code: 'GBP', emoji: '\ud83c\uddec\ud83c\udde7' },\n  { code: 'SAR', emoji: '\ud83c\uddf8\ud83c\udde6' },\n  { code: 'AED', emoji: '\ud83c\udde6\ud83c\uddea' },\n];\n\n// \u270d\ufe0f Build the report message for Telegram\nlet report = `<b>\ud83d\udcb1 Currency Exchange Rates</b>\\n\\n`;\n\nfor (const target of targets) {\n  const rate = rates[target.code];\n  if (rate) {\n    // Calculate 1 of the target currency = ? of the base currency\n    const inverseRate = (1 / rate).toFixed(2);\n    report += `${target.emoji} 1 ${target.code} = <b>${inverseRate} ${baseCode}</b>\\n`;\n  }\n}\n\nreport += `\\n<i>Last updated: ${lastUpdate}</i>`;\n\n// \u2705 Return the text for the next node\nreturn [{\n  json: {\n    telegram_text: report\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "a6a78262-ed4e-4ecd-8fc9-7815548d1838",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        880,
        0
      ],
      "parameters": {
        "text": "={{ $json.telegram_text }}",
        "chatId": "={{ $('Set Currency').item.json.telegram_chat_id }}",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0cbfe028-2702-48fa-9370-a7e218e4aa79",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -140,
        -80
      ],
      "parameters": {
        "color": 5,
        "width": 220,
        "height": 240,
        "content": "## Set inputs \n- currency"
      },
      "typeVersion": 1
    },
    {
      "id": "7a41155a-e736-405e-bb18-3203fdcdf3dd",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        500,
        -80
      ],
      "parameters": {
        "color": 3,
        "width": 220,
        "height": 240,
        "content": "## Report"
      },
      "typeVersion": 1
    },
    {
      "id": "b9bcc84e-b758-4309-b160-1d7d435e86ca",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        820,
        -80
      ],
      "parameters": {
        "color": 6,
        "width": 220,
        "height": 240,
        "content": "## Send"
      },
      "typeVersion": 1
    },
    {
      "id": "b8c88e6d-7a4c-417b-a4e8-1533ebab27b5",
      "name": "Convert Currency",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        240,
        0
      ],
      "parameters": {
        "url": "=https://open.er-api.com/v6/latest/{{ $json.currency }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "1506df90-1c50-4744-b776-ff99e2b0d958",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        180,
        -80
      ],
      "parameters": {
        "color": 3,
        "width": 220,
        "height": 240,
        "content": "## Currrency"
      },
      "typeVersion": 1
    },
    {
      "id": "c90ab53c-8d8a-41b5-86e8-5136e81e6d96",
      "name": "Set Currency",
      "type": "n8n-nodes-base.set",
      "position": [
        -80,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b9f4869a-2059-4b09-84e3-26c7d1e95d30",
              "name": "currency",
              "type": "string",
              "value": "=EGP"
            },
            {
              "id": "593d886f-6c7b-4338-a057-46f2c57a041e",
              "name": "to_currencies",
              "type": "string",
              "value": "=USD,AED,SAR"
            },
            {
              "id": "c58b12b1-b70b-451e-b519-ffb4602c2c9d",
              "name": "telegram_chat_id",
              "type": "string",
              "value": "={{ $env.telegram_chat_id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "ad78b7b5-198f-4eb5-a835-939461b99d94",
  "connections": {
    "Set Currency": {
      "main": [
        [
          {
            "node": "Convert Currency",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Report: Prepare": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Currency": {
      "main": [
        [
          {
            "node": "Report: Prepare",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Set Currency",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}