{
  "id": "5ZfYOwpQheqVtdoA",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "N-0047 End-of-Day Ops Summary Generator",
  "tags": [],
  "nodes": [
    {
      "id": "9c787b73-61c8-41b3-a749-825fbb234a94",
      "name": "Daily 6 PM Scheduler1",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -880,
        3680
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 18
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "5b6a18f1-3596-4c89-bff1-100dbdfe49a2",
      "name": "AI Email Generator1",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        384,
        3792
      ],
      "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 concise operations analyst.\n\nBased on the data below:\nTotal issues: {{$json.total}}\nResolved: {{$json.resolved}}\nPending: {{$json.pending}}\nSeverity: {{$json.severity}}\nTrend: {{$json.trend}}\n\nGenerate output in this EXACT format (do not change labels):\n\nSummary:\n<one short sentence including severity and trend>\n\nEmail:\n<professional end-of-day email under 120 words. Clearly mention severity and trend. If pending > 5, include \"ACTION NEEDED\". End with \"Ops Automation\">\n\nRules:\n- Do NOT add anything before or after this format\n- Do NOT rename \"Summary:\" or \"Email:\"\n- Keep it clean and structured"
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "994d96a1-84a6-4362-9ec3-03bfd891cf6b",
      "name": "Fetch Trade Breaks Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -576,
        3504
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Enib8AZ2_xj1vBnCrcKkICUbC9J0JeDrrOlYnwzuh28",
          "cachedResultName": "End of the day oops summary"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "5775f5c4-7521-47fc-af0c-12b21fbe9c20",
      "name": "Fetch Failed Trades Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -576,
        3680
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 941074853,
          "cachedResultName": "Sheet2"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Enib8AZ2_xj1vBnCrcKkICUbC9J0JeDrrOlYnwzuh28",
          "cachedResultName": "End of the day oops summary"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "4d34a574-9f63-491d-bd2d-83a7be2783c5",
      "name": "Fetch Exceptions Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -560,
        3872
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 615911534,
          "cachedResultName": "Sheet3"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Enib8AZ2_xj1vBnCrcKkICUbC9J0JeDrrOlYnwzuh28",
          "cachedResultName": "End of the day oops summary"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "2d6cd30f-5ce3-445b-bf05-f7cb7aeee4f9",
      "name": "Merge Trades and Breaks",
      "type": "n8n-nodes-base.merge",
      "position": [
        -400,
        3600
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "d10da9bf-8c99-4e83-aac8-19206aab780d",
      "name": "Merge All Sources",
      "type": "n8n-nodes-base.merge",
      "position": [
        -336,
        3808
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "1e4a3251-cbe8-4eed-b9dc-257cb5d2fef7",
      "name": "Filter Valid Records",
      "type": "n8n-nodes-base.if",
      "position": [
        -160,
        3808
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1cb6cc07-d79a-46d0-a85c-495ceb9ec347",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{$json.Status}}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "1d9402cc-62be-4a15-a06c-35fbc8e6f696",
      "name": "Calculate Resolved vs Pending",
      "type": "n8n-nodes-base.code",
      "position": [
        32,
        3792
      ],
      "parameters": {
        "jsCode": "let resolved = 0;\nlet pending = 0;\n\nitems.forEach(item => {\n  if (item.json.Status && item.json.Status.toLowerCase() === 'resolved') {\n    resolved++;\n  } else {\n    pending++;\n  }\n});\n\nreturn [\n  {\n    json: {\n      total: items.length,\n      resolved,\n      pending\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "e3a3e00f-2c11-4918-809a-fd2724759f39",
      "name": "Compute Severity & Trend",
      "type": "n8n-nodes-base.code",
      "position": [
        208,
        3792
      ],
      "parameters": {
        "jsCode": "const item = items[0].json;\nconst total = item.total;\nconst pending = item.pending;\nconst resolved = item.resolved;\n\nlet severity = 'LOW';\nif (pending > 10) severity = 'CRITICAL';\nelse if (pending > 5) severity = 'HIGH';\nelse if (pending > 2) severity = 'MEDIUM';\n\nlet trend = 'STABLE';\nif (pending > resolved) trend = 'WORSENING';\nelse if (resolved > pending) trend = 'IMPROVING';\n\nreturn [{ json: { total, resolved, pending, severity, trend } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "db25337a-4800-4489-b72e-4154eda77fee",
      "name": "Check High Pending Condition",
      "type": "n8n-nodes-base.if",
      "position": [
        672,
        3792
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "pending-check-001",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $('Compute Severity & Trend').item.json.pending }}",
              "rightValue": 5
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "76bf3cc4-ca0f-4ae3-8ed2-13003eab3443",
      "name": "Extract Email Body",
      "type": "n8n-nodes-base.set",
      "position": [
        1040,
        3808
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "field-message",
              "name": "message",
              "type": "string",
              "value": "={{ $('AI Email Generator1').item.json.content.parts[0].text.split(\"Email:\")[1]?.replace(/Subject:.*\\n?/i, '').trim() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "489c4ca3-c940-4ec5-906f-8c12cc866b01",
      "name": "Send Slack Alert (High Priority)",
      "type": "n8n-nodes-base.slack",
      "position": [
        848,
        3584
      ],
      "parameters": {
        "text": "=*End-of-Day Ops Alert* \u2014 {{$now.format('dd MMM yyyy')}}\n\n*Pending Issues:* {{ $('Compute Severity & Trend').item.json.pending }} (ACTION NEEDED)\n*Severity:* {{ $('Compute Severity & Trend').item.json.severity }}\n*Trend:* {{ $('Compute Severity & Trend').item.json.trend }}\n*Total Today:* {{ $('Compute Severity & Trend').item.json.total }}\n*Resolved:* {{ $('Compute Severity & Trend').item.json.resolved }}\n\nPlease review the ops dashboard immediately.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AP6S28KM3",
          "cachedResultName": "all-aishvarya"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "0956f1bc-d0ee-4082-b1b3-f95871592bec",
      "name": "Send EOD Summary Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1232,
        3808
      ],
      "parameters": {
        "message": "={{$json.message}}",
        "options": {
          "senderName": "Ops Automation",
          "appendAttribution": false
        },
        "subject": "=End-of-Day Ops Summary \u2014 {{$now.format('dd MMM yyyy')}} | {{ $('Compute Severity & Trend').item.json.severity }} | {{$('Compute Severity & Trend').item.json.pending > 5 ? 'ACTION NEEDED' : 'All Clear'}}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "1dc0214a-ad68-4618-979c-beafeaeb1b47",
      "name": "Store Summary in Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1456,
        3808
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date": "={{$now}}",
            "Total": "={{ $('Compute Severity & Trend').item.json.total }}",
            "Trend ": "={{ $('Compute Severity & Trend').item.json.trend }}",
            "Pending": "={{ $('Compute Severity & Trend').item.json.pending }}",
            "Summary": "={{ $('AI Email Generator1').item.json.content.parts[0].text.split(\"Email:\")[0].replace(\"Summary:\", \"\").trim() }}",
            "Resolved": "={{ $('Compute Severity & Trend').item.json.resolved }}",
            "Serverity": "={{ $('Compute Severity & Trend').item.json.severity }}"
          },
          "schema": [
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Total",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Total",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Resolved",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Resolved",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Pending",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Pending",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Serverity",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Serverity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Trend ",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Trend ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Summary",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 565093658,
          "cachedResultName": "Sheet4"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Enib8AZ2_xj1vBnCrcKkICUbC9J0JeDrrOlYnwzuh28",
          "cachedResultName": "End of the day oops summary"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "0bc87c8b-d2b3-4515-b228-b7228fc448c6",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -848,
        2864
      ],
      "parameters": {
        "width": 432,
        "height": 400,
        "content": "##  End-of-Day Ops Summary Generator\n## How it works:\nThis workflow runs daily at 6 PM, fetches trade, break, and exception data from Google Sheets, merges and filters valid records, and calculates total, resolved, and pending issues. It then determines severity and trend, generates an AI-based summary, and sends alerts via Slack and email.\n\n## Setup steps:\n1. Connect Google Sheets account\n2. Configure Slack and Gmail credentials\n3. Update sheet IDs and column names\n4. Verify Gemini API key\n5. Test workflow manually before scheduling"
      },
      "typeVersion": 1
    },
    {
      "id": "c6742a8a-2139-4f96-ad05-698fed60d2ec",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -704,
        3360
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 736,
        "content": "## Data Collection\nFetch data from 3 sheets and merge into a single dataset for processing."
      },
      "typeVersion": 1
    },
    {
      "id": "11cc0d1a-8304-4b0e-a76a-f2e37c8197e3",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        3664
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 336,
        "content": "## Processing & Logic\nFilter valid rows, calculate resolved/pending counts, and determine severity and trend."
      },
      "typeVersion": 1
    },
    {
      "id": "fbac8f95-15d2-4783-b136-a326ff1fb707",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        368,
        3488
      ],
      "parameters": {
        "color": 7,
        "width": 1216,
        "height": 544,
        "content": "## Notifications & Storage\nGenerate AI summary,sends Slack alert if pending issues are high, and emails the report, and store results in Google Sheets."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "8530b1b5-6e29-4267-99a9-ecf72b376d64",
  "connections": {
    "Merge All Sources": {
      "main": [
        [
          {
            "node": "Filter Valid Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Email Body": {
      "main": [
        [
          {
            "node": "Send EOD Summary Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Email Generator1": {
      "main": [
        [
          {
            "node": "Check High Pending Condition",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Valid Records": {
      "main": [
        [
          {
            "node": "Calculate Resolved vs Pending",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily 6 PM Scheduler1": {
      "main": [
        [
          {
            "node": "Fetch Trade Breaks Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Failed Trades Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Exceptions Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Exceptions Data": {
      "main": [
        [
          {
            "node": "Merge All Sources",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Send EOD Summary Email": {
      "main": [
        [
          {
            "node": "Store Summary in Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Trade Breaks Data": {
      "main": [
        [
          {
            "node": "Merge Trades and Breaks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Trades and Breaks": {
      "main": [
        [
          {
            "node": "Merge All Sources",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compute Severity & Trend": {
      "main": [
        [
          {
            "node": "AI Email Generator1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Failed Trades Data": {
      "main": [
        [
          {
            "node": "Merge Trades and Breaks",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Check High Pending Condition": {
      "main": [
        [
          {
            "node": "Send Slack Alert (High Priority)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract Email Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Resolved vs Pending": {
      "main": [
        [
          {
            "node": "Compute Severity & Trend",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Slack Alert (High Priority)": {
      "main": [
        [
          {
            "node": "Extract Email Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}