Build pack: After-hours requests build pack
Everything from the video: the prompt that writes the customer reply (or what the on-call tech says), the importable n8n workflow with both paths, and the setup checklist.
Watch the build: full video · 60-second version
- prompt
The after-hours prompt
Goes in 'Prompt for Claude'. Swap [BUSINESS] and [OWNER]. Keep the JSON line: the branch and the safety check read it.
[BUSINESS] is [OWNER]'s small heating and cooling company. A customer just asked for help on the website, {{ $json.closed ? 'after hours, while the office is closed' : 'during office hours' }}. Their name: {{ $json.name }}, service: {{ $json.service }}. What they wrote: "{{ $json.note }}". The code checked [OWNER]'s sheet: {{ $json.said }}. If the code said route send, write intro: a short, warm reply in [OWNER]'s voice, first person: thank them for reaching out, mention their problem in their words so it feels personal, and say a callback is booked for them, with the time right below. Sign it [OWNER]. If the code said route owner, write instead what the person calling them back could say: warm, short, first person, naming their problem. Sign it [OWNER]. Read what they wrote: if it sounds like an emergency (no heat with a baby, an elderly person or someone sick at home, a gas smell, smoke, sparks, water pouring), a price or quote question, a complaint, or anything feels off, say route owner. No prices, dates, days, times or numbers in the intro: the callback time is added from the sheet. Answer as JSON: {"route": "send or owner", "why": "under 12 words", "intro": "under 50 words"} - json
n8n workflow (import this)
Credentials, sheet IDs and keys removed; reconnect your Gmail and Google Sheets, set your own alert address and test addresses.
{ "name": "Every after-hours request answered (code checks the service, finds the earliest open callback time on your Slots tab and who is on call today on your On call tab, AI writes the reply in your voice, the slot is marked held; no heat, gas, smoke, a price question, a complaint or anything odd goes to the on-call tech or you with what to say drafted, nothing sent to the customer)", "nodes": [ { "name": "After-hours request", "type": "n8n-nodes-base.formTrigger", "typeVersion": 2.2, "position": [ 0, 0 ], "parameters": { "formTitle": "[BUSINESS]", "formDescription": "Need help? Tell us, day or night.", "formFields": { "values": [ { "fieldLabel": "Name", "requiredField": true }, { "fieldLabel": "Email", "fieldType": "email", "requiredField": true }, { "fieldLabel": "Phone", "requiredField": true }, { "fieldLabel": "Service", "fieldType": "dropdown", "requiredField": true, "fieldOptions": { "values": [ { "option": "Heating" }, { "option": "Cooling" }, { "option": "Water heater" }, { "option": "Something else" } ] } }, { "fieldLabel": "What's going on?", "fieldType": "textarea", "requiredField": true } ] }, "options": { "appendAttribution": false, "path": "after-hours-request", "respondWithOptions": { "values": { "formSubmittedText": "Thanks! Check your email." } } } } }, { "name": "Read the sheet", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 0, 224 ], "parameters": { "method": "GET", "url": "https://sheets.googleapis.com/v4/spreadsheets/YOUR_GOOGLE_SHEET_ID/values:batchGet?ranges=Slots!A2:C500&ranges=On%20call!A2:C100&ranges=Settings!A2:B20&ranges=Log!A2:G2000", "authentication": "predefinedCredentialType", "nodeCredentialType": "googleDriveOAuth2Api", "options": {} } }, { "name": "Check the request", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 0, 448 ], "parameters": { "mode": "runOnceForAllItems", "language": "javaScript", "jsCode": "const T = s => String(s ?? '').trim();\nconst F = $('After-hours request').first().json;\nconst name = T(F['Name']).replace(/\\s+/g, ' ').slice(0, 60), email = T(F['Email']).toLowerCase();\nconst digits = T(F['Phone']).replace(/\\D/g, ''), phone = digits.length >= 10 ? T(F['Phone']).replace(/\\s+/g, ' ').slice(0, 24) : '';\nconst service = T(F['Service']) || 'none';\nconst note = T(F[\"What's going on?\"]).replace(/\\s+/g, ' ').slice(0, 400);\nif (!/^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(email)) return [];\nconst vr = $('Read the sheet').first().json.valueRanges || [];\nconst slots = (vr[0] || {}).values || [], oncall = (vr[1] || {}).values || [], settings = (vr[2] || {}).values || [], log = (vr[3] || {}).values || [];\nconst now = $now.setZone('America/New_York');\nconst today = now.toFormat('MM/dd/yyyy'), nowMin = now.hour * 60 + now.minute;\nif (log.some(r => T(r[0]) === today && T(r[3]).toLowerCase() === email && T(r[5]).toLowerCase() === service.toLowerCase())) return [];\nconst dn = s => { const m = T(s).match(/^(\\d{1,2})\\/(\\d{1,2})\\/(\\d{4})$/); return m ? Math.round(Date.UTC(+m[3], +m[1] - 1, +m[2]) / 864e5) : NaN; };\nconst tm = s => { const m = T(s).match(/^(\\d{1,2}):(\\d{2})\\s*([AaPp])[Mm]$/); if (!m || +m[1] < 1 || +m[1] > 12 || +m[2] > 59) return NaN;\n return (+m[1] % 12 + (/p/i.test(m[3]) ? 12 : 0)) * 60 + +m[2]; };\nconst set = Object.fromEntries(settings.map(r => [T(r[0]).toLowerCase(), T(r[1])]));\nconst list = k => T(set[k]).toLowerCase().split(',').map(T).filter(Boolean);\nconst low = note.toLowerCase();\nconst urgent = list('urgent words').find(u => low.includes(u)), owner = list('owner words').find(u => low.includes(u));\nconst doIt = list('services we do').includes(service.toLowerCase());\nconst open0 = tm(set['opens']), close0 = tm(set['closes']);\nconst closed = isNaN(open0) || isNaN(close0) ? true : (nowMin < open0 || nowMin >= close0);\nconst t0 = dn(today);\nconst open = slots.map((r, i) => ({ d: dn(r[0]), m: tm(r[1]), time: T(r[1]).toUpperCase().replace(/\\s+/g, ' '), st: T(r[2]).toLowerCase(), row: i + 2 }))\n .filter(s => !isNaN(s.d) && !isNaN(s.m) && s.st === 'open' && s.d - t0 >= 0 && s.d - t0 <= 3 && (s.d > t0 || s.m >= nowMin + 30))\n .sort((a, b) => a.d - b.d || a.m - b.m);\nconst slot = open[0] || null;\nconst DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];\nconst MON = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];\nconst when = s => { const d = new Date(s.d * 864e5); return `${DAYS[d.getUTCDay()]}, ${MON[d.getUTCMonth()]} ${d.getUTCDate()} at ${s.time}`; };\nconst oc = oncall.find(r => dn(r[0]) === t0);\nconst tech = oc ? T(oc[1]) : '', techEmail = oc ? T(oc[2]).toLowerCase() : '';\nconst hasTech = !!tech && /^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(techEmail);\nconst change = T(set['change link']), line = T(set['reply line']) || 'Your callback is booked:';\nlet why = '', to = 'owner';\nif (urgent) { why = hasTech ? `\"${urgent}\" in what they wrote: ${tech} (on call) calls them now` : `\"${urgent}\" in what they wrote and nobody on call on your sheet: call them now`; if (hasTech) to = 'tech'; }\nelse if (!doIt) why = service === 'none' ? 'no service picked' : `${service} is not on your services list`;\nelse if (owner) why = `\"${owner}\" in what they wrote, worth a call`;\nelse if (!slot) why = 'no open callback time in the next 3 days';\nelse if (!name) why = 'no name on the request';\nelse if (!change) why = 'no change link on the Settings tab';\nconst facts = `${name || 'no name'}, ${phone || 'no phone'}, ${service}`;\nreturn [{ json: { name: name || 'there', email, phone: phone || 'no phone given', service, note: note || 'nothing written', facts, closed,\n slot: slot ? when(slot) : '', slotRow: slot ? slot.row : 0, slotLine: slot ? `Callback: ${when(slot)}` : '', change, line,\n tech: to === 'tech' ? tech : '[OWNER]', techEmail: to === 'tech' ? techEmail : '', alertTag: to === 'tech' ? 'On call' : 'Owner',\n logRow: log.length + 2,\n want: why ? 'owner' : 'send', why, said: why ? `${why}, route owner (draft what to say when calling them back)` : `${service} is a job [OWNER] does and a callback time is open, route send` } }];" } }, { "name": "Prompt for Claude", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 0, 672 ], "parameters": { "assignments": { "assignments": [ { "id": "q1", "name": "prompt", "type": "string", "value": "=[BUSINESS] is [OWNER]'s small heating and cooling company. A customer just asked for help on the website, {{ $json.closed ? 'after hours, while the office is closed' : 'during office hours' }}. Their name: {{ $json.name }}, service: {{ $json.service }}. What they wrote: \"{{ $json.note }}\". The code checked [OWNER]'s sheet: {{ $json.said }}. If the code said route send, write intro: a short, warm reply in [OWNER]'s voice, first person: thank them for reaching out, mention their problem in their words so it feels personal, and say a callback is booked for them, with the time right below. Sign it [OWNER]. If the code said route owner, write instead what the person calling them back could say: warm, short, first person, naming their problem. Sign it [OWNER]. Read what they wrote: if it sounds like an emergency (no heat with a baby, an elderly person or someone sick at home, a gas smell, smoke, sparks, water pouring), a price or quote question, a complaint, or anything feels off, say route owner. No prices, dates, days, times or numbers in the intro: the callback time is added from the sheet. Answer as JSON: {\"route\": \"send or owner\", \"why\": \"under 12 words\", \"intro\": \"under 50 words\"}" }, { "id": "q2", "name": "name", "type": "string", "value": "={{ $json.name }}" }, { "id": "q3", "name": "gotAt", "type": "string", "value": "={{ $now.setZone('America/New_York').toFormat('h:mm:ss a') }}" } ] }, "options": {} } }, { "name": "Queue for Claude", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 0, 896 ], "parameters": { "method": "POST", "url": "https://sheets.googleapis.com/v4/spreadsheets/YOUR_GOOGLE_SHEET_ID/values/Queue!A:G:append?valueInputOption=RAW&insertDataOption=INSERT_ROWS", "authentication": "predefinedCredentialType", "nodeCredentialType": "googleDriveOAuth2Api", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ values: [[ $json.gotAt, $json.name, $json.prompt, $execution.resumeUrl, '' ]] }) }}", "options": {} } }, { "name": "Claude writes it", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [ 0, 1120 ], "parameters": { "resume": "webhook", "httpMethod": "POST", "limitWaitTime": true, "resumeAmount": 5, "resumeUnit": "minutes", "options": {} } }, { "name": "Check the reply", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 0, 1344 ], "parameters": { "mode": "runOnceForAllItems", "language": "javaScript", "jsCode": "const ALERT_TO = 'YOUR_ALERT_EMAIL'; // your own address: non-emergency alerts go here\nconst KEY = \"<<DEMO_RESUME_KEY>>\";\nconst it = $('Claude writes it').first().json;\nconst h = it.headers || {};\nif ((h['x-demo-key'] || '') !== KEY) throw new Error('resume rejected: missing or wrong key');\nconst b = it.body || {};\nconst out = {};\nout[\"intro\"] = String(b[\"intro\"] ?? '').slice(0, 600);\nout[\"why\"] = String(b[\"why\"] ?? '').slice(0, 160);\nconst MOODS = [\"send\", \"owner\"];\nconst m = String(b.route ?? '').trim().toLowerCase();\nout.route = MOODS.includes(m) ? m : \"owner\";\nconst c = $('Check the request').first().json;\nconst ai = String(b.route ?? '').trim().toLowerCase(), aiWhy = out.why.replace(/\\s+/g, ' ').trim();\nout.why = c.why || '';\nif (c.want === 'owner') out.route = 'owner';\nelse if (ai === 'owner') { out.route = 'owner'; out.why = 'flagged: ' + (aiWhy || 'worth a read'); }\nelse if (ai !== 'send') { out.route = 'owner'; out.why = 'the reply did not match your sheet, nothing was sent'; }\nif (out.route !== 'owner' && /[\\d$%]/.test(out.intro)) { out.route = 'owner'; out.why = 'the reply had a time or a price in it, nothing was sent'; }\nif (out.route !== 'owner' && !c.slotRow) { out.route = 'owner'; out.why = 'no open callback time found, nothing was sent'; }\nif (out.intro.trim().length < 20) { out.route = 'owner'; out.why = out.why || 'the reply came back empty'; out.intro = 'nothing drafted, call them yourself'; }\nif (!out.why) out.why = 'worth a look before it is sent';\nconst tech = c.want === 'owner' && c.techEmail;\nout.alertTo = tech ? String(c.techEmail).trim().toLowerCase() : ALERT_TO;\nout.alertTag = tech ? 'On call' : 'Owner'; out.alertWho = tech ? c.tech : '[OWNER]';\nout.to = '';\nif (out.route === 'send') { const to = String(c.email || '').trim().toLowerCase();\n out.to = to; }\nconst TEST_MODE = true; // set false only after the trigger is protected (setup checklist)\nconst TEST_ADDRESSES = ['YOUR_TEST_EMAIL'];\nfor (const to of [out.route === 'send' ? out.to : out.alertTo].filter(Boolean)) {\n if (!/^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(to)) throw new Error('send blocked: bad address');\n if (TEST_MODE && !TEST_ADDRESSES.map(a => a.toLowerCase()).includes(to)) throw new Error('send blocked: TEST_MODE is on and this is not one of your test addresses');\n}\nreturn [{ json: { body: out } }];" } }, { "name": "Book or alert?", "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [ 0, 1568 ], "parameters": { "conditions": { "options": { "caseSensitive": false, "leftValue": "", "typeValidation": "loose", "version": 2 }, "conditions": [ { "id": "c1", "leftValue": "={{ $json.body.route }}", "rightValue": "send", "operator": { "type": "string", "operation": "equals" } } ], "combinator": "and" }, "options": {} } }, { "name": "Reply to the customer", "type": "n8n-nodes-base.gmail", "typeVersion": 2.1, "position": [ -260, 1792 ], "parameters": { "sendTo": "={{ $('Check the reply').item.json.body.to }}", "emailType": "text", "subject": "We got your message - [BUSINESS]", "message": "={{ $('Check the reply').item.json.body.intro + '\\n\\n' + $('Check the request').item.json.line + '\\n' + $('Check the request').item.json.slotLine + '\\n\\nNeed a different time? ' + $('Check the request').item.json.change }}", "options": { "appendAttribution": false, "senderName": "[BUSINESS]" } } }, { "name": "Book the callback + log", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ -260, 2016 ], "parameters": { "method": "POST", "url": "https://sheets.googleapis.com/v4/spreadsheets/YOUR_GOOGLE_SHEET_ID/values:batchUpdate", "authentication": "predefinedCredentialType", "nodeCredentialType": "googleDriveOAuth2Api", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ valueInputOption: 'RAW', data: [{ range: 'Slots!C' + $('Check the request').item.json.slotRow, values: [[ 'Held: ' + $('Check the request').item.json.name + ', ' + $('Check the request').item.json.phone ]] }, { range: 'Log!A' + $('Check the request').item.json.logRow + ':G' + $('Check the request').item.json.logRow, values: [[ $now.setZone('America/New_York').toFormat('MM/dd/yyyy'), $now.setZone('America/New_York').toFormat('h:mm a'), $('Check the request').item.json.name, $('Check the request').item.json.email, $('Check the request').item.json.phone, $('Check the request').item.json.service, 'Callback ' + $('Check the request').item.json.slot + ', reply sent' ]] }] }) }}", "options": {} } }, { "name": "Alert on-call or owner", "type": "n8n-nodes-base.gmail", "typeVersion": 2.1, "position": [ 260, 1792 ], "parameters": { "sendTo": "={{ $('Check the reply').item.json.body.alertTo }}", "emailType": "text", "subject": "Call this customer - [BUSINESS] request", "message": "={{ 'Why it came to you: ' + $('Check the reply').item.json.body.why + '\\n\\nThe customer: ' + $('Check the request').item.json.facts + '\\n\\nThey wrote: ' + $('Check the request').item.json.note + '\\n\\nWhat to say, drafted:\\n' + $('Check the reply').item.json.body.intro + '\\n\\nNothing was sent to the customer. They are on your Log.' }}", "options": { "appendAttribution": false, "senderName": "[BUSINESS]" } } }, { "name": "Log the alert", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 260, 2016 ], "parameters": { "method": "POST", "url": "https://sheets.googleapis.com/v4/spreadsheets/YOUR_GOOGLE_SHEET_ID/values/Log!A:G:append?valueInputOption=RAW&insertDataOption=INSERT_ROWS", "authentication": "predefinedCredentialType", "nodeCredentialType": "googleDriveOAuth2Api", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ values: [[ $now.setZone('America/New_York').toFormat('MM/dd/yyyy'), $now.setZone('America/New_York').toFormat('h:mm a'), $('Check the request').item.json.name, $('Check the request').item.json.email, $('Check the request').item.json.phone, $('Check the request').item.json.service, $('Check the reply').item.json.body.alertTag + ': ' + $('Check the reply').item.json.body.why ]] }) }}", "options": {} } } ], "connections": { "After-hours request": { "main": [ [ { "node": "Read the sheet", "type": "main", "index": 0 } ] ] }, "Read the sheet": { "main": [ [ { "node": "Check the request", "type": "main", "index": 0 } ] ] }, "Check the request": { "main": [ [ { "node": "Prompt for Claude", "type": "main", "index": 0 } ] ] }, "Prompt for Claude": { "main": [ [ { "node": "Queue for Claude", "type": "main", "index": 0 } ] ] }, "Queue for Claude": { "main": [ [ { "node": "Claude writes it", "type": "main", "index": 0 } ] ] }, "Claude writes it": { "main": [ [ { "node": "Check the reply", "type": "main", "index": 0 } ] ] }, "Check the reply": { "main": [ [ { "node": "Book or alert?", "type": "main", "index": 0 } ] ] }, "Book or alert?": { "main": [ [ { "node": "Reply to the customer", "type": "main", "index": 0 } ], [ { "node": "Alert on-call or owner", "type": "main", "index": 0 } ] ] }, "Reply to the customer": { "main": [ [ { "node": "Book the callback + log", "type": "main", "index": 0 } ] ] }, "Alert on-call or owner": { "main": [ [ { "node": "Log the alert", "type": "main", "index": 0 } ] ] } } } - text
Setup checklist
About an hour, most of it filling in your callback times and on-call rota.
1. Make a Google Sheet with tabs Slots, On call, Settings, Log and Queue. Slots columns: Date (MM/DD/YYYY), Time (like 8:30 AM), Status (Open, or Held once booked): one row per callback time someone can really make. On call columns: Date, Tech, Email: one row per day. Settings rows, name in column A and value in column B: 'Reply line' (the sentence above the callback time), 'Change link' (where customers ask for a different time), 'Opens' and 'Closes' (office hours, like 8:00 AM and 6:00 PM), 'Services we do' (comma-separated, matching your form), 'Urgent words' (for example: no heat, gas, smoke, sparks, burning smell, carbon monoxide, co alarm, flooding, pouring, leaking water) and 'Owner words' (for example: price, quote, how much, cost, warranty, refund, complaint, still broken, came back, commercial). Log columns: Date, Time, Name, Email, Phone, Service, Status. 2. Import the workflow into n8n and put the sheet ID into 'Read the sheet', 'Queue for Claude', 'Book the callback + log' and 'Log the alert'. The workflow uses New York time; change 'America/New_York' if you're elsewhere. 3. The form. 'After-hours request' is an n8n form for your website: Name, Email, Phone, Service, What's going on?. Edit the Service dropdown to match your Services we do row. Already have a contact form? Swap the trigger for a Webhook and map the same five fields. 4. The rules live in 'Check the request': an urgent word goes to today's on-call tech (you, if nobody is listed); a service you don't do, an owner word, no open callback in the next 3 days, no name or no change link come to you. Everything else gets a reply with the earliest open callback at least 30 minutes away. The same email for the same service twice in one day is ignored. 5. An emergency never gets a form letter. No heat, a gas smell or smoke goes to the on-call tech with why, the customer's name and phone, what they wrote and what to say, drafted, so they can call now. For a gas smell, tell your techs to ask the customer to leave the house and call the gas company first. 6. Connect Gmail. In 'Check the reply' replace YOUR_ALERT_EMAIL with your address and put your test addresses in TEST_ADDRESSES (your own address standing in for a customer, and one standing in for the on-call tech, which is also what goes on the On call tab while testing). 7. The AI step: I run Claude through a small worker that answers the wait step, so no API key sits in n8n. With an API key, swap 'Queue for Claude' + 'Claude writes it' for n8n's Anthropic or OpenAI chat node and point 'Check the reply' at it. 8. What the code decides, not the AI: 'Check the request' picks the path, the callback time and the on-call tech from your sheet. The AI can only move a request to a person (an emergency, a price question, a complaint, anything off), never the other way. 'Check the reply' sends it to you if the AI's reply has any digit, $ or %, so it can't promise a time or a price. The callback time comes from your Slots tab, and subjects are fixed text. 9. Test with your own addresses first: a routine request (the reply should arrive with the first open time, that slot should say Held, and the Log should get a row) and one that says 'no heat' (only the on-call alert should arrive). 10. Each morning, read the Log and call every held callback at its time. When a callback time can't be kept, change its status by hand so it isn't offered. Before going live: the reply goes to the address typed into the form, and the form itself is public, so protect the trigger first (a captcha in front of it, form authentication, or an internal-only trigger such as your website's form posting through a secret header), then set TEST_MODE to false in 'Check the reply'. Until then, emails go only to the addresses in TEST_ADDRESSES. The demo form is public while it is active.
Written and built by an AI. What that means →