{
  "name": "DemoCare Clinic: Voicely SIP receptionist",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "voicely-democare-phone",
        "responseMode": "responseNode",
        "options": {
          "rawBody": true
        }
      },
      "id": "255be5b1-fc4c-55e3-be82-2a04e5c39b67",
      "name": "Voicely Phone Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        -400,
        0
      ],
      "webhookId": "721c044e-e3cf-59ca-89b3-dc4d5a86c3a0"
    },
    {
      "parameters": {
        "mode": "raw",
        "includeOtherFields": true,
        "options": {
          "stripBinary": false
        },
        "jsonOutput": "{\n  \"voicelyPolicy\": {\n    \"storage\": \"both\",\n    \"appointmentsTableId\": \"SELECT_CLINIC_APPOINTMENTS_TABLE_ID\",\n    \"patientsTableId\": \"SELECT_CLINIC_PATIENTS_TABLE_ID\",\n    \"requestsTableId\": \"SELECT_CLINIC_REQUESTS_TABLE_ID\",\n    \"callsTableId\": \"SELECT_CLINIC_CALLS_TABLE_ID\",\n    \"sheets\": {\n      \"documentId\": \"SELECT_GOOGLE_SPREADSHEET_ID\",\n      \"appointmentsSheet\": \"appointments\",\n      \"patientsSheet\": \"patients\",\n      \"requestsSheet\": \"requests\",\n      \"callsSheet\": \"calls\"\n    },\n    \"windowMs\": 300000,\n    \"bodyBytes\": 262144,\n    \"depth\": 32,\n    \"expectedAccountId\": \"SET_YOUR_VOICELY_ACCOUNT_ID\",\n    \"pinSalt\": \"SET_A_LONG_RANDOM_PIN_SALT\",\n    \"clinicName\": \"DemoCare Family Clinic\"\n  }\n}"
      },
      "id": "87df5aef-c95a-594f-87ed-79da868e29fa",
      "name": "DemoCare Policy",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -170,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "return await (async function prepareSignedRequest(){\n const items=$input.all();if(items.length!==1)throw Error('voicely_webhook_item_invalid');\n const item=items[0],policy=item.json.voicelyPolicy;\n for(const name of ['windowMs','bodyBytes','depth'])if(!Number.isSafeInteger(policy?.[name])||policy[name]<=0)throw Error('voicely_webhook_policy_required');\n const headers=item.json.headers,id=headers?.['x-voicely-event-id'],stamp=headers?.['x-voicely-timestamp'],signature=headers?.['x-voicely-signature'];\n if(typeof id!=='string'||!id||typeof stamp!=='string'||!/^\\d+$/.test(stamp)||!Number.isSafeInteger(Number(stamp))||typeof signature!=='string'||!/^v1=[a-f0-9]{64}$/.test(signature)||Math.abs(Date.now()-Number(stamp))>policy.windowMs)throw Error('voicely_webhook_unauthorized');\n const raw=await this.helpers.getBinaryDataBuffer(0,'data');if(!Buffer.isBuffer(raw)||raw.length>policy.bodyBytes)throw Error('voicely_webhook_body_refused');\n const prefix=Buffer.from(JSON.stringify([1,Number(stamp),id])+'\\n'),frame=Buffer.concat([prefix,raw]);\n return [{json:{voicelyPolicy:policy,voicelyId:id,voicelyStamp:stamp,voicelySignature:signature,voicelyRaw:raw.toString('base64')},binary:{voicelySigned:{data:frame.toString('base64'),mimeType:'application/octet-stream'}}}];\n}).call(this);"
      },
      "id": "a4b30688-ae17-587a-ae89-0fbbbe0a0c50",
      "name": "Prepare Voicely Signature",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        60,
        0
      ],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "jsCode": "// >>> PASTE your Voicely webhook signing secret (whsec_...) between the quotes. Kept only here, never in execution data. <<<\nconst SIGNING_SECRET='PASTE_YOUR_WHSEC_SIGNING_SECRET_HERE';\n// VERIFY VOICELY SIGNATURE (replaces the Crypto node). Voicely's key is the part of the endpoint secret after \"whsec_\",\n// base64url-decoded (see Voicely > API access > Webhooks > \"How to verify a webhook\"). Pure JavaScript HMAC-SHA256:\n// no credential, no built-in module, so it runs the same on self-hosted n8n and n8n Cloud.\nreturn await (async function verifyVoicely(){\n const items=$input.all();if(items.length!==1)throw Error('voicely_webhook_item_invalid');\n const item=items[0],secret=SIGNING_SECRET;\n if(typeof secret!=='string'||!/^whsec_[A-Za-z0-9_-]{43,}$/.test(secret))throw Error('voicely_signing_secret_not_configured');\n const fromB64url=s=>{const t=s.replace(/-/g,'+').replace(/_/g,'/');return Uint8Array.from(Buffer.from(t+'='.repeat((4-t.length%4)%4),'base64'));};\n const K=new Uint32Array([0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2]);\n const sha256=msg=>{const l=msg.length,n=((l+9+63)>>6)<<6,b=new Uint8Array(n);b.set(msg);b[l]=0x80;const bits=l*8;\n  for(let i=0;i<8;i++)b[n-1-i]=Math.floor(bits/2**(8*i))&255;\n  const H=new Uint32Array([0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19]),W=new Uint32Array(64);\n  const r=(x,s)=>(x>>>s)|(x<<(32-s));\n  for(let o=0;o<n;o+=64){for(let i=0;i<16;i++)W[i]=(b[o+4*i]<<24)|(b[o+4*i+1]<<16)|(b[o+4*i+2]<<8)|b[o+4*i+3];\n   for(let i=16;i<64;i++){const s0=r(W[i-15],7)^r(W[i-15],18)^(W[i-15]>>>3),s1=r(W[i-2],17)^r(W[i-2],19)^(W[i-2]>>>10);W[i]=(W[i-16]+s0+W[i-7]+s1)>>>0;}\n   let [a,bb,c,d,e,f,g,h]=H;\n   for(let i=0;i<64;i++){const S1=r(e,6)^r(e,11)^r(e,25),ch=(e&f)^(~e&g),t1=(h+S1+ch+K[i]+W[i])>>>0,S0=r(a,2)^r(a,13)^r(a,22),mj=(a&bb)^(a&c)^(bb&c),t2=(S0+mj)>>>0;\n    h=g;g=f;f=e;e=(d+t1)>>>0;d=c;c=bb;bb=a;a=(t1+t2)>>>0;}\n   H[0]+=a;H[1]+=bb;H[2]+=c;H[3]+=d;H[4]+=e;H[5]+=f;H[6]+=g;H[7]+=h;}\n  const out=new Uint8Array(32);for(let i=0;i<8;i++){out[4*i]=H[i]>>>24;out[4*i+1]=(H[i]>>>16)&255;out[4*i+2]=(H[i]>>>8)&255;out[4*i+3]=H[i]&255;}return out;};\n const hmac=(key,msg)=>{let k=key.length>64?sha256(key):key;const kp=new Uint8Array(64);kp.set(k);const ip=new Uint8Array(64+msg.length),op=new Uint8Array(96);\n  for(let i=0;i<64;i++){ip[i]=kp[i]^0x36;op[i]=kp[i]^0x5c;}ip.set(msg,64);op.set(sha256(ip),64);return sha256(op);};\n const frame=Uint8Array.from(Buffer.from(item.binary.voicelySigned.data,'base64'));\n const expectedSignature=Array.from(hmac(fromB64url(secret.slice(6)),frame),x=>x.toString(16).padStart(2,'0')).join('');\n const json={...item.json,expectedSignature};return [{json}];\n})();\n"
      },
      "id": "32650043-1090-5f71-9594-915c19928a50",
      "name": "Verify Voicely HMAC",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        290,
        0
      ],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "jsCode": "// Voicely webhook envelope (signed with this endpoint's secret): {id, type, created_at, account_id, api_version, data}.\nreturn await (function acceptEvent(){\n const items=$input.all();if(items.length!==1)throw Error('voicely_webhook_item_invalid');const j=items[0].json,p=j.voicelyPolicy;\n if(typeof j.expectedSignature!=='string'||!/^[a-f0-9]{64}$/.test(j.expectedSignature)||typeof j.voicelySignature!=='string'||!/^v1=[a-f0-9]{64}$/.test(j.voicelySignature))throw Error('voicely_webhook_unauthorized');\n let mismatch=0;for(let i=0;i<64;i++)mismatch|=j.expectedSignature.charCodeAt(i)^j.voicelySignature.charCodeAt(i+3);\n if(mismatch||Math.abs(Date.now()-Number(j.voicelyStamp))>p.windowMs)throw Error('voicely_webhook_unauthorized');\n const raw=Buffer.from(j.voicelyRaw,'base64');if(raw.length>p.bodyBytes)throw Error('voicely_webhook_body_refused');\n let body;try{body=JSON.parse(raw.toString('utf8'));}catch{throw Error('voicely_webhook_body_refused');}\n const types=['telephony.call.start','telephony.call.lookup','calling.call.completed','telephony.recording.ready','telephony.call.started','telephony.call.ended','telephony.call.failed','webhook.test'];\n if(!body||body.id!==j.voicelyId||!types.includes(body.type)||!body.data||typeof body.data!=='object'||Array.isArray(body.data))throw Error('voicely_webhook_contract_invalid');\n // Tenant binding: this workflow serves ONE Voicely business account. Any other account's event is refused, never processed.\n if(typeof p.expectedAccountId!=='string'||!p.expectedAccountId||p.expectedAccountId.startsWith('SET_'))throw Error('democare_account_not_configured');\n if(String(body.account_id)!==p.expectedAccountId)throw Error('voicely_webhook_account_refused');\n return [{json:{event:body}}];\n})();"
      },
      "id": "667f614b-c144-5d31-8660-9fd1d03597de",
      "name": "Accept Voicely Event",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        0
      ],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "jsCode": "return [{json:{httpStatus:401,reply:{error:'webhook_authentication_refused'}}}];"
      },
      "id": "160f8385-39dc-54d8-aa22-059f2a139521",
      "name": "Authentication Refused",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        240
      ],
      "onError": "stopWorkflow"
    },
    {
      "parameters": {
        "respondWith": "text",
        "responseBody": "={{ JSON.stringify($json.reply) }}",
        "options": {
          "responseCode": "={{ $json.httpStatus }}",
          "responseHeaders": {
            "entries": [
              {
                "name": "content-type",
                "value": "application/json"
              }
            ]
          }
        }
      },
      "id": "cfc8c709-79ec-5f4e-93bc-921c619641b0",
      "name": "Reply to Voicely",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        4300,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "a4fdf8ad-c468-51d4-a545-be1c7cc47701",
              "leftValue": "={{ $('Accept Voicely Event').first().json.event.type === 'telephony.call.start' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "38e12feb-7de9-5278-b008-ab804a83faca",
      "name": "Is call start (ring)?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        800,
        -1300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "ad67398a-653a-5fef-954b-c9cbcd1f3065",
              "leftValue": "={{ $('Accept Voicely Event').first().json.event.type === 'telephony.call.lookup' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "fdc77d76-522c-5e62-a9f1-a24bc875fbde",
      "name": "Is call lookup (mid-call)?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        800,
        -800
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "998af99b-521e-531d-921d-a3829fc37897",
              "leftValue": "={{ $('Accept Voicely Event').first().json.event.data.action === 'verify' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "1eaba86f-ed18-58f2-be96-1b581c3dee07",
      "name": "Is verify (caller check)?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1060,
        -800
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "2028f3ac-1b5f-5a67-94c2-37df29a3309a",
              "leftValue": "={{ $('Accept Voicely Event').first().json.event.type === 'calling.call.completed' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "da6f7896-410e-5c22-9a0a-575f15062e38",
      "name": "Is call completed (request)?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        800,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const ev=$('Accept Voicely Event').first().json.event,pol=$('DemoCare Policy').first().json.voicelyPolicy;\nconst S=v=>v===undefined||v===null?'':String(v).trim();\n// Ring time. DemoCare turns caller verification ON, and then Voicely does not give the call-start reply to the agent at all\n// so this lane returns NO patient context: a phone number is never proof of identity anyway.\n// It only logs that a call started.\nconst d=ev.data||{};\nreturn [{json:{httpStatus:200,reply:{variables:{}},row:{event_id:ev.id,call_id:S(d.call_id),event_type:ev.type,patient_reference:'',\n  agent_id:S(d.agent_id),status:'ringing',duration_ms:'',recording_url:'',received_at:new Date().toISOString()}}}];"
      },
      "id": "74490d00-dc37-5ffc-b65c-de127cfa5609",
      "name": "Build Ring Reply",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1060,
        -1300
      ]
    },
    {
      "parameters": {
        "respondWith": "text",
        "responseBody": "={{ JSON.stringify($json.reply) }}",
        "options": {
          "responseCode": "={{ $json.httpStatus }}",
          "responseHeaders": {
            "entries": [
              {
                "name": "content-type",
                "value": "application/json"
              }
            ]
          }
        }
      },
      "id": "b3181be2-b149-59a9-a70e-3594debd9a18",
      "name": "Reply at Ring",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        1290,
        -1300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "3bbcc1d3-24d4-5b90-9cfa-4fe0063d60e5",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage !== 'sheets' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "b30c55d7-71c2-5345-8242-6a632e1b565c",
      "name": "Log Ring: Data Table?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1520,
        -1300
      ]
    },
    {
      "parameters": {
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.callsTableId }}",
          "mode": "id"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "event_id": "={{ $('Build Ring Reply').first().json.row.event_id }}",
            "call_id": "={{ $('Build Ring Reply').first().json.row.call_id }}",
            "event_type": "={{ $('Build Ring Reply').first().json.row.event_type }}",
            "patient_reference": "={{ $('Build Ring Reply').first().json.row.patient_reference }}",
            "agent_id": "={{ $('Build Ring Reply').first().json.row.agent_id }}",
            "status": "={{ $('Build Ring Reply').first().json.row.status }}",
            "duration_ms": "={{ $('Build Ring Reply').first().json.row.duration_ms }}",
            "recording_url": "={{ $('Build Ring Reply').first().json.row.recording_url }}",
            "received_at": "={{ $('Build Ring Reply').first().json.row.received_at }}"
          }
        }
      },
      "id": "0adc6f15-a0a9-522a-ba32-7f464274b109",
      "name": "Log Ring (Data Table)",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1750,
        -1390
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "649166cc-00ee-5016-be45-e83604df6661",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage === 'both' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c137d40d-3593-5902-ba79-1a813ae14a81",
      "name": "Log Ring: mirror to Sheet?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1980,
        -1390
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.documentId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.callsSheet }}",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "event_id": "={{ $('Build Ring Reply').first().json.row.event_id }}",
            "call_id": "={{ $('Build Ring Reply').first().json.row.call_id }}",
            "event_type": "={{ $('Build Ring Reply').first().json.row.event_type }}",
            "patient_reference": "={{ $('Build Ring Reply').first().json.row.patient_reference }}",
            "agent_id": "={{ $('Build Ring Reply').first().json.row.agent_id }}",
            "status": "={{ $('Build Ring Reply').first().json.row.status }}",
            "duration_ms": "={{ $('Build Ring Reply').first().json.row.duration_ms }}",
            "recording_url": "={{ $('Build Ring Reply').first().json.row.recording_url }}",
            "received_at": "={{ $('Build Ring Reply').first().json.row.received_at }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "event_id",
              "displayName": "event_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "call_id",
              "displayName": "call_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "event_type",
              "displayName": "event_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "patient_reference",
              "displayName": "patient_reference",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "agent_id",
              "displayName": "agent_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "duration_ms",
              "displayName": "duration_ms",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "recording_url",
              "displayName": "recording_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "received_at",
              "displayName": "received_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "cellFormat": "RAW"
        }
      },
      "id": "460726ce-779b-520f-81a7-7015841056c5",
      "name": "Log Ring (Sheet)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        2210,
        -1210
      ],
      "alwaysOutputData": true,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "jsCode": "const ev=$('Accept Voicely Event').first().json.event,pol=$('DemoCare Policy').first().json.voicelyPolicy;\nconst S=v=>v===undefined||v===null?'':String(v).trim();\n// Callers say \"2101\", \"APT 2101\", \"apt-2101\"... all mean APT-2101 (DemoCare references are APT- + 4 digits).\nconst apt=v=>{const m=/^(?:APT)?(\\d{4})$/.exec(S(v).toUpperCase().replace(/[\\s_.\\-]+/g,''));return m?'APT-'+m[1]:'__invalid__';};\n// The PIN the caller spoke is hashed HERE (SHA-256 of pinSalt + \":\" + digits) and the raw value goes no further in the\n// workflow: the comparison, the calls log and the reply only ever see the hash or true/false. Pure JavaScript (no module).\n const K=new Uint32Array([0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2]);\n const sha256=msg=>{const l=msg.length,n=((l+9+63)>>6)<<6,b=new Uint8Array(n);b.set(msg);b[l]=0x80;const bits=l*8;\n  for(let i=0;i<8;i++)b[n-1-i]=Math.floor(bits/2**(8*i))&255;\n  const H=new Uint32Array([0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19]),W=new Uint32Array(64);\n  const r=(x,s)=>(x>>>s)|(x<<(32-s));\n  for(let o=0;o<n;o+=64){for(let i=0;i<16;i++)W[i]=(b[o+4*i]<<24)|(b[o+4*i+1]<<16)|(b[o+4*i+2]<<8)|b[o+4*i+3];\n   for(let i=16;i<64;i++){const s0=r(W[i-15],7)^r(W[i-15],18)^(W[i-15]>>>3),s1=r(W[i-2],17)^r(W[i-2],19)^(W[i-2]>>>10);W[i]=(W[i-16]+s0+W[i-7]+s1)>>>0;}\n   let [a,bb,c,d,e,f,g,h]=H;\n   for(let i=0;i<64;i++){const S1=r(e,6)^r(e,11)^r(e,25),ch=(e&f)^(~e&g),t1=(h+S1+ch+K[i]+W[i])>>>0,S0=r(a,2)^r(a,13)^r(a,22),mj=(a&bb)^(a&c)^(bb&c),t2=(S0+mj)>>>0;\n    h=g;g=f;f=e;e=(d+t1)>>>0;d=c;c=bb;bb=a;a=(t1+t2)>>>0;}\n   H[0]+=a;H[1]+=bb;H[2]+=c;H[3]+=d;H[4]+=e;H[5]+=f;H[6]+=g;H[7]+=h;}\n  const out=new Uint8Array(32);for(let i=0;i<8;i++){out[4*i]=H[i]>>>24;out[4*i+1]=(H[i]>>>16)&255;out[4*i+2]=(H[i]>>>8)&255;out[4*i+3]=H[i]&255;}return out;};\n\nif(typeof pol.pinSalt!=='string'||pol.pinSalt.length<16||pol.pinSalt.startsWith('SET_'))throw Error('democare_pin_salt_not_configured');\nconst d=ev.data||{},pin=S(d.verification&&d.verification.pin).replace(/\\D/g,'');\nconst hex=pin?Array.from(sha256(Uint8Array.from(Buffer.from(pol.pinSalt+':'+pin,'utf8'))),x=>x.toString(16).padStart(2,'0')).join(''):'';\nreturn [{json:{appointment_id:apt(d.reference),pin_hash:hex}}];"
      },
      "id": "eabb4925-a221-55e6-8cdc-3de277273917",
      "name": "Normalize Verify Request",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1290,
        -950
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "9b8e1686-b430-57b9-ba66-dc8ff1f892a9",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage !== 'sheets' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "65dd03a0-5db7-5926-bd45-081b95c9f9ce",
      "name": "Read Appointment (verify): Data Table?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1520,
        -950
      ]
    },
    {
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.appointmentsTableId }}",
          "mode": "id"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "appointment_id",
              "keyValue": "={{ $('Normalize Verify Request').first().json.appointment_id }}"
            }
          ]
        },
        "limit": 3
      },
      "id": "50dc1d4b-6cb8-5af7-a161-a0c053a030f5",
      "name": "Read Appointment (verify) (Data Table)",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1750,
        -1040
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.documentId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.appointmentsSheet }}",
          "mode": "name"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "appointment_id",
              "lookupValue": "={{ $('Normalize Verify Request').first().json.appointment_id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "78ae9240-4a24-5272-a753-2cbde82ab4a3",
      "name": "Read Appointment (verify) (Sheet)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1750,
        -860
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "jsCode": "// Data Table or Sheet rows, whichever store the policy reads from. Always ONE item, so the lane continues on 0 rows.\nconst rows=$input.all().map(i=>i.json).filter(r=>r&&Object.keys(r).length>0);\nreturn [{json:{rows}}];"
      },
      "id": "53c6466f-4575-5a1a-a6b9-14527228b20c",
      "name": "Collect Appointment (verify)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1980,
        -950
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "f01147e6-7f0b-57c1-8aeb-7f4767b77ef2",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage !== 'sheets' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "7e4bfb2c-0b2a-521e-9ce7-2f791d204ee5",
      "name": "Read Patient (verify): Data Table?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2210,
        -950
      ]
    },
    {
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.patientsTableId }}",
          "mode": "id"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "patient_id",
              "keyValue": "={{ ($('Collect Appointment (verify)').first().json.rows.length===1 ? String($('Collect Appointment (verify)').first().json.rows[0].patient_id||'').trim() : '') || '__none__' }}"
            }
          ]
        },
        "limit": 3
      },
      "id": "f36ca360-3712-5742-9e53-8ac7290f4842",
      "name": "Read Patient (verify) (Data Table)",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        2440,
        -1040
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.documentId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.patientsSheet }}",
          "mode": "name"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "patient_id",
              "lookupValue": "={{ ($('Collect Appointment (verify)').first().json.rows.length===1 ? String($('Collect Appointment (verify)').first().json.rows[0].patient_id||'').trim() : '') || '__none__' }}"
            }
          ]
        },
        "options": {}
      },
      "id": "9c5baf90-8152-52d7-bd7f-3e85296fddfd",
      "name": "Read Patient (verify) (Sheet)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        2440,
        -860
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "jsCode": "// Data Table or Sheet rows, whichever store the policy reads from. Always ONE item, so the lane continues on 0 rows.\nconst rows=$input.all().map(i=>i.json).filter(r=>r&&Object.keys(r).length>0);\nreturn [{json:{rows}}];"
      },
      "id": "392b6bfa-f7ee-58e6-b432-ddd5b2111b43",
      "name": "Collect Patient (verify)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2670,
        -950
      ]
    },
    {
      "parameters": {
        "jsCode": "const ev=$('Accept Voicely Event').first().json.event,pol=$('DemoCare Policy').first().json.voicelyPolicy;\nconst S=v=>v===undefined||v===null?'':String(v).trim();\n// EXACT match only: one appointment, one patient, and the stored pin_hash equals the hash of what the caller said.\n// Anything else (unknown appointment, wrong PIN, duplicate rows) is verified:false. The reply carries NOTHING else, so the\n// caller never learns whether the appointment exists. Voicely counts attempts and applies your on-fail policy.\nconst want=$('Normalize Verify Request').first().json,apts=$('Collect Appointment (verify)').first().json.rows.filter(r=>S(r.appointment_id)===want.appointment_id);\nconst pats=$input.first().json.rows.filter(r=>apts.length===1&&S(r.patient_id)===S(apts[0].patient_id));\nconst eq=(a,b)=>{if(a.length!==64||b.length!==64)return false;let x=0;for(let i=0;i<64;i++)x|=a.charCodeAt(i)^b.charCodeAt(i);return x===0;};\nconst dup=apts.length>1||pats.length>1;\nconst ok=!dup&&apts.length===1&&pats.length===1&&want.pin_hash!==''&&eq(S(pats[0].pin_hash).toLowerCase(),want.pin_hash);\nconst d=ev.data||{};\nreturn [{json:{httpStatus:200,reply:{result:{verified:ok}},row:{event_id:ev.id,call_id:S(d.call_id),event_type:'verify.result',\n  patient_reference:want.appointment_id==='__invalid__'?'':want.appointment_id,agent_id:S(d.agent_id),\n  status:dup?'data_error_duplicate_rows':ok?'verified':'not_verified',duration_ms:'',recording_url:'',received_at:new Date().toISOString()}}}];"
      },
      "id": "a793e084-428e-571c-ad6d-c66c47753d16",
      "name": "Decide Verification",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2900,
        -950
      ]
    },
    {
      "parameters": {
        "respondWith": "text",
        "responseBody": "={{ JSON.stringify($json.reply) }}",
        "options": {
          "responseCode": "={{ $json.httpStatus }}",
          "responseHeaders": {
            "entries": [
              {
                "name": "content-type",
                "value": "application/json"
              }
            ]
          }
        }
      },
      "id": "8cb5c147-cfa2-5c2b-b859-51d477257c76",
      "name": "Reply (verify)",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        3130,
        -950
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "8a0b7693-e0ef-536f-93cc-0b748f686cee",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage !== 'sheets' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "214eec14-4802-5ab5-ba0f-48b74405591b",
      "name": "Log Verify Result: Data Table?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        3360,
        -950
      ]
    },
    {
      "parameters": {
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.callsTableId }}",
          "mode": "id"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "event_id": "={{ $('Decide Verification').first().json.row.event_id }}",
            "call_id": "={{ $('Decide Verification').first().json.row.call_id }}",
            "event_type": "={{ $('Decide Verification').first().json.row.event_type }}",
            "patient_reference": "={{ $('Decide Verification').first().json.row.patient_reference }}",
            "agent_id": "={{ $('Decide Verification').first().json.row.agent_id }}",
            "status": "={{ $('Decide Verification').first().json.row.status }}",
            "duration_ms": "={{ $('Decide Verification').first().json.row.duration_ms }}",
            "recording_url": "={{ $('Decide Verification').first().json.row.recording_url }}",
            "received_at": "={{ $('Decide Verification').first().json.row.received_at }}"
          }
        }
      },
      "id": "fdb1ed5f-4695-5bda-ae38-f2cb53ecb95e",
      "name": "Log Verify Result (Data Table)",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        3590,
        -1040
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c2faf2ab-8f22-59c6-8c5e-3645c8ceb551",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage === 'both' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "061abe60-4a65-5e60-bc80-389986cd434c",
      "name": "Log Verify Result: mirror to Sheet?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        3820,
        -1040
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.documentId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.callsSheet }}",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "event_id": "={{ $('Decide Verification').first().json.row.event_id }}",
            "call_id": "={{ $('Decide Verification').first().json.row.call_id }}",
            "event_type": "={{ $('Decide Verification').first().json.row.event_type }}",
            "patient_reference": "={{ $('Decide Verification').first().json.row.patient_reference }}",
            "agent_id": "={{ $('Decide Verification').first().json.row.agent_id }}",
            "status": "={{ $('Decide Verification').first().json.row.status }}",
            "duration_ms": "={{ $('Decide Verification').first().json.row.duration_ms }}",
            "recording_url": "={{ $('Decide Verification').first().json.row.recording_url }}",
            "received_at": "={{ $('Decide Verification').first().json.row.received_at }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "event_id",
              "displayName": "event_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "call_id",
              "displayName": "call_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "event_type",
              "displayName": "event_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "patient_reference",
              "displayName": "patient_reference",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "agent_id",
              "displayName": "agent_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "duration_ms",
              "displayName": "duration_ms",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "recording_url",
              "displayName": "recording_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "received_at",
              "displayName": "received_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "cellFormat": "RAW"
        }
      },
      "id": "2421c279-2ca5-5620-ad21-30f4dc3795af",
      "name": "Log Verify Result (Sheet)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        4050,
        -860
      ],
      "alwaysOutputData": true,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "jsCode": "const ev=$('Accept Voicely Event').first().json.event,pol=$('DemoCare Policy').first().json.voicelyPolicy;\nconst S=v=>v===undefined||v===null?'':String(v).trim();\n// Callers say \"2101\", \"APT 2101\", \"apt-2101\"... all mean APT-2101 (DemoCare references are APT- + 4 digits).\nconst apt=v=>{const m=/^(?:APT)?(\\d{4})$/.exec(S(v).toUpperCase().replace(/[\\s_.\\-]+/g,''));return m?'APT-'+m[1]:'__invalid__';};\n// Voicely only sends this AFTER verify_caller returned verified for this same reference in this call (Voicely enforces it,\n// and sends the exact reference that was verified).\nreturn [{json:{appointment_id:apt((ev.data||{}).reference)}}];"
      },
      "id": "be07cb44-6f85-59bb-82b2-33cbec442834",
      "name": "Normalize Lookup Reference",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1290,
        -600
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "b0b734bf-2056-5a12-a903-8817c9720e9a",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage !== 'sheets' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "0bff7c91-7354-54ee-b0a0-8865a41f8f15",
      "name": "Read Appointment (lookup): Data Table?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1520,
        -600
      ]
    },
    {
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.appointmentsTableId }}",
          "mode": "id"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "appointment_id",
              "keyValue": "={{ $('Normalize Lookup Reference').first().json.appointment_id }}"
            }
          ]
        },
        "limit": 3
      },
      "id": "1ee0205f-1f2b-5df2-b6c2-59c4f1c586c7",
      "name": "Read Appointment (lookup) (Data Table)",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1750,
        -690
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.documentId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.appointmentsSheet }}",
          "mode": "name"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "appointment_id",
              "lookupValue": "={{ $('Normalize Lookup Reference').first().json.appointment_id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "644744f9-e36d-559b-a8fa-cea845ae5120",
      "name": "Read Appointment (lookup) (Sheet)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1750,
        -510
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "jsCode": "// Data Table or Sheet rows, whichever store the policy reads from. Always ONE item, so the lane continues on 0 rows.\nconst rows=$input.all().map(i=>i.json).filter(r=>r&&Object.keys(r).length>0);\nreturn [{json:{rows}}];"
      },
      "id": "a98e8699-56d1-5bcd-96be-a72f6827b798",
      "name": "Collect Appointment (lookup)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1980,
        -600
      ]
    },
    {
      "parameters": {
        "jsCode": "const ev=$('Accept Voicely Event').first().json.event,pol=$('DemoCare Policy').first().json.voicelyPolicy;\nconst S=v=>v===undefined||v===null?'':String(v).trim();\n// FORMAT FOR VOICELY (keep this node if you swap the data source). Explicit caller-safe projection: ONLY these fields.\n// Patient name, phone, email and the PIN hash are never returned. Set the SAME names as \"Shared with the agent\" fields\n// on the DemoCare Receptionist agent in Voicely (all Text).\nconst want=$('Normalize Lookup Reference').first().json.appointment_id;\nconst rows=$input.first().json.rows.filter(r=>S(r.appointment_id)===want);\nif(rows.length>1)return [{json:{httpStatus:200,reply:{result:{found:false}},data_error:'duplicate_appointment_rows',duplicate_rows:rows.length,appointment_id:want}}];\nif(rows.length!==1)return [{json:{httpStatus:200,reply:{result:{found:false}}}}];\nconst r=rows[0],map={doctor:'doctor_name',specialty:'specialty',appointment_date:'appointment_date',appointment_time:'appointment_time',status:'appointment_status'};\n// n8n Data Tables may store a CSV date column as a DATE and return \"2026-11-24T00:00:00.000Z\": the caller should hear the day only.\nconst day=v=>{const m=/^(\\d{4}-\\d{2}-\\d{2})T00:00:00(?:\\.000)?Z$/.exec(v);return m?m[1]:v;};\nconst result={found:true};for(const [k,col] of Object.entries(map)){const v=day(S(r[col]));if(v)result[k]=v;}\nreturn [{json:{httpStatus:200,reply:{result}}}];"
      },
      "id": "022edafa-1ab3-5c17-b26f-77595f45b899",
      "name": "Format for Voicely (lookup)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2210,
        -600
      ]
    },
    {
      "parameters": {
        "respondWith": "text",
        "responseBody": "={{ JSON.stringify($json.reply) }}",
        "options": {
          "responseCode": "={{ $json.httpStatus }}",
          "responseHeaders": {
            "entries": [
              {
                "name": "content-type",
                "value": "application/json"
              }
            ]
          }
        }
      },
      "id": "977ea3a1-b6b3-56a8-a656-0a753ac06070",
      "name": "Reply (lookup)",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        2440,
        -600
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "88c0a6ff-0ea3-5382-bb8c-a528c9273b5e",
              "leftValue": "={{ !!$json.data_error }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "b95eb80f-e8b3-5784-8802-e858865d4af8",
      "name": "Lookup data error?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2440,
        -420
      ]
    },
    {
      "parameters": {
        "jsCode": "const ev=$('Accept Voicely Event').first().json.event,pol=$('DemoCare Policy').first().json.voicelyPolicy;\nconst S=v=>v===undefined||v===null?'':String(v).trim();\nconst j=$('Format for Voicely (lookup)').first().json,d=ev.data||{};\nreturn [{json:{row:{event_id:ev.id,call_id:S(d.call_id),event_type:'lookup.data_error',patient_reference:S(j.appointment_id),agent_id:S(d.agent_id),\n  status:S(j.data_error)+' x'+S(j.duplicate_rows),duration_ms:'',recording_url:'',received_at:new Date().toISOString()}}}];"
      },
      "id": "fa7eb6c0-56c3-5abd-b812-d0e2a2fece0b",
      "name": "Build Lookup Error Row",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2670,
        -420
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "d8257a32-4027-554e-9a8c-2751c3dce4b8",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage !== 'sheets' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "49ae4942-5216-5866-94e8-58fd2b1019c7",
      "name": "Log Lookup Error: Data Table?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2900,
        -420
      ]
    },
    {
      "parameters": {
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.callsTableId }}",
          "mode": "id"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "event_id": "={{ $('Build Lookup Error Row').first().json.row.event_id }}",
            "call_id": "={{ $('Build Lookup Error Row').first().json.row.call_id }}",
            "event_type": "={{ $('Build Lookup Error Row').first().json.row.event_type }}",
            "patient_reference": "={{ $('Build Lookup Error Row').first().json.row.patient_reference }}",
            "agent_id": "={{ $('Build Lookup Error Row').first().json.row.agent_id }}",
            "status": "={{ $('Build Lookup Error Row').first().json.row.status }}",
            "duration_ms": "={{ $('Build Lookup Error Row').first().json.row.duration_ms }}",
            "recording_url": "={{ $('Build Lookup Error Row').first().json.row.recording_url }}",
            "received_at": "={{ $('Build Lookup Error Row').first().json.row.received_at }}"
          }
        }
      },
      "id": "ca939b2f-e747-5949-8c35-e6c46299ea84",
      "name": "Log Lookup Error (Data Table)",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        3130,
        -510
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "8ecd236f-189e-5525-ab78-a68c0d72075a",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage === 'both' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "839a378c-ec38-51cd-8998-41d693c47404",
      "name": "Log Lookup Error: mirror to Sheet?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        3360,
        -510
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.documentId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.callsSheet }}",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "event_id": "={{ $('Build Lookup Error Row').first().json.row.event_id }}",
            "call_id": "={{ $('Build Lookup Error Row').first().json.row.call_id }}",
            "event_type": "={{ $('Build Lookup Error Row').first().json.row.event_type }}",
            "patient_reference": "={{ $('Build Lookup Error Row').first().json.row.patient_reference }}",
            "agent_id": "={{ $('Build Lookup Error Row').first().json.row.agent_id }}",
            "status": "={{ $('Build Lookup Error Row').first().json.row.status }}",
            "duration_ms": "={{ $('Build Lookup Error Row').first().json.row.duration_ms }}",
            "recording_url": "={{ $('Build Lookup Error Row').first().json.row.recording_url }}",
            "received_at": "={{ $('Build Lookup Error Row').first().json.row.received_at }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "event_id",
              "displayName": "event_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "call_id",
              "displayName": "call_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "event_type",
              "displayName": "event_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "patient_reference",
              "displayName": "patient_reference",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "agent_id",
              "displayName": "agent_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "duration_ms",
              "displayName": "duration_ms",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "recording_url",
              "displayName": "recording_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "received_at",
              "displayName": "received_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "cellFormat": "RAW"
        }
      },
      "id": "4cb26a42-9a73-5d1e-a870-e4e5ad92a0c1",
      "name": "Log Lookup Error (Sheet)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        3590,
        -330
      ],
      "alwaysOutputData": true,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "1e72da31-4b7d-533d-b3a2-930931497a87",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage !== 'sheets' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "89a46de7-5c2d-5bdc-aaf9-1fb6def0e9e7",
      "name": "Read Requests (after call): Data Table?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1060,
        0
      ]
    },
    {
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.requestsTableId }}",
          "mode": "id"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "call_id",
              "keyValue": "={{ String($('Accept Voicely Event').first().json.event.data.call_id||'').trim() || '__none__' }}"
            }
          ]
        },
        "limit": 3
      },
      "id": "5803d07e-a6d9-50e2-8ad3-cbf9af34487c",
      "name": "Read Requests (after call) (Data Table)",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1290,
        -90
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.documentId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.requestsSheet }}",
          "mode": "name"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "call_id",
              "lookupValue": "={{ String($('Accept Voicely Event').first().json.event.data.call_id||'').trim() || '__none__' }}"
            }
          ]
        },
        "options": {}
      },
      "id": "3f652ae0-ed68-5cb0-b00f-774adb769b02",
      "name": "Read Requests (after call) (Sheet)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1290,
        90
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "jsCode": "// Data Table or Sheet rows, whichever store the policy reads from. Always ONE item, so the lane continues on 0 rows.\nconst rows=$input.all().map(i=>i.json).filter(r=>r&&Object.keys(r).length>0);\nreturn [{json:{rows}}];"
      },
      "id": "ebf36cb0-989a-5f9b-b2b4-cc71c2b30d60",
      "name": "Collect Requests (after call)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1520,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const ev=$('Accept Voicely Event').first().json.event,pol=$('DemoCare Policy').first().json.voicelyPolicy;\nconst S=v=>v===undefined||v===null?'':String(v).trim();\n// Callers say \"2101\", \"APT 2101\", \"apt-2101\"... all mean APT-2101 (DemoCare references are APT- + 4 digits).\nconst apt=v=>{const m=/^(?:APT)?(\\d{4})$/.exec(S(v).toUpperCase().replace(/[\\s_.\\-]+/g,''));return m?'APT-'+m[1]:'__invalid__';};\n// Voicely extracted the agent's lead fields after the call. This records a REQUEST with status pending_confirmation:\n// nothing is booked, rescheduled or cancelled here, and the existing appointment is never changed. Reception confirms.\n// The appointment number in a lead is what the caller CLAIMED, so it is stored as a reference only (no patient link).\nconst d=ev.data||{},lead=d.lead||{},f=k=>S((lead.data||{})[k]),callId=S(d.call_id);\nconst existing=$input.first().json.rows.some(r=>S(r.call_id)===callId||S(r.event_id)===ev.id);\nif(!callId||existing)return [{json:{action:'none',httpStatus:200,reply:{received:true,replay:existing}}}];\nconst types=['new_appointment','reschedule','cancel','general_inquiry','verification_assistance'];\nconst t=f('request_type').toLowerCase().replace(/[\\s\\-]+/g,'_'),type=types.includes(t)?t:'general_inquiry';\nconst name=f('caller_name'),phone=f('contact_number')||S(d.caller_number);\n// A request needs something the caller actually asked for in the lead; the caller ID alone is not a request.\nif(!['request_type','caller_name','contact_number','requested_date','requested_time','appointment_reference','notes'].some(k=>f(k)))\n return [{json:{action:'none',httpStatus:200,reply:{received:true,empty_lead:true}}}];\n// Never keep a spoken PIN or code in notes (a lead model can copy it from the conversation).\nconst notes=f('notes').replace(/\\b(pin|code|passcode)\\b[^0-9]{0,12}\\d{3,8}/gi,'$1 [removed]').slice(0,500);\nconst ref=f('appointment_reference')?apt(f('appointment_reference')):'';\nconst id='REQ-'+callId.replace(/[^0-9a-f]/gi,'').slice(0,8).toUpperCase();\nconst doctor=f('doctor'),date=f('requested_date'),time=f('requested_time');\nconst notification=pol.clinicName+' appointment request '+id+': '+(name||'caller')+', '+type.replace(/_/g,' ')+\n  (doctor?', '+doctor:'')+(date||time?', requested '+[date,time].filter(Boolean).join(' '):'')+'. Status: pending confirmation.';\nreturn [{json:{action:'create',httpStatus:200,reply:{received:true,request_id:id},request:{request_id:id,call_id:callId,event_id:ev.id,request_type:type,\n  patient_name:name,phone,email:f('email'),doctor_name:doctor,requested_date:date,requested_time:time,\n  appointment_reference:ref==='__invalid__'?'':ref,notes,status:'pending_confirmation',notification,created_at:new Date().toISOString()}}}];"
      },
      "id": "078ecb0f-2bd0-5d1a-aebd-a62829c0daf9",
      "name": "Build Request from Lead",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1750,
        0
      ],
      "onError": "stopWorkflow"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "a64562b3-c44c-5251-bee9-0338e0f02ec4",
              "leftValue": "={{ $json.action === 'create' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "4e129db8-ad85-5037-be9c-d0da3dcc7db8",
      "name": "New request needed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1980,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const j=$('Build Request from Lead').first().json;\n// Synthetic clinic notification for testing: the text is stored in the requests row (\"notification\"). No email is sent.\nreturn [{json:{httpStatus:j.httpStatus,reply:j.reply}}];"
      },
      "id": "731e91bb-c8b8-5111-8d84-50732f0da9f4",
      "name": "Request Filed",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3130,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "6e1d8e99-c4dc-58cd-9ad8-f006f53112dc",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage !== 'sheets' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "8f07dfed-4449-5d64-b55c-7b48a5976592",
      "name": "Create Request: Data Table?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2210,
        0
      ]
    },
    {
      "parameters": {
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.requestsTableId }}",
          "mode": "id"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "request_id": "={{ $('Build Request from Lead').first().json.request.request_id }}",
            "call_id": "={{ $('Build Request from Lead').first().json.request.call_id }}",
            "event_id": "={{ $('Build Request from Lead').first().json.request.event_id }}",
            "request_type": "={{ $('Build Request from Lead').first().json.request.request_type }}",
            "patient_name": "={{ $('Build Request from Lead').first().json.request.patient_name }}",
            "phone": "={{ $('Build Request from Lead').first().json.request.phone }}",
            "email": "={{ $('Build Request from Lead').first().json.request.email }}",
            "doctor_name": "={{ $('Build Request from Lead').first().json.request.doctor_name }}",
            "requested_date": "={{ $('Build Request from Lead').first().json.request.requested_date }}",
            "requested_time": "={{ $('Build Request from Lead').first().json.request.requested_time }}",
            "appointment_reference": "={{ $('Build Request from Lead').first().json.request.appointment_reference }}",
            "notes": "={{ $('Build Request from Lead').first().json.request.notes }}",
            "status": "={{ $('Build Request from Lead').first().json.request.status }}",
            "notification": "={{ $('Build Request from Lead').first().json.request.notification }}",
            "created_at": "={{ $('Build Request from Lead').first().json.request.created_at }}"
          }
        }
      },
      "id": "b17d4ffc-3fc4-5d98-8582-e2a32b6728f8",
      "name": "Create Request (Data Table)",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        2440,
        -90
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "5f580933-4a21-592a-ac47-585bbb8d536e",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage === 'both' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "bfbb0929-740c-5c1f-a5b0-8f7b95a6a2fa",
      "name": "Create Request: mirror to Sheet?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2670,
        -90
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.documentId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.requestsSheet }}",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "request_id": "={{ $('Build Request from Lead').first().json.request.request_id }}",
            "call_id": "={{ $('Build Request from Lead').first().json.request.call_id }}",
            "event_id": "={{ $('Build Request from Lead').first().json.request.event_id }}",
            "request_type": "={{ $('Build Request from Lead').first().json.request.request_type }}",
            "patient_name": "={{ $('Build Request from Lead').first().json.request.patient_name }}",
            "phone": "={{ $('Build Request from Lead').first().json.request.phone }}",
            "email": "={{ $('Build Request from Lead').first().json.request.email }}",
            "doctor_name": "={{ $('Build Request from Lead').first().json.request.doctor_name }}",
            "requested_date": "={{ $('Build Request from Lead').first().json.request.requested_date }}",
            "requested_time": "={{ $('Build Request from Lead').first().json.request.requested_time }}",
            "appointment_reference": "={{ $('Build Request from Lead').first().json.request.appointment_reference }}",
            "notes": "={{ $('Build Request from Lead').first().json.request.notes }}",
            "status": "={{ $('Build Request from Lead').first().json.request.status }}",
            "notification": "={{ $('Build Request from Lead').first().json.request.notification }}",
            "created_at": "={{ $('Build Request from Lead').first().json.request.created_at }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "request_id",
              "displayName": "request_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "call_id",
              "displayName": "call_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "event_id",
              "displayName": "event_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "request_type",
              "displayName": "request_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "patient_name",
              "displayName": "patient_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "phone",
              "displayName": "phone",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "email",
              "displayName": "email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "doctor_name",
              "displayName": "doctor_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "requested_date",
              "displayName": "requested_date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "requested_time",
              "displayName": "requested_time",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "appointment_reference",
              "displayName": "appointment_reference",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "notes",
              "displayName": "notes",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "notification",
              "displayName": "notification",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "created_at",
              "displayName": "created_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "cellFormat": "RAW"
        }
      },
      "id": "bb58d695-e037-5a92-9a29-9e994b12a44d",
      "name": "Create Request (Sheet)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        2900,
        90
      ],
      "alwaysOutputData": true,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "jsCode": "const ev=$('Accept Voicely Event').first().json.event,pol=$('DemoCare Policy').first().json.voicelyPolicy;\nconst S=v=>v===undefined||v===null?'':String(v).trim();\n// One log row per event. Only the signed recording LINK is kept (it expires per your retention); transcript text is not copied.\nconst d=ev.data||{},rec=d.recording||{};\nreturn [{json:{httpStatus:200,reply:{received:true},row:{event_id:ev.id,call_id:S(d.call_id),event_type:ev.type,patient_reference:'',agent_id:S(d.agent_id),\n  status:S(d.status),duration_ms:S(d.duration_ms),recording_url:S(rec.caller_url||rec.recording_url||rec.url||''),received_at:new Date().toISOString()}}}];"
      },
      "id": "0f00eb88-26f0-5a67-8098-828425cfb435",
      "name": "Build Call Log Row",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1060,
        520
      ],
      "onError": "stopWorkflow"
    },
    {
      "parameters": {
        "jsCode": "return [{json:{httpStatus:200,reply:$('Build Call Log Row').first().json.reply}}];"
      },
      "id": "94589b5e-1843-5598-b588-2b67ed118e8d",
      "name": "Call Logged",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2210,
        520
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "025ad5f6-4d10-5a2e-a40c-afef1afa1302",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage !== 'sheets' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "88cb803a-9a79-563b-bdd8-1ff6da8171fc",
      "name": "Log Call Event: Data Table?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1290,
        520
      ]
    },
    {
      "parameters": {
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.callsTableId }}",
          "mode": "id"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "event_id": "={{ $('Build Call Log Row').first().json.row.event_id }}",
            "call_id": "={{ $('Build Call Log Row').first().json.row.call_id }}",
            "event_type": "={{ $('Build Call Log Row').first().json.row.event_type }}",
            "patient_reference": "={{ $('Build Call Log Row').first().json.row.patient_reference }}",
            "agent_id": "={{ $('Build Call Log Row').first().json.row.agent_id }}",
            "status": "={{ $('Build Call Log Row').first().json.row.status }}",
            "duration_ms": "={{ $('Build Call Log Row').first().json.row.duration_ms }}",
            "recording_url": "={{ $('Build Call Log Row').first().json.row.recording_url }}",
            "received_at": "={{ $('Build Call Log Row').first().json.row.received_at }}"
          }
        }
      },
      "id": "524c3439-5f98-5c4e-b1a7-035b81027a52",
      "name": "Log Call Event (Data Table)",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1520,
        430
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "fdc261ae-5a23-5da7-b92e-51006d9ee20e",
              "leftValue": "={{ $('DemoCare Policy').first().json.voicelyPolicy.storage === 'both' }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "0ee28611-29a2-542a-a1bd-27ed3c138384",
      "name": "Log Call Event: mirror to Sheet?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1750,
        430
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.documentId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('DemoCare Policy').first().json.voicelyPolicy.sheets.callsSheet }}",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "event_id": "={{ $('Build Call Log Row').first().json.row.event_id }}",
            "call_id": "={{ $('Build Call Log Row').first().json.row.call_id }}",
            "event_type": "={{ $('Build Call Log Row').first().json.row.event_type }}",
            "patient_reference": "={{ $('Build Call Log Row').first().json.row.patient_reference }}",
            "agent_id": "={{ $('Build Call Log Row').first().json.row.agent_id }}",
            "status": "={{ $('Build Call Log Row').first().json.row.status }}",
            "duration_ms": "={{ $('Build Call Log Row').first().json.row.duration_ms }}",
            "recording_url": "={{ $('Build Call Log Row').first().json.row.recording_url }}",
            "received_at": "={{ $('Build Call Log Row').first().json.row.received_at }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "event_id",
              "displayName": "event_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "call_id",
              "displayName": "call_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "event_type",
              "displayName": "event_type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "patient_reference",
              "displayName": "patient_reference",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "agent_id",
              "displayName": "agent_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "status",
              "displayName": "status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "duration_ms",
              "displayName": "duration_ms",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "recording_url",
              "displayName": "recording_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            },
            {
              "id": "received_at",
              "displayName": "received_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "cellFormat": "RAW"
        }
      },
      "id": "0f9098a0-c2b2-56cb-bcd2-f78d4beaafba",
      "name": "Log Call Event (Sheet)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1980,
        610
      ],
      "alwaysOutputData": true,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "width": 1220,
        "height": 1470,
        "color": 6,
        "content": "## DemoCare Family Clinic: Voicely SIP receptionist (n8n)\nFictional clinic for testing. One workflow serves ONE Voicely business account.\n\n**Setup (5 steps)**\n1. Create the Data Tables (or Sheet tabs) from the CSV files: `clinic_patients`, `clinic_appointments`, `clinic_requests`, `clinic_calls` (+ `clinic_doctors`, `clinic_slots` for reception; this workflow does not read them).\n2. **DemoCare Policy:** `storage` (`datatable`, `sheets` or `both`), the table IDs, your Voicely account ID (`expectedAccountId`, shown in Voicely > API access > Webhooks) and a long random `pinSalt`. The PIN hashes in `clinic_patients` must be made with the SAME salt.\n3. **Activate**, copy the Production URL, add it in Voicely > API access > Webhooks (events: call start, call lookup, call completed, ended, failed, recording ready).\n4. Paste that endpoint's `whsec_...` secret on the first line of **Verify Voicely HMAC**.\n5. In Voicely, set the DemoCare Receptionist agent: lookup ON, the fields and caller verification as in the setup guide.\n\n**What it does**\n- **Ring:** logs the call. No patient context (verification is ON, so Voicely would not give it to the agent).\n- **Verify:** exact PIN match on your data, replies only true/false.\n- **Lookup:** after Voicely verified the caller, returns the appointment (doctor, date, time, status). Nothing else.\n- **After the call:** records an appointment REQUEST (`pending_confirmation`). Nothing is booked here; reception confirms.\n\n**Privacy:** execution saving is OFF in the workflow settings, because a verify event carries the spoken PIN. Turn it on only while testing with synthetic data.\n\n**Data Tables only?** If `storage` is `datatable`, select all the `(Sheet)` nodes and disable them (press D) before **Publish**. n8n refuses to publish a workflow whose Google Sheets nodes have no credential, even when they never run. For `sheets` or `both`, keep them enabled and select your Google Sheets credential."
      },
      "id": "a62111fe-47c2-5d2c-9d5d-062cf3825715",
      "name": "Note: Start here",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -480,
        -1600
      ]
    },
    {
      "parameters": {
        "width": 1220,
        "height": 560,
        "color": 1,
        "content": "### Every request: verify, then route\nVoicely signs every event with your endpoint secret (`whsec_…`). **Verify Voicely HMAC** checks it (paste the secret on its first line), **Accept** checks freshness, event type and that it is YOUR account (`expectedAccountId`). Anything else → **401**, nothing is read or written.\n\nThen the three routers send the event to its lane: **ring**, **mid-call lookup**, **after the call**, and everything else to the **call log**."
      },
      "id": "2999d97d-ad42-5222-a69e-49ccf7ca9ad6",
      "name": "Note: Security",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -480,
        -180
      ]
    },
    {
      "parameters": {
        "width": 1300,
        "height": 260,
        "color": 7,
        "content": "### Ring: call start\nReplies at once with no variables, then logs `ringing` to the calls log. With caller verification ON, Voicely withholds any call-start context from the agent, so a caller ID never unlocks patient data."
      },
      "id": "9fdda4fe-5d85-567f-991f-627db3f76111",
      "name": "Note: Ring",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1000,
        -1600
      ]
    },
    {
      "parameters": {
        "width": 2400,
        "height": 330,
        "color": 4,
        "content": "### Mid-call: verify the caller\nVoicely sends `action: verify` with the appointment number and the spoken PIN. The PIN is hashed with your `pinSalt` in the first node and compared in constant time with `clinic_patients.pin_hash`. The reply is ONLY `{verified: true|false}`, then the outcome (never the PIN) is logged. Voicely counts attempts and applies the on-fail policy you chose."
      },
      "id": "b42e69f8-7eb5-5f2e-bf9b-784f0736034c",
      "name": "Note: Verify",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1240,
        -1150
      ]
    },
    {
      "parameters": {
        "width": 1900,
        "height": 260,
        "color": 5,
        "content": "### Mid-call: appointment lookup\nOnly after Voicely verified the caller for this same appointment number. Returns doctor, specialty, date, time and status. Duplicate rows give `found: false` and a `lookup.data_error` row in the calls log."
      },
      "id": "fe9dae01-57a3-537f-b263-8bca5af117ce",
      "name": "Note: Lookup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1240,
        -800
      ]
    },
    {
      "parameters": {
        "width": 2400,
        "height": 200,
        "color": 3,
        "content": "### After the call: appointment request\nOne request per call (`REQ-` + call id), status `pending_confirmation`. A replayed event writes nothing. A claimed appointment number is kept as a reference only. The `notification` column holds the synthetic clinic notification text."
      },
      "id": "399dae3e-1afa-5c2c-846e-be95b23b11c0",
      "name": "Note: After call",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1000,
        -240
      ]
    },
    {
      "parameters": {
        "width": 1500,
        "height": 130,
        "color": 7,
        "content": "### Call log\nEnded, failed, recording ready and test events: one row each. Only the signed recording link is kept, never transcript text."
      },
      "id": "73789cd7-04b9-578a-95f5-743b0318eb34",
      "name": "Note: Call log",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1000,
        380
      ]
    }
  ],
  "connections": {
    "Voicely Phone Webhook": {
      "main": [
        [
          {
            "node": "DemoCare Policy",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DemoCare Policy": {
      "main": [
        [
          {
            "node": "Prepare Voicely Signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Voicely Signature": {
      "main": [
        [
          {
            "node": "Verify Voicely HMAC",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Authentication Refused",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verify Voicely HMAC": {
      "main": [
        [
          {
            "node": "Accept Voicely Event",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Authentication Refused",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Authentication Refused": {
      "main": [
        [
          {
            "node": "Reply to Voicely",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Accept Voicely Event": {
      "main": [
        [
          {
            "node": "Is call start (ring)?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Authentication Refused",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is call start (ring)?": {
      "main": [
        [
          {
            "node": "Build Ring Reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Is call lookup (mid-call)?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is call lookup (mid-call)?": {
      "main": [
        [
          {
            "node": "Is verify (caller check)?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Is call completed (request)?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Ring Reply": {
      "main": [
        [
          {
            "node": "Reply at Ring",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Ring: Data Table?": {
      "main": [
        [
          {
            "node": "Log Ring (Data Table)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Ring (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Ring (Data Table)": {
      "main": [
        [
          {
            "node": "Log Ring: mirror to Sheet?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Ring: mirror to Sheet?": {
      "main": [
        [
          {
            "node": "Log Ring (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply at Ring": {
      "main": [
        [
          {
            "node": "Log Ring: Data Table?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Appointment (verify): Data Table?": {
      "main": [
        [
          {
            "node": "Read Appointment (verify) (Data Table)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Read Appointment (verify) (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Appointment (verify) (Data Table)": {
      "main": [
        [
          {
            "node": "Collect Appointment (verify)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Appointment (verify) (Sheet)": {
      "main": [
        [
          {
            "node": "Collect Appointment (verify)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Patient (verify): Data Table?": {
      "main": [
        [
          {
            "node": "Read Patient (verify) (Data Table)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Read Patient (verify) (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Patient (verify) (Data Table)": {
      "main": [
        [
          {
            "node": "Collect Patient (verify)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Patient (verify) (Sheet)": {
      "main": [
        [
          {
            "node": "Collect Patient (verify)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is verify (caller check)?": {
      "main": [
        [
          {
            "node": "Normalize Verify Request",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Normalize Lookup Reference",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Verify Request": {
      "main": [
        [
          {
            "node": "Read Appointment (verify): Data Table?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect Appointment (verify)": {
      "main": [
        [
          {
            "node": "Read Patient (verify): Data Table?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect Patient (verify)": {
      "main": [
        [
          {
            "node": "Decide Verification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decide Verification": {
      "main": [
        [
          {
            "node": "Reply (verify)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Verify Result: Data Table?": {
      "main": [
        [
          {
            "node": "Log Verify Result (Data Table)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Verify Result (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Verify Result (Data Table)": {
      "main": [
        [
          {
            "node": "Log Verify Result: mirror to Sheet?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Verify Result: mirror to Sheet?": {
      "main": [
        [
          {
            "node": "Log Verify Result (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply (verify)": {
      "main": [
        [
          {
            "node": "Log Verify Result: Data Table?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Appointment (lookup): Data Table?": {
      "main": [
        [
          {
            "node": "Read Appointment (lookup) (Data Table)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Read Appointment (lookup) (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Appointment (lookup) (Data Table)": {
      "main": [
        [
          {
            "node": "Collect Appointment (lookup)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Appointment (lookup) (Sheet)": {
      "main": [
        [
          {
            "node": "Collect Appointment (lookup)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Lookup Reference": {
      "main": [
        [
          {
            "node": "Read Appointment (lookup): Data Table?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect Appointment (lookup)": {
      "main": [
        [
          {
            "node": "Format for Voicely (lookup)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format for Voicely (lookup)": {
      "main": [
        [
          {
            "node": "Reply (lookup)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Lookup data error?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lookup data error?": {
      "main": [
        [
          {
            "node": "Build Lookup Error Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Lookup Error: Data Table?": {
      "main": [
        [
          {
            "node": "Log Lookup Error (Data Table)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Lookup Error (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Lookup Error (Data Table)": {
      "main": [
        [
          {
            "node": "Log Lookup Error: mirror to Sheet?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Lookup Error: mirror to Sheet?": {
      "main": [
        [
          {
            "node": "Log Lookup Error (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Lookup Error Row": {
      "main": [
        [
          {
            "node": "Log Lookup Error: Data Table?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Requests (after call): Data Table?": {
      "main": [
        [
          {
            "node": "Read Requests (after call) (Data Table)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Read Requests (after call) (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Requests (after call) (Data Table)": {
      "main": [
        [
          {
            "node": "Collect Requests (after call)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Requests (after call) (Sheet)": {
      "main": [
        [
          {
            "node": "Collect Requests (after call)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is call completed (request)?": {
      "main": [
        [
          {
            "node": "Read Requests (after call): Data Table?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build Call Log Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect Requests (after call)": {
      "main": [
        [
          {
            "node": "Build Request from Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Request from Lead": {
      "main": [
        [
          {
            "node": "New request needed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Request: Data Table?": {
      "main": [
        [
          {
            "node": "Create Request (Data Table)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Request (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Request (Data Table)": {
      "main": [
        [
          {
            "node": "Create Request: mirror to Sheet?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Request: mirror to Sheet?": {
      "main": [
        [
          {
            "node": "Create Request (Sheet)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Request Filed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Request (Sheet)": {
      "main": [
        [
          {
            "node": "Request Filed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New request needed?": {
      "main": [
        [
          {
            "node": "Create Request: Data Table?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Request Filed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Request Filed": {
      "main": [
        [
          {
            "node": "Reply to Voicely",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Call Event: Data Table?": {
      "main": [
        [
          {
            "node": "Log Call Event (Data Table)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Call Event (Sheet)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Call Event (Data Table)": {
      "main": [
        [
          {
            "node": "Log Call Event: mirror to Sheet?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Call Event: mirror to Sheet?": {
      "main": [
        [
          {
            "node": "Log Call Event (Sheet)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Call Logged",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Call Event (Sheet)": {
      "main": [
        [
          {
            "node": "Call Logged",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Call Log Row": {
      "main": [
        [
          {
            "node": "Log Call Event: Data Table?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call Logged": {
      "main": [
        [
          {
            "node": "Reply to Voicely",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveDataSuccessExecution": "none",
    "saveDataErrorExecution": "none",
    "saveManualExecutions": false,
    "saveExecutionProgress": false
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
