{
  "workflow_id": "discord_price_alert",
  "description": "Checks the Bitcoin price and posts to your Discord channel only when it crosses a line you set. Put your own Discord webhook address in the two alert steps and your own numbers in the two run_if lines.",
  "tasks": [
    {
      "id": "fetch_price",
      "trigger": "manual",
      "action_type": "http_request",
      "target": "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd&include_24hr_change=true",
      "payload": {
        "method": "GET"
      },
      "output": {
        "store_as": "btc",
        "pass_to_next": true
      },
      "next": "alert_if_above"
    },
    {
      "id": "alert_if_above",
      "trigger": "after:fetch_price",
      "action_type": "http_request",
      "target": "https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN",
      "run_if": "{{btc.bitcoin.usd}} >= 100000",
      "payload": {
        "method": "POST",
        "headers": {
          "Content-Type": "application/json"
        },
        "body": {
          "content": "Bitcoin is at or above your line: now {{btc.bitcoin.usd}} USD (24h change {{btc.bitcoin.usd_24h_change}}%)"
        }
      },
      "next": "alert_if_below"
    },
    {
      "id": "alert_if_below",
      "trigger": "after:alert_if_above",
      "action_type": "http_request",
      "target": "https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN",
      "run_if": "{{btc.bitcoin.usd}} <= 80000",
      "payload": {
        "method": "POST",
        "headers": {
          "Content-Type": "application/json"
        },
        "body": {
          "content": "Bitcoin is at or below your line: now {{btc.bitcoin.usd}} USD (24h change {{btc.bitcoin.usd_24h_change}}%)"
        }
      },
      "next": "log_check"
    },
    {
      "id": "log_check",
      "trigger": "after:alert_if_below",
      "action_type": "file_op",
      "target": "{{desktop_dir}}/price_checks.log",
      "payload": {
        "operation": "append",
        "content": "{{date}} checked: Bitcoin {{btc.bitcoin.usd}} USD\n"
      }
    }
  ]
}
