{
 "id": "realfxratealert",
 "name": "AutomateRecipes \u2013 fx-rate-alert",
 "nodes": [
  {
   "parameters": {
    "rule": {
     "interval": [
      {
       "field": "days",
       "triggerAtHour": 9
      }
     ]
    }
   },
   "name": "Schedule Trigger",
   "type": "n8n-nodes-base.scheduleTrigger",
   "typeVersion": 1.2,
   "position": [
    0,
    0
   ],
   "id": "387d00e1-2bd4-4ec0-8f1a-8ce1cffa62fb"
  },
  {
   "parameters": {
    "jsCode": "// EDIT THESE SETTINGS\nreturn [{json:{\n \"ntfyTopic\": \"CHANGE-ME-to-a-long-random-topic\",\n \"base\": \"USD\",\n \"quote\": \"EUR\",\n \"alertBelow\": 0.85,\n \"alertAbove\": 1.2\n}}];"
   },
   "name": "Config",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    240,
    0
   ],
   "id": "97660779-1a5d-4304-a588-1a40827a342f"
  },
  {
   "parameters": {
    "url": "=https://api.frankfurter.app/latest?from={{ $json.base }}&to={{ $json.quote }}",
    "options": {
     "timeout": 15000
    }
   },
   "name": "Get ECB rate (Frankfurter)",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "position": [
    480,
    0
   ],
   "id": "bf4f4430-1313-4348-b985-5a3d3b066672"
  },
  {
   "parameters": {
    "jsCode": "const c=$('Config').first().json,r=$input.first().json.rates[c.quote];if(typeof r!=='number')throw new Error('no rate');const msg=`1 ${c.base} = ${r} ${c.quote} (ECB, ${$input.first().json.date})`;if(r>=c.alertBelow&&r<=c.alertAbove)return [];return [{json:{title:`Exchange rate alert: ${c.base}/${c.quote}`,tags:'chart_with_upwards_trend',message:msg+(r<c.alertBelow?` - below ${c.alertBelow}`:` - above ${c.alertAbove}`),rate:r}}];"
   },
   "name": "Check thresholds",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    720,
    0
   ],
   "id": "76034e63-b16a-4fa5-a0e1-357fed4f498b"
  },
  {
   "parameters": {
    "method": "POST",
    "url": "=https://ntfy.sh/{{ $('Config').first().json.ntfyTopic }}",
    "sendHeaders": true,
    "headerParameters": {
     "parameters": [
      {
       "name": "Title",
       "value": "={{ $json.title }}"
      },
      {
       "name": "Tags",
       "value": "={{ $json.tags || 'bell' }}"
      }
     ]
    },
    "sendBody": true,
    "contentType": "raw",
    "rawContentType": "text/plain",
    "body": "={{ $json.message }}",
    "options": {}
   },
   "name": "Send ntfy alert",
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "position": [
    960,
    0
   ],
   "id": "a45eddf2-243d-4f6d-8210-c1ab80840aac"
  },
  {
   "parameters": {},
   "name": "Run manually (test)",
   "type": "n8n-nodes-base.manualTrigger",
   "typeVersion": 1,
   "position": [
    0,
    200
   ],
   "id": "d34aa599-6674-4b76-ada6-bd68ca88f78c"
  }
 ],
 "connections": {
  "Schedule Trigger": {
   "main": [
    [
     {
      "node": "Config",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Config": {
   "main": [
    [
     {
      "node": "Get ECB rate (Frankfurter)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Get ECB rate (Frankfurter)": {
   "main": [
    [
     {
      "node": "Check thresholds",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Check thresholds": {
   "main": [
    [
     {
      "node": "Send ntfy alert",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Run manually (test)": {
   "main": [
    [
     {
      "node": "Config",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1"
 },
 "active": false,
 "pinData": {}
}