{
  "name": "KisanAlert_Weather_Updates_Telegram",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "value": "0 6 * * *"
            }
          ]
        }
      },
      "id": "node_trigger_cron",
      "name": "Daily 6AM Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        100,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:5000/api/farms/active-list",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-n8n-api-key",
              "value": "={{$env.JWT_SECRET}}"
            }
          ]
        },
        "options": {}
      },
      "id": "node_fetch_farms",
      "name": "Fetch Active Farms",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        280,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://api.open-meteo.com/v1/forecast",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "latitude",
              "value": "={{$json.latitude || 16.306}}"
            },
            {
              "name": "longitude",
              "value": "={{$json.longitude || 80.436}}"
            },
            {
              "name": "current",
              "value": "temperature_2m,relative_humidity_2m,rain"
            }
          ]
        }
      },
      "id": "node_open_meteo",
      "name": "Query Open-Meteo",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://generativelanguage.googleapis.com/v1/{{$env.GEMINI_FAST_MODEL || 'models/gemini-2.5-flash-lite'}}:generateContent?key={{$env.GEMINI_API_KEY}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"contents\": [{\"parts\":[{\"text\": \"You are an agricultural advisor. Weather parameters: Temp {{$json.current.temperature_2m}}C, Rain {{$json.current.rain}}mm. Write a 1-sentence simple agricultural sowing/irrigation alert for the farmer.\"}]}]}",
        "options": {}
      },
      "id": "node_gemini_advisory_http",
      "name": "Gemini AI Advisory (HTTP)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        640,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{$env.TELEGRAM_BOT_TOKEN}}/sendMessage",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"chat_id\": \"{{$env.TELEGRAM_CHAT_ID}}\", \"text\": \"\ud83c\udf31 Kisan Alert Advisory: {{$json.candidates[0].content.parts[0].text}}\"}",
        "options": {}
      },
      "id": "node_telegram_notify",
      "name": "Send Telegram Alert",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        820,
        300
      ]
    }
  ],
  "connections": {
    "Daily 6AM Cron": {
      "main": [
        [
          {
            "node": "Fetch Active Farms",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Active Farms": {
      "main": [
        [
          {
            "node": "Query Open-Meteo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query Open-Meteo": {
      "main": [
        [
          {
            "node": "Gemini AI Advisory (HTTP)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini AI Advisory (HTTP)": {
      "main": [
        [
          {
            "node": "Send Telegram Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}