{
 "name": "RecipeAgents: Draft a reply to a quote request with Claude",
 "nodes": [
  {
   "parameters": {
    "pollTimes": {
     "item": [
      {
       "mode": "everyMinute"
      }
     ]
    },
    "simple": false,
    "filters": {
     "q": "in:inbox -category:promotions (quote OR quotation OR estimate OR pricing OR \"how much\")",
     "readStatus": "unread"
    },
    "options": {}
   },
   "id": "47352211-8da1-5df2-aebf-8853efdef698",
   "name": "Gmail Trigger",
   "type": "n8n-nodes-base.gmailTrigger",
   "typeVersion": 1.2,
   "position": [
    240,
    300
   ]
  },
  {
   "parameters": {
    "operation": "read",
    "documentId": {
     "__rl": true,
     "value": "",
     "mode": "list"
    },
    "sheetName": {
     "__rl": true,
     "value": "",
     "mode": "list"
    },
    "options": {}
   },
   "id": "4f4d8630-616a-5c81-8eb2-2930af1c7cd8",
   "name": "Get price list",
   "type": "n8n-nodes-base.googleSheets",
   "typeVersion": 4.5,
   "position": [
    500,
    300
   ],
   "alwaysOutputData": true
  },
  {
   "parameters": {
    "jsCode": "// Turns the sheet rows into one clean price list. Columns needed: item, unit_price. Optional: unit.\nconst num = v => {\n  let s = String(v ?? '').trim().replace(/[^\\d.,-]/g, '');\n  if (!s) return NaN;\n  s = /,\\d{1,2}$/.test(s) && !s.includes('.') ? s.replace(',', '.') : s.replace(/,/g, '');\n  return Number(s);\n};\nconst rows = [];\nconst seen = new Set();\nfor (const it of $input.all()) {\n  const j = it.json;\n  const item = String(j.item ?? '').trim();\n  const price = num(j.unit_price);\n  if (!item || !Number.isFinite(price) || price < 0) continue;\n  const key = item.toLowerCase().replace(/\\s+/g, ' ');\n  if (seen.has(key)) throw new Error('Two rows have the same item name: ' + item + '. Make each name unique.');\n  seen.add(key);\n  rows.push({ item, unit_price: price, unit: String(j.unit ?? '').trim() });\n}\nif (rows.length === 0) throw new Error('The price list is empty, or the sheet has no item and unit_price columns in row 1.');\nif (rows.length > 300) throw new Error('The list has ' + rows.length + ' items. It is sent to Claude with every email, so keep it to 300 or fewer.');\nreturn [{ json: { rows, names_text: rows.map(r => r.item).join('\\n') } }];"
   },
   "id": "8a7004e3-470b-56eb-8069-567edf509925",
   "name": "Collect price list",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    760,
    300
   ]
  },
  {
   "parameters": {
    "resource": "text",
    "operation": "message",
    "modelId": {
     "__rl": true,
     "value": "claude-haiku-5-5",
     "mode": "id"
    },
    "messages": {
     "values": [
      {
       "content": "=You read one customer email for a business that sells the items in the price list below. Decide whether it asks for a price or quote, and extract what is asked. Return JSON only, with these keys:\nis_quote_request: true or false. False for complaints, invoices, newsletters, thank-you notes, and anything that does not ask for a price.\nlines: a list of objects with request (the customer's own words for the item), quantity (a number, or null if the email does not say), and list_item. For list_item copy EXACTLY one name from the price list when it is clearly the same product. Use null if there is no clear match. Never invent a name, and never pick a similar but different product.\nquestions: a list of short questions you would need answered to price this properly and the email does not say (size, colour, delivery address, date). Empty list if none.\nDo not write any prices, totals or discounts. Do not reply to the customer.\n\nPrice list (one item name per line):\n{{ $json.names_text }}\n\nFrom: {{ $('Gmail Trigger').first().json.from.text }}\nSubject: {{ $('Gmail Trigger').first().json.subject }}\nEmail:\n{{ ($('Gmail Trigger').first().json.text || '').slice(0, 10000) }}",
       "role": "user"
      }
     ]
    },
    "simplify": true,
    "options": {
     "includeMergedResponse": true,
     "maxTokens": 2000
    }
   },
   "id": "0306f118-68af-5585-9d72-d6ad749d7f41",
   "name": "Claude: read the request",
   "type": "@n8n/n8n-nodes-langchain.anthropic",
   "typeVersion": 1,
   "position": [
    1020,
    300
   ]
  },
  {
   "parameters": {
    "jsCode": "// Prices every line from the sheet (never from Claude), then writes the reply text.\nconst CURRENCY = 'EUR';                         // shown after each amount\nconst VALID_DAYS = 14;                          // how long the quote stays valid\nconst NOTE = 'Prices exclude VAT.';             // delete if you don't need it\nconst SIGN_OFF = 'Best regards,\\nYOUR NAME\\nYOUR BUSINESS';\n\nconst mail = $('Gmail Trigger').first().json;\nconst list = $('Collect price list').first().json.rows;\nconst raw = $input.first().json.merged_response ?? '';\nlet d;\ntry { d = JSON.parse(String(raw).replace(/^```(?:json)?\\s*|\\s*```$/g, '').trim()); }\ncatch (e) { throw new Error('Could not read the JSON from Claude: ' + String(raw).slice(0, 200)); }\nif (!d.is_quote_request) return [];             // not a quote request: no draft, the email stays unread\n\nconst norm = s => String(s || '').toLowerCase().replace(/\\s+/g, ' ').trim();\nconst byName = new Map(list.map(r => [norm(r.item), r]));\nconst money = n => n.toFixed(2);\nconst questions = (d.questions || []).map(String);\nconst lines = [];\nlet total = 0, unpriced = 0;\nfor (const l of d.lines || []) {\n  const row = l.list_item ? byName.get(norm(l.list_item)) : null;   // only a name that is really in the sheet counts\n  const qty = Number(l.quantity);\n  const per = row && row.unit ? ' per ' + row.unit : '';\n  if (!row) { lines.push('- ' + (String(l.request || '').trim() || 'one item') + ': we are checking this one and will confirm the price.'); unpriced++; continue; }\n  if (!(qty > 0)) { lines.push('- ' + row.item + ': ' + money(row.unit_price) + ' ' + CURRENCY + per); questions.push('How many ' + row.item + ' do you need?'); unpriced++; continue; }\n  const sum = Math.round(qty * row.unit_price * 100) / 100;\n  total += sum;\n  lines.push('- ' + qty + ' x ' + row.item + ' at ' + money(row.unit_price) + per + ' = ' + money(sum) + ' ' + CURRENCY);\n}\n\nconst from = (mail.from && mail.from.value && mail.from.value[0]) || {};\nconst address = from.address || '';\nconst flags = [];\nif (!address || /no-?reply|do-?not-?reply/i.test(address)) flags.push('the sender looks like a no-reply or form address: put the customer\\'s real address in To');\nif (lines.length === 0) flags.push('no items were found in the email text (attachments are not read)');\nif (unpriced) flags.push(unpriced + ' line(s) have no price yet');\n\nconst first = String(from.name || '').split(' ')[0];\nconst out = [];\nif (flags.length) out.push('[CHECK BEFORE SENDING, then delete this line: ' + flags.join('; ') + ']', '');\nout.push('Hi' + (first ? ' ' + first : '') + ',', '');\nif (lines.length) {\n  out.push('Thank you for your request. Here is our quote:', '', ...lines, '');\n  out.push((unpriced ? 'Total for the priced items: ' : 'Total: ') + money(total) + ' ' + CURRENCY);\n  out.push([NOTE, 'This quote is valid until ' + $now.plus({ days: VALID_DAYS }).toFormat('d LLLL yyyy') + '.'].filter(Boolean).join(' '), '');\n} else {\n  out.push('Thank you for your request. To prepare a quote, could you tell us which items you need and how many of each?', '');\n}\nif (questions.length) out.push('To confirm the price, could you tell us:', ...questions.map(q => '- ' + q), '');\nout.push(SIGN_OFF);\n\nreturn [{ json: { to: /no-?reply|do-?not-?reply/i.test(address) ? '' : address, subject: mail.subject || '', reply: out.join('\\n'), thread_id: mail.threadId, message_id: mail.id, total, flagged: flags.length > 0 } }];"
   },
   "id": "cca768d0-86c0-56e0-af88-98e7dcfefc6f",
   "name": "Price and write reply",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    1280,
    300
   ]
  },
  {
   "parameters": {
    "resource": "draft",
    "subject": "=Re: {{ $json.subject }}",
    "emailType": "text",
    "message": "={{ $json.reply }}",
    "options": {
     "sendTo": "={{ $json.to }}",
     "threadId": "={{ $json.thread_id }}"
    }
   },
   "id": "b4eaeaa6-d2bb-53d2-b4e7-44d05724032e",
   "name": "Save Gmail draft",
   "type": "n8n-nodes-base.gmail",
   "typeVersion": 2.1,
   "position": [
    1540,
    300
   ]
  },
  {
   "parameters": {
    "resource": "message",
    "operation": "markAsRead",
    "messageId": "={{ $('Price and write reply').first().json.message_id }}"
   },
   "id": "7e4b747c-c719-5211-b9f2-d3bc6d45e339",
   "name": "Mark email as read",
   "type": "n8n-nodes-base.gmail",
   "typeVersion": 2.1,
   "position": [
    1800,
    300
   ]
  },
  {
   "parameters": {
    "content": "## Draft a reply to a quote request with Claude\nFrom recipeagents.usestarbase.com/recipes/quote-request-reply-claude\n\n1. Connect credentials on each node (Gmail on the trigger and both Gmail nodes (the draft needs the gmail.compose scope), Google Sheets, Anthropic).\n2. Pick your sheet/folder/channel and model.\n3. Run once with test data and check the output before activating.\nKeep a human check on anything customer-facing.",
    "height": 260,
    "width": 420
   },
   "id": "042afe00-f06d-5b2f-9114-74fbf47ddf4d",
   "name": "Read me",
   "type": "n8n-nodes-base.stickyNote",
   "typeVersion": 1,
   "position": [
    200,
    20
   ]
  }
 ],
 "connections": {
  "Gmail Trigger": {
   "main": [
    [
     {
      "node": "Get price list",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Get price list": {
   "main": [
    [
     {
      "node": "Collect price list",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Collect price list": {
   "main": [
    [
     {
      "node": "Claude: read the request",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Claude: read the request": {
   "main": [
    [
     {
      "node": "Price and write reply",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Price and write reply": {
   "main": [
    [
     {
      "node": "Save Gmail draft",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Save Gmail draft": {
   "main": [
    [
     {
      "node": "Mark email as read",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "pinData": {},
 "active": false,
 "settings": {
  "executionOrder": "v1"
 },
 "meta": {
  "templateCredsSetupCompleted": false
 },
 "tags": []
}