{
  "name": "Sunday Grocery Assistant v2",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "grocery-assistant",
        "responseMode": "onReceived",
        "responseData": "allEntries"
      },
      "id": "webhook-trigger",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300],
      "webhookId": "grocery-assistant"
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://nominatim.openstreetmap.org/reverse?lat={{ $json.body.lat }}&lon={{ $json.body.lon }}&format=json",
        "options": {},
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "OpenClaw-GroceryAssistant/1.0"
            }
          ]
        }
      },
      "id": "reverse-geocode",
      "name": "Reverse Geocode",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "jsCode": "const geo = $input.first().json;\nconst address = geo.address || {};\n\n// Extract location info\nconst city = address.city || address.town || address.village || address.county || 'Unknown';\nconst state = address.state || '';\nconst dayOfWeek = new Date().toLocaleDateString('en-US', { weekday: 'long' });\nconst isSunday = dayOfWeek === 'Sunday';\nconst isWednesday = dayOfWeek === 'Wednesday';\n\n// Determine budget based on day\nlet budget = 80; // default Sunday\nlet shopType = 'Sunday big shop';\nif (isWednesday) {\n  budget = 50;\n  shopType = 'Wednesday restock';\n}\n\nreturn {\n  city,\n  state,\n  fullLocation: `${city}, ${state}`,\n  dayOfWeek,\n  budget,\n  shopType,\n  lat: geo.lat,\n  lon: geo.lon\n};"
      },
      "id": "parse-location",
      "name": "Parse Location",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [680, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://192.168.7.6:18789/hooks/agent",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer grocery-webhook-token-2026"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"message\": \"{{ $json.shopType }} triggered.\\n\\n**Location:** {{ $json.fullLocation }}\\n**Budget:** ${{ $json.budget }}\\n**Day:** {{ $json.dayOfWeek }}\\n\\nExecute the full grocery workflow:\\n1. Research deals at nearby stores (get actual prices)\\n2. Search Mealie for recipes using sale ingredients\\n3. Create shopping list in Mealie\\n4. Create meal plan in Mealie\\n5. Verify total is under ${{ $json.budget }}\\n6. Send summary to Signal\\n\\nDo not send generic advice. Do the actual work. Create real lists and plans in Mealie.\"\n}"
      },
      "id": "trigger-pantry",
      "name": "Trigger Pantry Agent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, 300]
    },
    {
      "parameters": {
        "jsCode": "// Log the response from OpenClaw\nconst response = $input.first().json;\nreturn {\n  status: 'triggered',\n  openclawResponse: response,\n  timestamp: new Date().toISOString()\n};"
      },
      "id": "log-response",
      "name": "Log Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1120, 300]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Reverse Geocode",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reverse Geocode": {
      "main": [
        [
          {
            "node": "Parse Location",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Location": {
      "main": [
        [
          {
            "node": "Trigger Pantry Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger Pantry Agent": {
      "main": [
        [
          {
            "node": "Log Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": ["grocery", "pantry"],
  "triggerCount": 0,
  "pinData": {}
}
