{
  "name": "Draft CPQ quotes from Slack with TurboQuote and OpenAI",
  "nodes": [
    {
      "id": "53fcdc6a-b8f3-40f8-9c9d-0df820916dbc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -608,
        -48
      ],
      "parameters": {
        "width": 480,
        "height": 896,
        "content": "## Slack AI \u2192 TurboQuote (CPQ) and E-Signature\n\n### How it works\n\nThis workflow turns a Slack quote request into a TurboQuote draft using AI-assisted product selection and catalog pricing. It loads pricing data, asks an AI agent to structure line items, validates that there is something to quote, then looks up the customer and creates a draft quote with line items. It posts either a review link back to Slack or a Slack notification when no quoteable items or customer match is found.\n\n### Setup steps\n\n- Connect Slack credentials for the trigger and posting nodes, and configure the quote-request channel or event the workflow should listen to.\n- Connect TurboDocx/TurboQuote credentials for catalog lookup, customer/company search, contact retrieval, quote creation, and line-item creation.\n- Connect OpenAI credentials for the AI Agent chat model, and ensure the structured output parser schema matches the expected quote line-item format.\n- Review the \"Set quote defaults\" node values such as appBaseUrl, currency, termDays, and validDays.\n- Verify that TurboQuote catalog products, customer companies, primary contacts, and quote templates or draft quote settings are available and named consistently with expected Slack requests.\n\n### Customization\n\nAdjust the AI prompt/schema to capture different product attributes, change the default quote terms and validity period, or customize the Slack messages for review links and exception paths."
      },
      "typeVersion": 1
    },
    {
      "id": "0556f4b6-8409-4c05-8bad-f1fea3e5fa8e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        384
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 336,
        "content": "## Receive quote request\n\nStarts the workflow from a Slack quote request and initializes default quote settings such as base URL, currency, payment term, and validity period."
      },
      "typeVersion": 1
    },
    {
      "id": "96c53271-23ce-42d7-995c-a4893774a8cb",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        400
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 320,
        "content": "## Load pricing catalog\n\nRetrieves the TurboQuote product catalog and aggregates it into a usable pricing dataset for downstream AI and pricing steps."
      },
      "typeVersion": 1
    },
    {
      "id": "d6f6a6d7-da17-4d78-aaa2-cc78192fbdbb",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        384
      ],
      "parameters": {
        "color": 7,
        "width": 432,
        "height": 688,
        "content": "## Draft quote with AI\n\nUses an OpenAI-powered agent, catalog search tool, and structured line-item schema to interpret the Slack request and produce a draft list of quote line items."
      },
      "typeVersion": 1
    },
    {
      "id": "6d561359-418b-409b-9a44-3505fa563b29",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1312,
        384
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 336,
        "content": "## Validate priced items\n\nMatches AI-selected products back to the real catalog to attach list prices, then branches based on whether any valid quoteable items remain."
      },
      "typeVersion": 1
    },
    {
      "id": "1bff744a-3e15-4c2c-bd04-5fa5de69de5b",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1760,
        448
      ],
      "parameters": {
        "color": 7,
        "width": 240,
        "height": 368,
        "content": "## Handle empty quote\n\nPosts a Slack notification when the AI and catalog matching steps do not produce anything that can be quoted."
      },
      "typeVersion": 1
    },
    {
      "id": "461fa4f3-77d4-4258-84f9-8bc6916fff2a",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2032,
        304
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 416,
        "content": "## Find customer record\n\nSearches for the customer company in TurboQuote and branches depending on whether a matching company is found, including the nearby Slack error response for missing customers."
      },
      "typeVersion": 1
    },
    {
      "id": "e9b61259-d22f-4a12-97ce-e52394ca4784",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2208,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 320,
        "content": "## Create draft quote\n\nRetrieves the company\u2019s primary contact and creates the initial draft quote record in TurboQuote."
      },
      "typeVersion": 1
    },
    {
      "id": "d02979fa-1f57-42ae-b421-546aadd7ed1b",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2704,
        240
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 304,
        "content": "## Post quote review\n\nAdds the selected line items to the draft quote, limits the result to a single Slack post, and sends the quote review link back to Slack."
      },
      "typeVersion": 1
    },
    {
      "id": "63040aa4-e470-4198-8297-cf90643024dc",
      "name": "When Quote Request Received",
      "type": "n8n-nodes-base.slackTrigger",
      "position": [
        0,
        560
      ],
      "parameters": {
        "options": {},
        "trigger": [
          "app_mention"
        ],
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": ""
        }
      },
      "typeVersion": 1
    },
    {
      "id": "055a696c-2c07-4800-afaa-2943c045279e",
      "name": "Set Default Quote Parameters",
      "type": "n8n-nodes-base.set",
      "position": [
        224,
        560
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "appBaseUrl",
              "type": "string",
              "value": "https://app.turbodocx.com"
            },
            {
              "id": "a2",
              "name": "currency",
              "type": "string",
              "value": "USD"
            },
            {
              "id": "a3",
              "name": "termDays",
              "type": "number",
              "value": 30
            },
            {
              "id": "a4",
              "name": "validDays",
              "type": "number",
              "value": 14
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d9a9b305-8fa8-44f2-884c-4eef07b6ccf8",
      "name": "Fetch Catalog for Pricing",
      "type": "@turbodocx/n8n-nodes-turbodocx.turboDocx",
      "position": [
        448,
        560
      ],
      "parameters": {
        "filters": {},
        "resource": "product",
        "returnAll": true
      },
      "typeVersion": 1
    },
    {
      "id": "f987b4dd-ef74-4d28-af4c-db30b0f50890",
      "name": "Aggregate Catalog Data",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        672,
        560
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "catalog"
      },
      "typeVersion": 1
    },
    {
      "id": "28f08f87-45ad-4b04-851b-4d96076205b5",
      "name": "Draft Quote Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        960,
        560
      ],
      "parameters": {
        "text": "=A sales rep wrote this in Slack:\n\"\"\"\n{{ $('When Quote Request Received').item.json.text }}\n\"\"\"\n\nWork out (1) the customer / company name and (2) each product they want with its quantity.\nFor EACH distinct product, call the \"Search TurboQuote catalog\" tool with a SHORT root keyword: singular, no adjectives or quantities (search \"server\", not \"2 new servers\"; \"monitor\", not \"large monitors\"). If a search returns nothing, try a shorter or alternate keyword before giving up. Take the productId from the tool result. Only use productIds the tool returned; if a product truly isn't in the catalog, leave it out. Never output prices.",
        "options": {
          "systemMessage": "You are a sales quoting assistant. You map a plain-English product request to catalog SKUs by searching the catalog once per product with a short singular keyword. You never invent products, IDs, or prices \u2014 only use what the catalog search tool returns."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "f4176b5a-0b1a-4808-8f7f-eb225ebcafa4",
      "name": "OpenAI GPT-4o Mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        872,
        784
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "400aeacf-7623-4808-a918-848f634c1352",
      "name": "Search TurboQuote Catalog",
      "type": "@turbodocx/n8n-nodes-turbodocx.turboDocxTool",
      "position": [
        1024,
        928
      ],
      "parameters": {
        "limit": 20,
        "filters": {
          "query": "={{ $fromAI('search', 'A product name or SKU to search the catalog for', 'string') }}"
        },
        "resource": "product"
      },
      "typeVersion": 1
    },
    {
      "id": "f78c8ae5-c54d-4840-ab3b-8eb1108836d6",
      "name": "Parse Line Items Schema",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1176,
        784
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"customerName\": {\n      \"type\": \"string\",\n      \"description\": \"The customer / company name to quote\"\n    },\n    \"items\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"productId\": {\n            \"type\": \"string\",\n            \"description\": \"productId from the catalog search tool\"\n          },\n          \"quantity\": {\n            \"type\": \"number\"\n          }\n        },\n        \"required\": [\n          \"productId\",\n          \"quantity\"\n        ]\n      }\n    }\n  },\n  \"required\": [\n    \"customerName\",\n    \"items\"\n  ]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "850e4295-e412-46f2-9729-f99674e67917",
      "name": "Attach Catalog Prices",
      "type": "n8n-nodes-base.code",
      "position": [
        1360,
        560
      ],
      "parameters": {
        "jsCode": "// Join the AI's chosen products to the catalog to attach real list prices.\n// The model only returns productId + quantity; prices are authoritative here.\nconst catalog = $('Aggregate Catalog Data').first().json.catalog || [];\nconst byId = new Map(catalog.map(p => [p.id, p]));\n\nconst ai = $json.output || $json;            // agent output parser nests under `output`\nconst wanted = Array.isArray(ai.items) ? ai.items : [];\n\nconst items = [];\nconst unmatched = [];   // productId the AI returned that isn't in the catalog\nconst unpriced = [];    // matched but no usable price -> never post a $0 line silently\nfor (const w of wanted) {\n  const p = byId.get(w.productId);\n  if (!p) { unmatched.push(w.productId); continue; }\n  // listPrice is a MySQL decimal -> comes back as a STRING (e.g. \"1000.00\")\n  const price = Number(p.listPrice);\n  if (!Number.isFinite(price) || price <= 0) { unpriced.push(p.name || p.id); continue; }\n  const qty = Number(w.quantity) > 0 ? Number(w.quantity) : 1;\n  items.push({\n    productId: p.id,\n    productName: p.name,\n    productSku: p.sku,\n    unitPrice: price,\n    billingFrequency: p.billingFrequency || 'one-time',\n    quantity: qty,\n  });\n}\n\nconst total = items.reduce((s, i) => s + i.unitPrice * i.quantity, 0);\n\n// pretty money for Slack, e.g. \"$80,250.00\" \u2014 falls back if the currency code is odd\nconst currency = ($('Set Default Quote Parameters').first().json.currency) || 'USD';\nlet totalFormatted;\ntry { totalFormatted = total.toLocaleString('en-US', { style: 'currency', currency }); }\ncatch (e) { totalFormatted = currency + ' ' + total.toFixed(2); }\n\nreturn [{ json: {\n  customerName: (ai.customerName || '').trim(),\n  items,\n  unmatched,\n  unpriced,\n  itemCount: items.length,\n  total,\n  totalFormatted,\n} }];"
      },
      "typeVersion": 2
    },
    {
      "id": "eeb19f9e-1d34-4157-a64b-b894a0bd0c15",
      "name": "Check Items to Quote",
      "type": "n8n-nodes-base.if",
      "position": [
        1584,
        560
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "g1",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.itemCount }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8e819263-b645-451a-ab71-b3434959ac82",
      "name": "Locate Customer Company",
      "type": "@turbodocx/n8n-nodes-turbodocx.turboDocx",
      "position": [
        2080,
        464
      ],
      "parameters": {
        "limit": 1,
        "filters": {
          "query": "={{ $('Attach Catalog Prices').item.json.customerName }}"
        },
        "resource": "company"
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "ef1751bf-dcc6-4f3f-af93-b5a078dc1f4c",
      "name": "Verify Company Found",
      "type": "n8n-nodes-base.if",
      "position": [
        2304,
        464
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c1",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "4046cead-1f4c-4aae-982c-e270b67f7bfe",
      "name": "Fetch Primary Contact",
      "type": "@turbodocx/n8n-nodes-turbodocx.turboDocx",
      "position": [
        2256,
        112
      ],
      "parameters": {
        "limit": 1,
        "resource": "company",
        "companyId": "={{ $('Locate Customer Company').item.json.id }}",
        "operation": "listContacts",
        "contactFilters": {}
      },
      "typeVersion": 1
    },
    {
      "id": "50936d44-87a8-48ba-a8f3-3e8adc22b41b",
      "name": "Generate Draft Quote",
      "type": "@turbodocx/n8n-nodes-turbodocx.turboDocx",
      "maxTries": 3,
      "position": [
        2480,
        112
      ],
      "parameters": {
        "name": "=Quote for {{ $('Attach Catalog Prices').item.json.customerName }} \u2014 {{ $now.toFormat('yyyy-LL-dd') }}",
        "resource": "quote",
        "companyId": "={{ $('Locate Customer Company').item.json.id }}",
        "contactId": "={{ $('Fetch Primary Contact').item.json.id }}",
        "additionalFields": {
          "currency": "={{ $('Set Default Quote Parameters').item.json.currency }}",
          "termDays": "={{ $('Set Default Quote Parameters').item.json.termDays }}",
          "validUntil": "={{ $now.plus({ days: $('Set Default Quote Parameters').item.json.validDays }).toISO() }}"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1
    },
    {
      "id": "f4972a7c-c50f-4a39-a425-8c00247c3238",
      "name": "Insert Line Items",
      "type": "@turbodocx/n8n-nodes-turbodocx.turboDocx",
      "maxTries": 3,
      "position": [
        2752,
        368
      ],
      "parameters": {
        "items": "={{ JSON.stringify($('Attach Catalog Prices').item.json.items) }}",
        "quoteId": "={{ $('Generate Draft Quote').item.json.id }}",
        "resource": "quoteLineItem",
        "operation": "add"
      },
      "retryOnFail": true,
      "typeVersion": 1
    },
    {
      "id": "657346af-6248-43fc-bcc6-549833ca3adb",
      "name": "Limit to One Post",
      "type": "n8n-nodes-base.limit",
      "position": [
        2976,
        368
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "2f46f129-6715-4bd0-8986-7e935676ba2d",
      "name": "Send Review Link to Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        3200,
        368
      ],
      "parameters": {
        "text": "=:memo: *Draft quote ready for review*\n*{{ $('Attach Catalog Prices').item.json.customerName }}* \u2014 {{ $('Attach Catalog Prices').item.json.itemCount }} line item(s), {{ $('Attach Catalog Prices').item.json.totalFormatted }}\nQuote *#{{ $('Generate Draft Quote').item.json.quoteNumber }}* \u2014 <{{ $('Set Default Quote Parameters').item.json.appBaseUrl }}/turboquote/{{ $('Generate Draft Quote').item.json.id }}/configure|Open to review>\n{{ ($('Attach Catalog Prices').item.json.unmatched || []).length ? ':warning: Not in catalog: ' + $('Attach Catalog Prices').item.json.unmatched.join(', ') + '\\n' : '' }}{{ ($('Attach Catalog Prices').item.json.unpriced || []).length ? ':warning: No price set: ' + $('Attach Catalog Prices').item.json.unpriced.join(', ') : '' }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('When Quote Request Received').item.json.channel }}"
        },
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "dca13308-5d3c-4ab6-8341-8cd6a90a75d7",
      "name": "Notify Customer Not Found",
      "type": "n8n-nodes-base.slack",
      "position": [
        2528,
        560
      ],
      "parameters": {
        "text": "=:mag: I couldn\u2019t find a customer matching *{{ $('Attach Catalog Prices').item.json.customerName }}* in TurboQuote.\nCreate the company (with a contact) first, then ask again.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('When Quote Request Received').item.json.channel }}"
        },
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "51e0b932-875c-47eb-9973-02e5848d68ee",
      "name": "Notify Nothing to Quote in Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        1808,
        656
      ],
      "parameters": {
        "text": "=:information_source: I couldn\u2019t build any priced line items for *{{ $('Attach Catalog Prices').item.json.customerName }}*.\n{{ ($('Attach Catalog Prices').item.json.unmatched || []).length ? 'Not in catalog: ' + $('Attach Catalog Prices').item.json.unmatched.join(', ') + '\\n' : '' }}{{ ($('Attach Catalog Prices').item.json.unpriced || []).length ? 'No price set: ' + $('Attach Catalog Prices').item.json.unpriced.join(', ') : '' }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('When Quote Request Received').item.json.channel }}"
        },
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "typeVersion": 2.3
    }
  ],
  "connections": {
    "Draft Quote Agent": {
      "main": [
        [
          {
            "node": "Attach Catalog Prices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Line Items": {
      "main": [
        [
          {
            "node": "Limit to One Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit to One Post": {
      "main": [
        [
          {
            "node": "Send Review Link to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4o Mini": {
      "ai_languageModel": [
        [
          {
            "node": "Draft Quote Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check Items to Quote": {
      "main": [
        [
          {
            "node": "Locate Customer Company",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Notify Nothing to Quote in Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Draft Quote": {
      "main": [
        [
          {
            "node": "Insert Line Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify Company Found": {
      "main": [
        [
          {
            "node": "Fetch Primary Contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Notify Customer Not Found",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Attach Catalog Prices": {
      "main": [
        [
          {
            "node": "Check Items to Quote",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Primary Contact": {
      "main": [
        [
          {
            "node": "Generate Draft Quote",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Catalog Data": {
      "main": [
        [
          {
            "node": "Draft Quote Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Locate Customer Company": {
      "main": [
        [
          {
            "node": "Verify Company Found",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Line Items Schema": {
      "ai_outputParser": [
        [
          {
            "node": "Draft Quote Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Catalog for Pricing": {
      "main": [
        [
          {
            "node": "Aggregate Catalog Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search TurboQuote Catalog": {
      "ai_tool": [
        [
          {
            "node": "Draft Quote Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When Quote Request Received": {
      "main": [
        [
          {
            "node": "Set Default Quote Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Default Quote Parameters": {
      "main": [
        [
          {
            "node": "Fetch Catalog for Pricing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "instanceId": null
  },
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  }
}