{
  "id": "j0iDG6Dv5amsch9s",
  "name": "Ride Booking App Monitoring",
  "tags": [],
  "nodes": [
    {
      "id": "7750aee5-d8bb-4956-ae7d-06c96c502acb",
      "name": "Alert: Send Surge Slack Notification",
      "type": "n8n-nodes-base.slack",
      "position": [
        176,
        208
      ],
      "parameters": {
        "text": "=Ride Update\n\nHi! Prices are currently higher than usual in your area.\n\n City: {{ $json.city }}\n Ride_price:{{ $json.ride_price }}\n Current Price: \u20b9{{ $json.ride_price }}\n Estimated Wait Time: {{ $json.wait_time }} mins\n\nYou may experience delays or higher fares right now.\n\n Tip: You can try again after some time for better prices.\n\n {{ $now }}",
        "user": {
          "__rl": true,
          "mode": "list",
          "value": "USLACKBOT",
          "cachedResultName": "slackbot"
        },
        "select": "user",
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "5d0137cd-3c4a-4065-952b-143a5f996547",
      "name": "Send Error Report to Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        816,
        1056
      ],
      "parameters": {
        "text": "=Hi! Here\u2019s an update on your ride issue:\n\n City: {{ $('Structure Error Context Data').item.json.user_id }}\n\n Problem:{{ $json.incident_summary }}\n\n What likely happened:\n{{ $json.probable_cause }}\n\n What you can do:\n- {{ $json.recommended_actions[0] }}\n- {{ $json.recommended_actions[1] }}\n\n Please try again in a few moments.\nWe\u2019re working to improve your experience.\n\n {{ $now }}",
        "user": {
          "__rl": true,
          "mode": "list",
          "value": "USLACKBOT",
          "cachedResultName": "slackbot"
        },
        "select": "user",
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "661772d7-69e2-4fd4-b63b-31dfb9283e80",
      "name": "Start Workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1376,
        512
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "5b2dfd67-7007-4be2-b2cc-a72e0c85a9a7",
      "name": "Process Each Ride Event",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -992,
        336
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "79671e62-850e-4fea-a7e8-7351bb561fa4",
      "name": "Control Processing Delay",
      "type": "n8n-nodes-base.wait",
      "position": [
        -864,
        512
      ],
      "parameters": {
        "amount": 3
      },
      "typeVersion": 1.1
    },
    {
      "id": "15c4f139-d934-4f8a-abee-1f01b0b8de24",
      "name": "Split Event vs Error Flow",
      "type": "n8n-nodes-base.switch",
      "position": [
        -432,
        512
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Event Flow",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "4e53e2e5-1ee7-43ca-a8c1-2ebb1f16a8f7",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "event"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Error Flow",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "05d72090-9898-42fb-8763-96895581dffe",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.type }}",
                    "rightValue": "error"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {},
        "looseTypeValidation": true
      },
      "typeVersion": 3.4,
      "alwaysOutputData": true
    },
    {
      "id": "e174b60b-0cea-442c-97e7-7f0cbd908735",
      "name": "Decision: Detect Surge Pricing & Delay",
      "type": "n8n-nodes-base.if",
      "position": [
        -192,
        352
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "84c784e8-3106-479b-ba87-6c716641e28b",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $('Process Each Ride Event').item.json.ride_price }}",
              "rightValue": "={{ $json.normal_price * 1.5 }}"
            },
            {
              "id": "6b27dba1-f871-4d23-819e-8daf3ba418c0",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $('Process Each Ride Event').item.json.wait_time }}",
              "rightValue": 10
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "25bb67ee-96dc-46d7-bd4a-803527d94ecf",
      "name": "Record Surge Alert Event",
      "type": "n8n-nodes-base.set",
      "position": [
        624,
        208
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e2e218a3-36a8-43c7-ad40-5e12f60a2f8d",
              "name": "log_type",
              "type": "string",
              "value": "event_alert"
            },
            {
              "id": "36e8344b-e9ed-47b3-85af-be1f0b1faa39",
              "name": "log_city",
              "type": "string",
              "value": "={{ $('Split Event vs Error Flow').item.json.city }}"
            },
            {
              "id": "c651540d-4606-4183-a1a5-1c7b0a682561",
              "name": "log_ride_price",
              "type": "string",
              "value": "={{ $('Split Event vs Error Flow').item.json.ride_price }}"
            },
            {
              "id": "aabe23e3-c6cd-440b-b649-1016f9be80bc",
              "name": "log_status",
              "type": "string",
              "value": "Surge Alert Sent via Slack"
            },
            {
              "id": "9efc921d-d600-4564-86a0-428f696fae7e",
              "name": "log_timestamp",
              "type": "string",
              "value": "={{ $now }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a12a4c3d-3b82-44fe-a7f3-a7d6b4ec7407",
      "name": "Record Normal Ride Event",
      "type": "n8n-nodes-base.set",
      "position": [
        240,
        608
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a1b2c3d4-+123456789001",
              "name": "log_type",
              "type": "string",
              "value": "event_no_surge"
            },
            {
              "id": "a1b2c3d4-+123456789002",
              "name": "log_city",
              "type": "string",
              "value": "={{ $('Control Processing Delay').item.json.city }}"
            },
            {
              "id": "a1b2c3d4-+123456789003",
              "name": "log_status",
              "type": "string",
              "value": "Normal \u2014 No Alert Needed"
            },
            {
              "id": "a1b2c3d4-+123456789004",
              "name": "log_timestamp",
              "type": "string",
              "value": "={{ $now }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "4a7ce339-51a8-4236-8e02-08f080149bbe",
      "name": "Structure Error Context Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -320,
        1056
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={\n  \"formatted_error\": \"{{ $json.error_message }}\",\n  \"formatted_details\": \"{{ $json.details }}\",\n  \"formatted_user\": \"{{ $json.user_id }}\",\n  \"city\": \"{{ $json.city }}\",\n  \"traffic_status\": \"{{ $json.traffic_status }}\",\n  \"wait_time\": \"{{ $json.wait_time }}\",\n  \"ride_price\": \"{{ $json.ride_price }}\",\n  \"pickup_location\": \"{{ $json.pickup_location }}\",\n  \"drop_location\": \"{{ $json.drop_location }}\"\n}",
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "dd51e3a2-a89f-4418-a0f5-f3eaa6416ecd",
      "name": "Diagnose Issue & Recommend Actions",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        32,
        1056
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a Ride Operations Analyst for a ride-hailing platform.\n\nYour job is to investigate ride issues using system data and external context like traffic and weather.\n\nYou have access to external tools:\n- Weather API (for real-time weather data)\n- Traffic API (for real-time travel time and traffic conditions)\n\n-------------------------\nOUTPUT RULES\n\n- Return ONLY valid JSON\n- Do NOT include any extra text\n- Response MUST start with { and end with }\n- Do NOT leave fields empty (use \"N/A\" if needed)\n\n-------------------------\nERROR DETAILS\n\nError: {{ $json.formatted_error }}\nDetails: {{ $json.formatted_details }}\nUser ID: {{ $json.formatted_user }}\nCity: {{ $json.city }}\n\n-------------------------\nINSTRUCTIONS FOR TOOL USAGE\n\n- If weather data is missing or unclear \u2192 call the Weather API tool\n- If traffic data is missing or unclear \u2192 call the Traffic API tool\n- Use tool results in your analysis\n- Prefer real-time tool data over provided values if available\n\n-------------------------\nWEATHER (mustfetched)\n\nCondition: {{ $json.weather_condition }}\nTemperature: {{ $json.temperature }}\u00b0C\nHumidity: {{ $json.humidity }}%\n\n-------------------------\nTRAFFIC (must fetched)\n\nNormal Travel Time: {{ $json.normal_time }}\nCurrent Travel Time: {{ $json.traffic_time }}\nTraffic Status: {{ $json.traffic_status }}\n\n-------------------------\nRIDE DATA\n\nWait Time: {{ $json.wait_time }} mins\nRide Price: \u20b9{{ $json.ride_price }}\nPickup: {{ $json.pickup_location }}\nDrop: {{ $json.drop_location }}\n\n-------------------------\nANALYSIS\n\n- Combine ride data + traffic + weather\n- Identify the root cause clearly\n- Be short and data-driven\n- Do NOT assume missing data without tool verification\n\nCheck for:\n- High wait time \u2192 driver shortage or traffic\n- High price \u2192 surge demand\n- Traffic delay \u2192 compare normal vs current time\n- Weather impact \u2192 rain, heat, storms\n\n-------------------------\nOUTPUT FORMAT\n\n{\n  \"incident_summary\": \"\",\n  \"probable_cause\": \"\",\n  \"evidence\": {\n    \"traffic_analysis\": \"\",\n    \"weather_analysis\": \"\",\n    \"system_behavior\": \"\",\n    \"historical_match\": \"\"\n  },\n  \"recommended_actions\": [\n    \"\",\n    \"\",\n    \"\"\n  ],\n  \"priority_level\": \"\"\n}"
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "f1867cdc-d442-4746-b149-b9f3fadf56ba",
      "name": "Get Real-Time Traffic Data",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -16,
        1424
      ],
      "parameters": {
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "origins",
              "value": "={{ $json.pickup_location }}"
            },
            {
              "name": "destinations",
              "value": "={{ $json.drop_location }}"
            },
            {
              "name": "departure_time",
              "value": "now"
            },
            {
              "name": "key",
              "value": "AIzaYOUR_GOOGLE_API_KEY_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "c22f8480-a599-40ba-af92-e6042c372999",
      "name": "Get Real-Time Weather Data",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        272,
        1424
      ],
      "parameters": {
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "appid",
              "value": "1f663e6e9f1ea0dc90d89af4fe13d5eb"
            },
            {
              "name": "=q",
              "value": "={{ $json.city }}"
            },
            {
              "name": "units",
              "value": "metric"
            }
          ]
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "ad175f97-ac9c-4b92-bc44-108f9dc09c79",
      "name": "Convert AI Response to JSON",
      "type": "n8n-nodes-base.code",
      "position": [
        448,
        1056
      ],
      "parameters": {
        "jsCode": "// Assuming 'inputString' is the raw text from the previous node\nconst inputString = $input.item.json.content.parts[0].text;\n\n// 1. Remove the markdown wrappers: ```json and ```\nconst cleanJsonString = inputString.replace(/```json\\n|```/g, \"\");\n\n// 2. Parse the string into a real object\nconst extractedData = JSON.parse(cleanJsonString);\n\nreturn extractedData;"
      },
      "typeVersion": 2
    },
    {
      "id": "53e2883d-cf82-4ddc-8b68-a7bc5342448e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2368,
        160
      ],
      "parameters": {
        "width": 784,
        "height": 992,
        "content": "# Ride Booking App Monitoring \n\n\n# How It Works\n### This workflow monitors ride events and errors from Google Sheets. It checks for surge pricing and high wait times\u2014if found, it sends a Slack alert; otherwise, it logs normal events. For errors, it uses AI (Google Gemini) with traffic and weather data to analyze the issue, find the root cause, and send a smart resolution message to Slack.\n\n# Setup Steps\n\n## Prepare Google Sheets\nAdd ride data (type, city, price, wait time, error info, locations).\n\n## Connect Accounts\nSet up Google Sheets, Slack, and Gemini API credentials.\n\n## Add Trigger\nUse Manual Trigger (or Cron/Webhook).\n\n## Process Data\nFetch data then loop and route using Switch (event/error).\n\n## Handle Events\nIF surge then send Slack alert otherwise  log normal event.\n\n## Handle Errors\nFormat data then AI  wil analysis (with traffic & weather) hence it get parse response.\n\n## Notify\nSend final error insights to Slack ."
      },
      "typeVersion": 1
    },
    {
      "id": "ee1ee364-3275-4578-bafe-738b74f2808a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1264,
        192
      ],
      "parameters": {
        "color": 7,
        "width": 656,
        "height": 528,
        "content": "## Data Fetch & Loop\nFetches ride event data from Google Sheets and processes each record one by one using a loop. This ensures every ride event or error is handled individually for accurate monitoring."
      },
      "typeVersion": 1
    },
    {
      "id": "29ed1e66-842c-42a9-8fbf-da6af0a2394d",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -528,
        192
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 544,
        "content": "## Event Routing\nChecks the type of data (event or error) and routes it into separate flows. This helps in applying different logic for normal ride events and system errors."
      },
      "typeVersion": 1
    },
    {
      "id": "de08d22c-8411-4a40-bd5d-561985ddcec1",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        496,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 368,
        "height": 384,
        "content": "## Surge Detection\n\nAnalyzes ride price and wait time to detect surge conditions (high price + long wait). If conditions match, it identifies a potential user impact scenario."
      },
      "typeVersion": 1
    },
    {
      "id": "036b2705-a28f-4237-b938-c1bad122b79c",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 368,
        "height": 384,
        "content": "##  User Alert \n\nSends a Slack notification to inform users about surge pricing and delays. This improves transparency and user experience during high-demand situations."
      },
      "typeVersion": 1
    },
    {
      "id": "ee9a67f6-3e7e-4ff9-a63f-71e42e0d1921",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        464
      ],
      "parameters": {
        "color": 7,
        "width": 448,
        "height": 288,
        "content": "## Normal Event Logging\n\nLogs events where no surge is detected as normal activity. This helps maintain tracking without triggering unnecessary alerts."
      },
      "typeVersion": 1
    },
    {
      "id": "600865f3-509c-4882-a52a-a439d940c9f0",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -464,
        896
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 336,
        "content": "##  Error Data Preparation\n\nFormats error-related data into a structured format for AI processing. This step ensures consistent input for accurate analysis."
      },
      "typeVersion": 1
    },
    {
      "id": "7b7a8d2f-44aa-4bd4-a14e-f1c37699dd65",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        880
      ],
      "parameters": {
        "color": 7,
        "width": 352,
        "height": 352,
        "content": "## AI Error Analysis\n\nUses Google Gemini to analyze ride issues by combining system data with traffic and weather inputs. It identifies root cause, impact, and recommended actions."
      },
      "typeVersion": 1
    },
    {
      "id": "2b1df867-11cc-41fc-a7e0-75d76d9fe6bc",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        1280
      ],
      "parameters": {
        "color": 7,
        "width": 560,
        "height": 304,
        "content": "##  External Data Enrichment\n\nFetches real-time traffic and weather data using APIs when needed. This improves the accuracy of AI-based decision making."
      },
      "typeVersion": 1
    },
    {
      "id": "71db6717-3527-4f8a-ada8-86597ac4224c",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        352,
        880
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 352,
        "content": "##  Response Parsing\n\nCleans and converts AI output into proper JSON format. This makes the data usable for downstream actions."
      },
      "typeVersion": 1
    },
    {
      "id": "bd54ed64-7dc3-474b-b009-85346d9de147",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        880
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 352,
        "content": "##  Error Notification\n\nSends a detailed Slack message with issue summary, cause, and suggested fixes. This enables quick response and better operational visibility"
      },
      "typeVersion": 1
    },
    {
      "id": "79d3f2ef-cf41-488b-9722-38479b612eef",
      "name": "Fetch Ride Events",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1120,
        512
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1658960456,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1D2ARPjyzz4uTSNGRvPMzuzPBeB9eiKBUET14nSOflTY/edit#gid=1658960456",
          "cachedResultName": "ride_events"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1D2ARPjyzz4uTSNGRvPMzuzPBeB9eiKBUET14nSOflTY",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1D2ARPjyzz4uTSNGRvPMzuzPBeB9eiKBUET14nSOflTY/edit?usp=drivesdk",
          "cachedResultName": "ride_events_sample"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "d2ad1b24-99a3-48ec-ace3-2b2dfdf780af",
  "connections": {
    "Start Workflow": {
      "main": [
        [
          {
            "node": "Fetch Ride Events",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Ride Events": {
      "main": [
        [
          {
            "node": "Process Each Ride Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Each Ride Event": {
      "main": [
        [],
        [
          {
            "node": "Control Processing Delay",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Control Processing Delay": {
      "main": [
        [
          {
            "node": "Split Event vs Error Flow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Record Normal Ride Event": {
      "main": [
        [
          {
            "node": "Fetch Ride Events",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Event vs Error Flow": {
      "main": [
        [
          {
            "node": "Decision: Detect Surge Pricing & Delay",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Structure Error Context Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Real-Time Traffic Data": {
      "ai_tool": [
        [
          {
            "node": "Diagnose Issue & Recommend Actions",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Real-Time Weather Data": {
      "ai_tool": [
        [
          {
            "node": "Diagnose Issue & Recommend Actions",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Convert AI Response to JSON": {
      "main": [
        [
          {
            "node": "Send Error Report to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structure Error Context Data": {
      "main": [
        [
          {
            "node": "Diagnose Issue & Recommend Actions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Diagnose Issue & Recommend Actions": {
      "main": [
        [
          {
            "node": "Convert AI Response to JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alert: Send Surge Slack Notification": {
      "main": [
        [
          {
            "node": "Record Surge Alert Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decision: Detect Surge Pricing & Delay": {
      "main": [
        [
          {
            "node": "Alert: Send Surge Slack Notification",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Record Normal Ride Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}