Sistema de alerta de asteroides cercanos a la Tierra de la NASA

Avanzado

Este es unSocial Mediaflujo de automatización del dominio deautomatización que contiene 16 nodos.Utiliza principalmente nodos como If, Code, Nasa, Slack, SplitOut. Alerta automatizada de asteroidas, usando NASA API, Slack y Google Calendar

Requisitos previos
  • Bot Token de Slack o URL de Webhook

Categoría

Vista previa del flujo de trabajo
Visualización de las conexiones entre nodos, con soporte para zoom y panorámica
Exportar flujo de trabajo
Copie la siguiente configuración JSON en n8n para importar y usar este flujo de trabajo
{
  "id": "qxBmyFKAUjkuc2Wx",
  "meta": {
    "instanceId": "15d6057a37b8367f33882dd60593ee5f6cc0c59310ff1dc66b626d726083b48d",
    "templateCredsSetupCompleted": true
  },
  "name": "NASA Near-Earth Asteroid Alert System",
  "tags": [],
  "nodes": [
    {
      "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "name": "Disparador Programado",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        224,
        304
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 12
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "note1a2b3c4d-5678-90ab-cdef-1234567890ab",
      "name": "Resumen del Flujo de Trabajo",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        16
      ],
      "parameters": {
        "color": 5,
        "width": 300,
        "height": 264,
        "content": "## NASA Asteroid Alert Workflow\n\nThis workflow automatically checks for near-Earth asteroids twice daily using NASA's API and sends alerts to Slack and Google Calendar.\n\n**Process:**\n1. Runs on a 12-hour schedule.\n2. Fetches asteroid data for the next 14 days.\n3. Filters for significant objects.\n4. Notifies via Slack & creates Calendar events."
      },
      "typeVersion": 1
    },
    {
      "id": "b2c3d4e5-f678-90ab-cdef-234567890abc",
      "name": "Calcular Rango de Fechas",
      "type": "n8n-nodes-base.code",
      "position": [
        464,
        304
      ],
      "parameters": {
        "jsCode": "// Calculate date range for API request\nconst today = new Date();\nconst nextWeek = new Date();\nnextWeek.setDate(today.getDate() + 14);\n\n// Format dates as YYYY-MM-DD\nconst formatDate = (date) => {\n  const year = date.getFullYear();\n  const month = String(date.getMonth() + 1).padStart(2, '0');\n  const day = String(date.getDate()).padStart(2, '0');\n  return `${year}-${month}-${day}`;\n};\n\nreturn [{\n  json: {\n    start_date: formatDate(today),\n    end_date: formatDate(nextWeek),\n    today: formatDate(today),\n    next_week: formatDate(nextWeek)\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "note2b3c4d5e-6789-0abc-def1-234567890abc",
      "name": "Nota Clave API",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        16
      ],
      "parameters": {
        "color": 6,
        "width": 280,
        "height": 260,
        "content": "## ⚙️ NASA API Configuration\n\n**Action Required:** Replace the default `DEMO_KEY` with your own NASA API key in the 'Get an asteroid neo feed' node.\n\n1. **Get a free key at:** [api.nasa.gov](https://api.nasa.gov/)\n2. **Why?** The demo key has very strict rate limits and is not suitable for regular use."
      },
      "typeVersion": 1
    },
    {
      "id": "d4e5f678-90ab-cdef-1234-567890abcdef",
      "name": "Filtrar y Procesar Asteroides",
      "type": "n8n-nodes-base.code",
      "position": [
        992,
        304
      ],
      "parameters": {
        "jsCode": "// Get all individual asteroid items from the input\nconst allAsteroidItems = $input.all();\n\n// Configuration thresholds (テスト用の緩い値)\nconst MAX_DISTANCE_KM = 75000000000; // 75 billion km\nconst MIN_DIAMETER_METERS = 1;       // 1 meter\n\nconst filteredAsteroids = [];\n\n// Loop through each asteroid item that was passed to this node\nfor (const item of allAsteroidItems) {\n  const asteroid = item.json; // Get the actual asteroid data from the item\n\n  // Ensure the necessary data exists before trying to process it\n  if (asteroid && asteroid.close_approach_data && asteroid.close_approach_data.length > 0) {\n    const missDistance = parseFloat(asteroid.close_approach_data[0].miss_distance.kilometers);\n    const maxDiameter = asteroid.estimated_diameter.meters.estimated_diameter_max;\n    const minDiameter = asteroid.estimated_diameter.meters.estimated_diameter_min;\n    const avgDiameter = (maxDiameter + minDiameter) / 2;\n\n    // Apply filters\n    if (missDistance <= MAX_DISTANCE_KM && avgDiameter >= MIN_DIAMETER_METERS) {\n      filteredAsteroids.push({\n        name: asteroid.name,\n        id: asteroid.id,\n        approach_date: asteroid.close_approach_data[0].close_approach_date,\n        approach_date_full: asteroid.close_approach_data[0].close_approach_date_full,\n        miss_distance_km: Math.round(missDistance),\n        miss_distance_lunar: parseFloat(asteroid.close_approach_data[0].miss_distance.lunar).toFixed(2),\n        diameter_min_m: Math.round(minDiameter),\n        diameter_max_m: Math.round(maxDiameter),\n        diameter_avg_m: Math.round(avgDiameter),\n        velocity_km_h: Math.round(parseFloat(asteroid.close_approach_data[0].relative_velocity.kilometers_per_hour)),\n        is_potentially_hazardous: asteroid.is_potentially_hazardous_asteroid,\n        nasa_jpl_url: asteroid.nasa_jpl_url,\n        absolute_magnitude: asteroid.absolute_magnitude_h\n      });\n    }\n  }\n}\n\n// Sort by closest approach distance\nfilteredAsteroids.sort((a, b) => a.miss_distance_km - b.miss_distance_km);\n\n// Return the final list of asteroids that met the criteria\nreturn filteredAsteroids.map(asteroid => ({ json: asteroid }));"
      },
      "typeVersion": 2
    },
    {
      "id": "note3c4d5e6f-7890-abcd-ef12-34567890abcd",
      "name": "Configuración de Filtro",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        -16
      ],
      "parameters": {
        "color": 3,
        "width": 280,
        "height": 280,
        "content": "## ⚙️ Filtering Criteria\n\nThis node filters asteroids to find only significant ones. **You should adjust these values.**\n\n**Default (Test) Values:**\n- `MAX_DISTANCE_KM = 75000000000` (very far)\n- `MIN_DIAMETER_METERS = 1` (very small)\n\n**Recommended Values:**\n- `MAX_DISTANCE_KM = 7500000` (7.5 million km)\n- `MIN_DIAMETER_METERS = 100` (100 meters)\n\n**Action:** Edit the code in this node to customize your alert sensitivity."
      },
      "typeVersion": 1
    },
    {
      "id": "e5f67890-abcd-ef12-3456-7890abcdef12",
      "name": "Verificar si se Encontraron Asteroides",
      "type": "n8n-nodes-base.if",
      "position": [
        1376,
        304
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567891",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $items().length }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "f6789012-3456-7890-abcd-ef1234567890",
      "name": "Formatear Mensajes de Alerta",
      "type": "n8n-nodes-base.code",
      "position": [
        1648,
        192
      ],
      "parameters": {
        "jsCode": "// Format message for Slack/Email\nconst asteroids = $input.all();\nconst messageLines = [];\n\nmessageLines.push('🚨 *NEAR-EARTH ASTEROID ALERT* 🚨');\nmessageLines.push('');\nmessageLines.push(`Found ${asteroids.length} asteroid(s) meeting alert criteria:`);\nmessageLines.push('');\n\nasteroids.forEach((item, index) => {\n  const asteroid = item.json;\n  const hazardIcon = asteroid.is_potentially_hazardous ? '⚠️' : '✓';\n  \n  messageLines.push(`*${index + 1}. ${asteroid.name}* ${hazardIcon}`);\n  messageLines.push(`   • Approach Date: ${asteroid.approach_date}`);\n  messageLines.push(`   • Distance: ${asteroid.miss_distance_km.toLocaleString()} km (${asteroid.miss_distance_lunar} lunar distances)`);\n  messageLines.push(`   • Size: ${asteroid.diameter_min_m}-${asteroid.diameter_max_m} meters`);\n  messageLines.push(`   • Speed: ${asteroid.velocity_km_h.toLocaleString()} km/h`);\n  messageLines.push(`   • Details: ${asteroid.nasa_jpl_url}`);\n  messageLines.push('');\n});\n\nmessageLines.push('_Data source: NASA Near Earth Object Web Service_');\n\nreturn [{\n  json: {\n    slackMessage: messageLines.join('\\n'),\n    emailSubject: `🚨 Asteroid Alert: ${asteroids.length} Near-Earth Object(s) Detected`,\n    emailBody: messageLines.join('\\n').replace(/\\*/g, '').replace(/_/g, ''),\n    asteroidCount: asteroids.length,\n    asteroids: asteroids.map(a => a.json)\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "78901234-5678-90ab-cdef-123456789012",
      "name": "Enviar Alerta Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        1840,
        64
      ],
      "webhookId": "927fb2da-a34d-40b5-a589-e67716049dd1",
      "parameters": {
        "text": "={{ $json.slackMessage }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C09KTEYDKDY",
          "cachedResultName": "サポートチーム"
        },
        "otherOptions": {
          "mrkdwn": true
        },
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "id": "BX5igCUXrjyHLAU1",
          "name": "Slack account 5"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "note4d5e6f78-90ab-cdef-1234-567890abcdef",
      "name": "Configuración Slack",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1504,
        -80
      ],
      "parameters": {
        "color": 4,
        "width": 280,
        "height": 244,
        "content": "## ⚙️ Slack Configuration\n\n**Setup Required:**\n1. Select the 'Send Slack Alert' node.\n2. Add your Slack OAuth2 credentials.\n3. Choose the channel for alerts (e.g., `#asteroid-alerts`).\n\nEnsure the n8n app has permission to post in the selected channel."
      },
      "typeVersion": 1
    },
    {
      "id": "90123456-7890-abcd-ef12-345678901234",
      "name": "Separar Asteroides Individuales",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1840,
        304
      ],
      "parameters": {
        "include": "selectedOtherFields",
        "options": {},
        "fieldToSplitOut": "asteroids",
        "fieldsToInclude": "emailSubject, slackMessage"
      },
      "typeVersion": 1
    },
    {
      "id": "note6f78901a-bcde-f123-4567-890abcdef123",
      "name": "Configuración de Calendario",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1920,
        512
      ],
      "parameters": {
        "width": 280,
        "height": 264,
        "content": "## ⚙️ Google Calendar Setup\n\nThis branch creates a calendar event for *each* asteroid found.\n\n**Setup Required:**\n1. Select the 'Create an event' node.\n2. Add your Google Calendar OAuth2 credentials.\n3. Select your desired calendar.\n\n**Customization:** You can modify the event title, description, and even add color-coding based on hazard level."
      },
      "typeVersion": 1
    },
    {
      "id": "note7890abcd-ef12-3456-7890-abcdef123456",
      "name": "Nota Sin Resultados",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1296,
        480
      ],
      "parameters": {
        "color": 7,
        "width": 280,
        "height": 224,
        "content": "## No Asteroids Branch\n\nThis is the 'false' branch of the IF node. It's triggered when no asteroids meet the filtering criteria.\n\nThe **NoOp** node does nothing, ending the workflow silently.\n\n**Idea:** Replace this with a node that sends a daily \"All Clear\" message."
      },
      "typeVersion": 1
    },
    {
      "id": "8da8e937-6acf-43d7-8a7e-43635b7abfde",
      "name": "Obtener un feed de asteroides neo",
      "type": "n8n-nodes-base.nasa",
      "position": [
        720,
        304
      ],
      "parameters": {
        "resource": "asteroidNeoFeed",
        "additionalFields": {}
      },
      "credentials": {
        "nasaApi": {
          "id": "gvg1cGvjElgkwNpP",
          "name": "NASA account 2"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9c7340e9-6b56-4888-8180-373942e5d1d7",
      "name": "Crear un evento",
      "type": "n8n-nodes-base.googleCalendar",
      "position": [
        2064,
        304
      ],
      "parameters": {
        "start": "={{ $json.asteroids.approach_date_full }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "t.minamig20@gmail.com",
          "cachedResultName": "t.minamig20@gmail.com"
        },
        "additionalFields": {
          "summary": "小惑星接近アラート",
          "description": "=接近距離: {{ $json.asteroids.miss_distance_km.toLocaleString() }} km \n直径: 約{{ $json.asteroids.diameter_avg_m }} m \n速度: {{ $json.asteroids.velocity_km_h.toLocaleString() }} km/h \n詳細URL: {{ $json.asteroids.nasa_jpl_url }}"
        }
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "5lKtFJo2lfQL9TkJ",
          "name": "Google Calendar account 12"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "89d59b68-b6a1-43c3-8968-c6710a561032",
      "name": "Sin Operación, no hacer nada",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1616,
        400
      ],
      "parameters": {},
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "timezone": "America/New_York",
    "errorWorkflow": "",
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true,
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "all"
  },
  "versionId": "80885207-ba21-410d-b306-fc5bc0e8e339",
  "connections": {
    "a1b2c3d4-e5f6-7890-abcd-ef1234567890": {
      "main": [
        [
          {
            "node": "b2c3d4e5-f678-90ab-cdef-234567890abc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "b2c3d4e5-f678-90ab-cdef-234567890abc": {
      "main": [
        [
          {
            "node": "8da8e937-6acf-43d7-8a7e-43635b7abfde",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "f6789012-3456-7890-abcd-ef1234567890": {
      "main": [
        [
          {
            "node": "78901234-5678-90ab-cdef-123456789012",
            "type": "main",
            "index": 0
          },
          {
            "node": "90123456-7890-abcd-ef12-345678901234",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e5f67890-abcd-ef12-3456-7890abcdef12": {
      "main": [
        [
          {
            "node": "f6789012-3456-7890-abcd-ef1234567890",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "89d59b68-b6a1-43c3-8968-c6710a561032",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "8da8e937-6acf-43d7-8a7e-43635b7abfde": {
      "main": [
        [
          {
            "node": "d4e5f678-90ab-cdef-1234-567890abcdef",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "d4e5f678-90ab-cdef-1234-567890abcdef": {
      "main": [
        [
          {
            "node": "e5f67890-abcd-ef12-3456-7890abcdef12",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "90123456-7890-abcd-ef12-345678901234": {
      "main": [
        [
          {
            "node": "9c7340e9-6b56-4888-8180-373942e5d1d7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Preguntas frecuentes

¿Cómo usar este flujo de trabajo?

Copie el código de configuración JSON de arriba, cree un nuevo flujo de trabajo en su instancia de n8n y seleccione "Importar desde JSON", pegue la configuración y luego modifique la configuración de credenciales según sea necesario.

¿En qué escenarios es adecuado este flujo de trabajo?

Avanzado - Redes sociales

¿Es de pago?

Este flujo de trabajo es completamente gratuito, puede importarlo y usarlo directamente. Sin embargo, tenga en cuenta que los servicios de terceros utilizados en el flujo de trabajo (como la API de OpenAI) pueden requerir un pago por su cuenta.

Información del flujo de trabajo
Nivel de dificultad
Avanzado
Número de nodos16
Categoría1
Tipos de nodos9
Descripción de la dificultad

Adecuado para usuarios avanzados, flujos de trabajo complejos con 16+ nodos

Autor
Yusuke Yamamoto

Yusuke Yamamoto

@yusuke-yamamoto

Business creator from Tokyo. Designing AI-driven automations that enhance marketing, reporting, and daily operations. I turn complex workflows into simple, elegant automations with n8n.

Enlaces externos
Ver en n8n.io

Compartir este flujo de trabajo

Categorías

Categorías: 34