{
  "name": "ST-01 Dashboard",
  "active": true,
  "nodes": [
    {
      "id": "5301660a",
      "name": "Every 5 min",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        256,
        208
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 5
            }
          ]
        }
      }
    },
    {
      "id": "ecf410f2",
      "name": "Get Agent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        208
      ],
      "parameters": {
        "url": "https://api.spacetraders.io/v2/my/agent",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpHeaderAuth",
        "options": {
          "response": {
            "response": {}
          },
          "continueOnFail": true
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "cd733b58",
      "name": "Get Ships",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        704,
        208
      ],
      "parameters": {
        "url": "https://api.spacetraders.io/v2/my/ships",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpHeaderAuth",
        "options": {
          "response": {},
          "continueOnFail": true
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "a7d955d7",
      "name": "Get Contracts",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        928,
        208
      ],
      "parameters": {
        "url": "https://api.spacetraders.io/v2/my/contracts",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpHeaderAuth",
        "options": {
          "response": {},
          "continueOnFail": true
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "838234df",
      "name": "Format",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1152,
        208
      ],
      "parameters": {
        "jsCode": "\nconst staticData = $getWorkflowStaticData('global');\nconst agent     = $('Get Agent').first().json.data;\nconst ships     = $('Get Ships').first().json.data || [];\nconst contracts = $('Get Contracts').first().json.data || [];\n\nconst credits = agent.credits || 0;\nconst lastCredits = staticData.lastCredits;\n\n// Only send if credits changed (or first ever run)\nif (lastCredits !== undefined && lastCredits === credits) {\n  return [];\n}\nstaticData.lastCredits = credits;\n\nconst active = contracts.filter(c => !c.fulfilled).length;\nconst diff   = lastCredits !== undefined ? credits - lastCredits : null;\nconst diffStr = diff !== null ? (diff >= 0 ? ` (+${diff.toLocaleString()})` : ` (${diff.toLocaleString()})`) : '';\n\nconst text = `\ud83d\ude80 <b>HERMES-FLEET Dashboard</b>\n\ud83d\udcb0 Credits: ${credits.toLocaleString()}${diffStr}\n\ud83d\udea2 Ships: ${ships.length}\n\ud83d\udccb Active contracts: ${active}\n\ud83d\udccd HQ: ${agent.headquarters}`;\n\nreturn [{json: {text}}];\n"
      }
    },
    {
      "id": "177b2319",
      "name": "Send Telegram",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1376,
        208
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.telegram.org/bot8983287190:AAGm8Zc1dC5FfLgtJKc2FfnX_AeplMqL56c/sendMessage",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({\"chat_id\":\"7603833558\",\"text\":$json.text,\"parse_mode\":\"HTML\"}) }}",
        "options": {
          "continueOnFail": true
        }
      }
    }
  ],
  "connections": {
    "Every 5 min": {
      "main": [
        [
          {
            "node": "Get Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Agent": {
      "main": [
        [
          {
            "node": "Get Ships",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Ships": {
      "main": [
        [
          {
            "node": "Get Contracts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Contracts": {
      "main": [
        [
          {
            "node": "Format",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format": {
      "main": [
        [
          {
            "node": "Send Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "errorWorkflow": "UBBtoeMsOM2deZTM"
  }
}