{
  "name": "Slack Deal Room Concierge",
  "nodes": [
    {
      "id": "fc729c80-9913-44e6-962a-459ac25d97d8",
      "name": "Poll: Deals Entering Negotiation",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.4,
      "position": [0, 80],
      "parameters": { "rule": { "interval": [{ "field": "cronExpression", "expression": "0 * * * *" }] } }
    },
    {
      "id": "f34e10f7-11c8-4d8e-8509-bb6832c485e1",
      "name": "Fetch Opportunities in Negotiation",
      "type": "n8n-nodes-base.salesforce",
      "typeVersion": 1.1,
      "position": [224, 80],
      "parameters": {
        "resource": "search",
        "query": "SELECT Id, Name, Amount, CloseDate, StageName, NextStep, IsClosed, IsWon, Account.Name, Account.Industry FROM Opportunity WHERE StageName = 'Negotiation/Review' AND IsClosed = false AND Account.Name IN ('Northwind Freight Co','Halberd Insurance Partners')"
      },
      "credentials": { "salesforceOAuth2Api": { "id": "553Tae1kPe5Wpthq", "name": "Salesforce account" } }
    },
    {
      "id": "f7fb296f-16f8-4913-9ade-0b735d88584d",
      "name": "Get Deal Room Registry",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [448, 80],
      "executeOnce": true,
      "alwaysOutputData": true,
      "parameters": {
        "operation": "get",
        "dataTableId": { "__rl": true, "mode": "id", "value": "rGsNWQy72pfWX6GV", "cachedResultName": "Deal Room Registry" },
        "returnAll": true
      }
    },
    {
      "id": "2e2ee874-b8a0-452c-bfad-0d71084bcea2",
      "name": "Find New Deals",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [672, 80],
      "parameters": {
        "jsCode": "const candidates = $('Fetch Opportunities in Negotiation').all().map(i => i.json);\nconst registryRows = $input.all().map(i => i.json);\nconst registeredIds = new Set(registryRows.map(r => r.opportunityId));\nconst newDeals = candidates.filter(c => !registeredIds.has(c.Id));\nreturn newDeals.map(c => ({ json: c }));"
      }
    },
    {
      "id": "ce19d552-dbfd-411b-8cf2-061102efc36d",
      "name": "Loop New Deals",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [896, 80],
      "parameters": { "options": {} }
    },
    {
      "id": "46689abc-aee4-45fc-8871-204cdb261ccb",
      "name": "Build Room Name",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1120, 0],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const opp = $json;\nconst acctName = (opp.Account && opp.Account.Name) || 'account';\nconst slug = acctName.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, '');\nconst idSuffix = (opp.Id || '').slice(-6).toLowerCase();\nconst channelName = ('deal-' + slug + '-' + idSuffix).slice(0, 80);\nreturn { json: { ...opp, channelName } };"
      }
    },
    {
      "id": "edc2a29e-36e7-4ef8-8222-4f43923b6bb5",
      "name": "List Workspace Users",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [1344, 0],
      "parameters": { "resource": "user", "operation": "getAll", "returnAll": true },
      "credentials": { "slackApi": { "id": "mv7TIi8kucFPqPg6", "name": "Slack account" } }
    },
    {
      "id": "54c3186a-2b98-4a66-99ae-d303a81912e2",
      "name": "Pick Human User",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1568, 0],
      "parameters": {
        "jsCode": "const users = $input.all().map(i => i.json);\nconst human = users.find(u => !u.is_bot && !u.deleted && u.id !== 'USLACKBOT' && u.name !== 'slackbot');\nif (!human) { throw new Error('No human user found in workspace'); }\nreturn [{ json: { id: human.id, name: human.name, real_name: human.real_name } }];"
      }
    },
    {
      "id": "ea0a22fe-8276-4f57-862c-48103f346a04",
      "name": "Create Deal Room Channel",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [1792, 0],
      "parameters": { "resource": "channel", "channelId": "={{ $('Build Room Name').item.json.channelName }}" },
      "credentials": { "slackApi": { "id": "mv7TIi8kucFPqPg6", "name": "Slack account" } }
    },
    {
      "id": "37dc27a7-6f0c-4112-8169-4355a0e6e54d",
      "name": "Invite Concierge to Room",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [2016, 0],
      "parameters": {
        "resource": "channel",
        "operation": "invite",
        "channelId": { "__rl": true, "mode": "id", "value": "={{ $('Create Deal Room Channel').item.json.id }}" },
        "userIds": ["={{ $('Pick Human User').item.json.id }}"]
      },
      "credentials": { "slackApi": { "id": "mv7TIi8kucFPqPg6", "name": "Slack account" } }
    },
    {
      "id": "f41b1033-1afa-45ee-a12b-55638961da11",
      "name": "Post Deal Context to Room",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [2240, 0],
      "parameters": {
        "select": "channel",
        "channelId": { "__rl": true, "mode": "id", "value": "={{ $('Create Deal Room Channel').item.json.id }}" },
        "text": "=🏠 *Deal room open: {{ $('Build Room Name').item.json.Name }}*\n*Account:* {{ $('Build Room Name').item.json.Account.Name }}\n*Stage:* {{ $('Build Room Name').item.json.StageName }}\n*Amount:* ${{ $('Build Room Name').item.json.Amount }}\n*Target close:* {{ $('Build Room Name').item.json.CloseDate }}\n*Next step:* {{ $('Build Room Name').item.json.NextStep }}\n\nThis room auto-archives with a summary when the deal closes. In a full deployment it would also invite the deal's AE, SE, and manager automatically from Salesforce Owner/role data — for this demo, only the workflow owner is invited for real.",
        "otherOptions": {}
      },
      "credentials": { "slackApi": { "id": "mv7TIi8kucFPqPg6", "name": "Slack account" } }
    },
    {
      "id": "be2f11da-1ecc-4ec0-8bd4-a6b9f058d589",
      "name": "Log Deal Room",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [2464, 80],
      "parameters": {
        "dataTableId": { "__rl": true, "mode": "id", "value": "rGsNWQy72pfWX6GV", "cachedResultName": "Deal Room Registry" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "opportunityId": "={{ $('Build Room Name').item.json.Id }}",
            "opportunityName": "={{ $('Build Room Name').item.json.Name }}",
            "accountName": "={{ $('Build Room Name').item.json.Account.Name }}",
            "amount": "={{ $('Build Room Name').item.json.Amount }}",
            "closeDate": "={{ $('Build Room Name').item.json.CloseDate }}",
            "channelId": "={{ $('Create Deal Room Channel').item.json.id }}",
            "channelName": "={{ $('Build Room Name').item.json.channelName }}",
            "status": "open",
            "roomCreatedAt": "={{ $now.toISO() }}"
          }
        },
        "options": {}
      }
    },
    {
      "id": "9a7fff46-e270-461d-9138-4f141a417cec",
      "name": "Poll: Detect Closed Deals",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.4,
      "position": [0, 656],
      "parameters": { "rule": { "interval": [{ "field": "cronExpression", "expression": "30 * * * *" }] } }
    },
    {
      "id": "1fc84c6e-279d-41ee-b579-51edb5aaa451",
      "name": "Get Open Deal Rooms",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [224, 656],
      "parameters": {
        "operation": "get",
        "dataTableId": { "__rl": true, "mode": "id", "value": "rGsNWQy72pfWX6GV", "cachedResultName": "Deal Room Registry" },
        "filters": { "conditions": [{ "keyName": "status", "keyValue": "open" }] },
        "returnAll": true
      }
    },
    {
      "id": "311faa65-5c75-480d-846b-7009e6115293",
      "name": "Loop Open Rooms",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [448, 656],
      "parameters": { "options": {} }
    },
    {
      "id": "aa325c1c-76ea-47ba-b081-999450114340",
      "name": "Check Opportunity Status",
      "type": "n8n-nodes-base.salesforce",
      "typeVersion": 1.1,
      "position": [672, 400],
      "parameters": { "resource": "opportunity", "operation": "get", "opportunityId": "={{ $json.opportunityId }}" },
      "credentials": { "salesforceOAuth2Api": { "id": "553Tae1kPe5Wpthq", "name": "Salesforce account" } }
    },
    {
      "id": "c0cf7f8c-a3ce-4f75-a77e-72235f382919",
      "name": "Is Deal Closed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [896, 400],
      "parameters": {
        "conditions": {
          "combinator": "and",
          "conditions": [{ "leftValue": "={{ $json.IsClosed }}", "operator": { "operation": "true", "type": "boolean" }, "rightValue": "" }],
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 1 }
        },
        "looseTypeValidation": true,
        "options": {}
      }
    },
    {
      "id": "cb65d287-42e6-4634-a05b-5fae5adb5769",
      "name": "Fetch Room Activity",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [1120, 400],
      "parameters": {
        "resource": "channel",
        "operation": "history",
        "channelId": { "__rl": true, "mode": "id", "value": "={{ $('Get Open Deal Rooms').item.json.channelId }}" },
        "returnAll": true,
        "filters": {}
      },
      "credentials": { "slackApi": { "id": "mv7TIi8kucFPqPg6", "name": "Slack account" } }
    },
    {
      "id": "3df973fa-ac87-4269-a1ca-4089f56dda16",
      "name": "Format Room Activity",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1344, 400],
      "parameters": {
        "jsCode": "const messages = $input.all().map(i => i.json);\nconst sorted = messages.slice().sort((a, b) => Number(a.ts) - Number(b.ts));\nconst lines = sorted.map(m => '- ' + (m.text || '(non-text event)'));\nconst activityText = lines.length ? lines.join('\\n') : '(no messages were posted in this deal room before it closed)';\nreturn [{ json: { activityText, messageCount: sorted.length } }];"
      }
    },
    {
      "id": "47297d3c-e088-476e-8f16-f26b3cd3a655",
      "name": "Deal Room Summarizer",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [1568, 400],
      "parameters": {
        "promptType": "define",
        "text": "=Deal: {{ $('Get Open Deal Rooms').item.json.opportunityName }} ({{ $('Get Open Deal Rooms').item.json.accountName }})\nAmount: ${{ $('Get Open Deal Rooms').item.json.amount }}\nFinal Salesforce stage: {{ $('Check Opportunity Status').item.json.StageName }}\nWon: {{ $('Check Opportunity Status').item.json.IsWon }}\n\nHere is the real message activity from this deal's dedicated Slack room, oldest first:\n{{ $('Format Room Activity').item.json.activityText }}\n\nWrite a plain-English recap of how this deal room played out and what the outcome was. Ground it in the actual activity given (or note plainly if the room saw little to no discussion) rather than inventing detail.",
        "hasOutputParser": true,
        "options": { "systemMessage": "You are a GTM operations assistant for Fortavault, Inc., a fictional data protection and security platform. You are given a real, closed Salesforce opportunity and the real Slack message history from its dedicated deal room, and asked to recap what happened before the room is archived. Respond with a JSON object with exactly two fields: headline (one sentence) and summary (3-4 sentences)." }
      }
    },
    {
      "id": "193e5f3e-c932-4428-8640-026c4420f8a2",
      "name": "Anthropic Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1.5,
      "position": [1576, 632],
      "parameters": { "model": { "__rl": true, "mode": "list", "value": "claude-sonnet-4-6", "cachedResultName": "Claude Sonnet 4.6" }, "options": { "temperature": 0.4 } },
      "credentials": { "anthropicApi": { "id": "3d3ZiTi7BwnkFwqU", "name": "Anthropic account" } }
    },
    {
      "id": "b1e76646-d210-46a5-9ddf-eb0bed3070c0",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [1704, 632],
      "parameters": { "jsonSchemaExample": "{ \"headline\": \"one-sentence headline about how the deal room played out\", \"summary\": \"3-4 sentence plain-English recap of the deal room activity and the outcome, grounded in the actual channel messages given\" }" }
    },
    {
      "id": "d5a1b529-d494-485a-8a46-ac3fcd5b95ab",
      "name": "Archive Deal Room",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [1920, 400],
      "parameters": { "resource": "channel", "operation": "archive", "channelId": { "__rl": true, "mode": "id", "value": "={{ $('Get Open Deal Rooms').item.json.channelId }}" } },
      "credentials": { "slackApi": { "id": "mv7TIi8kucFPqPg6", "name": "Slack account" } }
    },
    {
      "id": "d7f8ce71-bc65-48bb-912b-440f9ceab87f",
      "name": "Post Close Summary to Main Channel",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.7,
      "position": [2144, 400],
      "parameters": {
        "select": "channel",
        "channelId": { "__rl": true, "mode": "id", "value": "C0BQ3G96HL6" },
        "text": "=🗄️ *Deal room archived: {{ $('Get Open Deal Rooms').item.json.opportunityName }}* ({{ $('Get Open Deal Rooms').item.json.accountName }})\nOutcome: *{{ $('Check Opportunity Status').item.json.StageName }}* — ${{ $('Get Open Deal Rooms').item.json.amount }}\n\n*{{ $('Deal Room Summarizer').item.json.output.headline }}*\n{{ $('Deal Room Summarizer').item.json.output.summary }}",
        "otherOptions": {}
      },
      "credentials": { "slackApi": { "id": "mv7TIi8kucFPqPg6", "name": "Slack account" } }
    },
    {
      "id": "edef9e43-7f50-44bc-b02c-a097921e5d7e",
      "name": "Update Deal Room Registry",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [2368, 528],
      "parameters": {
        "operation": "update",
        "dataTableId": { "__rl": true, "mode": "id", "value": "rGsNWQy72pfWX6GV", "cachedResultName": "Deal Room Registry" },
        "matchType": "allConditions",
        "filters": { "conditions": [{ "keyName": "opportunityId", "keyValue": "={{ $('Get Open Deal Rooms').item.json.opportunityId }}" }] },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "status": "archived",
            "roomArchivedAt": "={{ $now.toISO() }}",
            "outcome": "={{ $('Check Opportunity Status').item.json.StageName }}",
            "summary": "={{ $('Deal Room Summarizer').item.json.output.summary }}"
          }
        },
        "options": {}
      }
    }
  ],
  "connections": {
    "Poll: Deals Entering Negotiation": { "main": [[{ "node": "Fetch Opportunities in Negotiation", "type": "main", "index": 0 }]] },
    "Fetch Opportunities in Negotiation": { "main": [[{ "node": "Get Deal Room Registry", "type": "main", "index": 0 }]] },
    "Get Deal Room Registry": { "main": [[{ "node": "Find New Deals", "type": "main", "index": 0 }]] },
    "Find New Deals": { "main": [[{ "node": "Loop New Deals", "type": "main", "index": 0 }]] },
    "Loop New Deals": { "main": [[], [{ "node": "Build Room Name", "type": "main", "index": 0 }]] },
    "Build Room Name": { "main": [[{ "node": "List Workspace Users", "type": "main", "index": 0 }]] },
    "List Workspace Users": { "main": [[{ "node": "Pick Human User", "type": "main", "index": 0 }]] },
    "Pick Human User": { "main": [[{ "node": "Create Deal Room Channel", "type": "main", "index": 0 }]] },
    "Create Deal Room Channel": { "main": [[{ "node": "Invite Concierge to Room", "type": "main", "index": 0 }]] },
    "Invite Concierge to Room": { "main": [[{ "node": "Post Deal Context to Room", "type": "main", "index": 0 }]] },
    "Post Deal Context to Room": { "main": [[{ "node": "Log Deal Room", "type": "main", "index": 0 }]] },
    "Log Deal Room": { "main": [[{ "node": "Loop New Deals", "type": "main", "index": 0 }]] },
    "Poll: Detect Closed Deals": { "main": [[{ "node": "Get Open Deal Rooms", "type": "main", "index": 0 }]] },
    "Get Open Deal Rooms": { "main": [[{ "node": "Loop Open Rooms", "type": "main", "index": 0 }]] },
    "Loop Open Rooms": { "main": [[], [{ "node": "Check Opportunity Status", "type": "main", "index": 0 }]] },
    "Check Opportunity Status": { "main": [[{ "node": "Is Deal Closed?", "type": "main", "index": 0 }]] },
    "Is Deal Closed?": { "main": [[{ "node": "Fetch Room Activity", "type": "main", "index": 0 }], [{ "node": "Loop Open Rooms", "type": "main", "index": 0 }]] },
    "Fetch Room Activity": { "main": [[{ "node": "Format Room Activity", "type": "main", "index": 0 }]] },
    "Format Room Activity": { "main": [[{ "node": "Deal Room Summarizer", "type": "main", "index": 0 }]] },
    "Deal Room Summarizer": { "main": [[{ "node": "Archive Deal Room", "type": "main", "index": 0 }]] },
    "Anthropic Chat Model": { "ai_languageModel": [[{ "node": "Deal Room Summarizer", "type": "ai_languageModel", "index": 0 }]] },
    "Structured Output Parser": { "ai_outputParser": [[{ "node": "Deal Room Summarizer", "type": "ai_outputParser", "index": 0 }]] },
    "Archive Deal Room": { "main": [[{ "node": "Post Close Summary to Main Channel", "type": "main", "index": 0 }]] },
    "Post Close Summary to Main Channel": { "main": [[{ "node": "Update Deal Room Registry", "type": "main", "index": 0 }]] },
    "Update Deal Room Registry": { "main": [[{ "node": "Loop Open Rooms", "type": "main", "index": 0 }]] }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
