{
  "name": "Monday pipeline forecast email",
  "nodes": [
    {
      "parameters": {
        "content": "## Monday pipeline forecast email\n\nPortfolio demo only. This workflow is an original example for demonstration. It is not client work and it does not represent a deployment for any customer.\n\nRun **Run demo** to execute the offline rules engine. The live branch is used only when the incoming item sets `demo` to false and the placeholder credentials have been replaced.",
        "height": 220,
        "width": 520,
        "color": 4
      },
      "id": "ba1ecd8c-4cde-4a79-a6c0-025f560f89ba",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -40
      ]
    },
    {
      "parameters": {},
      "id": "09dbeebb-de69-4df0-852b-aa4e89f6e9de",
      "name": "Run demo",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        40,
        280
      ],
      "notes": "CLI and the n8n editor start here. An empty manual run loads the bundled sample.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "monday-pipeline-forecast",
        "authentication": "none",
        "responseMode": "lastNode",
        "responseData": "firstEntryJson",
        "options": {}
      },
      "id": "dac70230-b405-4ef8-bf1c-8546a92cb8b4",
      "name": "Inbound webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        40,
        460
      ],
      "notes": "POST JSON to this path. Include demo:false only after credentials are connected.",
      "notesInFlow": true,
      "webhookId": "06e98a4a-f601-4f88-9ead-9b9d5be1e839"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 8,
              "triggerAtMinute": 15
            }
          ]
        }
      },
      "id": "ca519cbc-95cf-4b70-a741-287d203da501",
      "name": "Weekday schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        40,
        640
      ],
      "notes": "Monday 08:15. The manual trigger and webhook remain available for tests.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const sample = {\n  \"demo\": true,\n  \"period\": \"2026-W48\",\n  \"rows\": [\n    {\n      \"commit\": 12000,\n      \"bestCase\": 20000,\n      \"pipeline\": 48000\n    }\n  ],\n  \"previous\": {\n    \"commit\": 10000,\n    \"bestCase\": 18000,\n    \"pipeline\": 51000\n  }\n};\nconst incoming = $input.first()?.json ?? {};\nconst provided = Object.keys(incoming).filter((key) => incoming[key] !== undefined && incoming[key] !== null && incoming[key] !== '');\nconst base = provided.length ? { ...sample, ...incoming } : { ...sample };\nconst flag = incoming.demo;\nbase.demo = !(flag === false || flag === 'false' || flag === 0 || flag === '0');\nreturn [{ json: base }];\n"
      },
      "id": "f8388abe-7a1a-4df7-bd56-46de5c20b650",
      "name": "Normalize input",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        340,
        360
      ],
      "notes": "Merges the request over the bundled sample. demo stays true unless the caller explicitly turns it off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nconst produced = (() => {\n\nconst rows = Array.isArray(item.rows) ? item.rows : [item];\nconst keys = ['commit', 'bestCase', 'pipeline'];\nconst totals = {};\nfor (const key of keys) totals[key] = 0;\nfor (const row of rows) {\n  for (const key of keys) totals[key] += Number(row[key] || 0);\n}\nconst previous = item.previous || {};\nconst deltas = {};\nfor (const key of keys) {\n  const before = Number(previous[key] || 0);\n  deltas[key] = before === 0 ? null : Math.round(((totals[key] - before) / before) * 1000) / 10;\n}\nconst lines = keys.map((key) => key + ': ' + totals[key] + (deltas[key] === null ? '' : ' (' + (deltas[key] > 0 ? '+' : '') + deltas[key] + '%)'));\nconst record = { report: 'Monday forecast', period: item.period || 'last-7-days', totals, deltas, narrative: lines.join('\\n') };\nreturn {\n  summary: 'Monday forecast' + ' for ' + record.period + '. ' + lines[0] + '.',\n  route: 'send',\n  record,\n  slackText: 'Monday forecast' + '\\n' + lines.join('\\n'),\n  actions: [{ app: 'Slack', operation: 'post', payload: record }],\n};\n\n})();\nif (!produced || typeof produced.summary !== 'string' || !produced.summary.trim()) {\n  throw new Error('Apply rules must return a summary string');\n}\nreturn [{\n  json: {\n    ...item,\n    ...produced,\n    demo: item.demo !== false,\n  },\n}];\n"
      },
      "id": "110e170c-d126-41be-993a-76d13f798de1",
      "name": "Apply rules",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        620,
        360
      ],
      "notes": "Deterministic stand-in for the model or enrichment API. Replace or precede this with a live model node when you turn demo mode off.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "3633d74f-2180-42cd-9f20-2c33d55564c1",
              "leftValue": "={{ $json.demo }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "495f3453-e7d3-4aa0-b801-1045c6e8c1e8",
      "name": "Demo mode?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        360
      ],
      "notes": "True: package the offline result. False: run the credentialed apps.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nreturn [{\n  json: {\n    demo: true,\n    status: 'demo_ready',\n    workflow: 'monday-pipeline-forecast',\n    summary: item.summary,\n    route: item.route ?? null,\n    record: item.record ?? {},\n    actions: item.actions ?? [],\n    slackText: item.slackText ?? item.summary,\n    notes: 'Demo mode did not call external apps. Send {\"demo\": false} after placeholder credentials are replaced.',\n  },\n}];\n"
      },
      "id": "dacef87c-982a-475e-bf5b-81c099f03104",
      "name": "Package demo result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1180,
        180
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $json.record.email || $json.email || 'lead@example.com' }}",
        "subject": "={{ $json.record.subject || $json.summary }}",
        "message": "={{ $json.record.body || $json.record.message || $json.summary }}",
        "emailType": "text",
        "messageId": "={{ $json.record.messageId || 'MESSAGE_ID' }}",
        "labelIds": [
          "Label_1"
        ]
      },
      "id": "f3b2a9a4-2991-48cc-8a15-5048c41a358a",
      "name": "Send Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1180,
        760
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "PLACEHOLDER_GMAILOAUTH2",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "deal",
        "operation": "create",
        "stage": "appointmentscheduled",
        "additionalFields": {
          "dealName": "={{ $json.record.dealName || $json.record.company || $json.summary }}",
          "amount": "={{ $json.record.amount || $json.record.budget || 0 }}"
        }
      },
      "id": "f5824269-8417-493a-bbba-2e5d9f74cc67",
      "name": "Create HubSpot deal",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        1460,
        760
      ],
      "credentials": {
        "hubspotOAuth2Api": {
          "id": "PLACEHOLDER_HUBSPOTOAUTH2API",
          "name": "HubSpot account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Live path\n\nReplace every `PLACEHOLDER_*` credential, then POST the sample with `\"demo\": false`.\n\nThe nodes on this branch use the `record` and `actions` fields produced by Apply rules.",
        "height": 180,
        "width": 420,
        "color": 6
      },
      "id": "5039dca1-182d-43b9-b79e-bfba58bf0da2",
      "name": "Live path",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1120,
        520
      ]
    }
  ],
  "connections": {
    "Run demo": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inbound webhook": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekday schedule": {
      "main": [
        [
          {
            "node": "Normalize input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize input": {
      "main": [
        [
          {
            "node": "Apply rules",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apply rules": {
      "main": [
        [
          {
            "node": "Demo mode?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Demo mode?": {
      "main": [
        [
          {
            "node": "Package demo result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Gmail": {
      "main": [
        [
          {
            "node": "Create HubSpot deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Open pipeline, commit, and best-case are rolled into the Monday forecast email."
  },
  "active": false
}
