{
  "name": "AI Receptionist: Post-Call Pipeline (Demo)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "ai-receptionist-call-ended",
        "options": {}
      },
      "id": "4f72eca6-8867-4cee-a6da-11c4da9050cd",
      "name": "Call Ended (Vapi / Retell)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.2,
      "position": [
        -16,
        224
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 1
          },
          "conditions": [
            {
              "leftValue": "={{ $json.body?.message?.type ?? \"\" }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "rightValue": "end-of-call-report"
            },
            {
              "leftValue": "={{ $json.body?.event ?? \"\" }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "rightValue": "call_analyzed"
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "id": "af8cbc79-c8eb-4ead-81ab-02488a598ade",
      "name": "Is Final Call Report?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        272,
        320
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "dc1",
              "name": "business_name",
              "value": "Summit Comfort HVAC",
              "type": "string"
            },
            {
              "id": "dc2",
              "name": "trade",
              "value": "HVAC",
              "type": "string"
            },
            {
              "id": "dc3",
              "name": "city",
              "value": "Denver, CO",
              "type": "string"
            },
            {
              "id": "dc4",
              "name": "timezone",
              "value": "America/Denver",
              "type": "string"
            },
            {
              "id": "dc5",
              "name": "owner_name",
              "value": "Mike",
              "type": "string"
            },
            {
              "id": "dc6",
              "name": "owner_email",
              "value": "owner@example.com",
              "type": "string"
            },
            {
              "id": "dc7",
              "name": "twilio_from",
              "value": "+15550000001",
              "type": "string"
            },
            {
              "id": "dc8",
              "name": "job_length_minutes",
              "value": 90,
              "type": "number"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "50a2613f-54dc-4ca8-ba59-83845b6ffd1a",
      "name": "DEMO CLIENT",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        496,
        320
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c1",
              "name": "platform",
              "value": "={{ $json.body?.message ? \"vapi\" : \"retell\" }}",
              "type": "string"
            },
            {
              "id": "c2",
              "name": "call_id",
              "value": "={{ $json.body?.message?.call?.id ?? $json.body?.call?.call_id ?? $execution.id }}",
              "type": "string"
            },
            {
              "id": "c3",
              "name": "caller_phone",
              "value": "={{ $json.body?.message?.call?.customer?.number ?? $json.body?.message?.customer?.number ?? $json.body?.call?.from_number ?? \"\" }}",
              "type": "string"
            },
            {
              "id": "c4",
              "name": "transcript",
              "value": "={{ $json.body?.message?.artifact?.transcript ?? $json.body?.message?.transcript ?? $json.body?.call?.transcript ?? \"\" }}",
              "type": "string"
            },
            {
              "id": "c5",
              "name": "recording_url",
              "value": "={{ $json.body?.message?.artifact?.recordingUrl ?? $json.body?.message?.recordingUrl ?? $json.body?.call?.recording_url ?? \"\" }}",
              "type": "string"
            },
            {
              "id": "c6",
              "name": "duration_seconds",
              "value": "={{ Math.round($json.body?.message?.durationSeconds ?? (($json.body?.call?.duration_ms ?? 0) / 1000)) }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "a47793d6-7e26-4e96-b588-6e95b59ae0cc",
      "name": "Normalize Call",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        720,
        320
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "s1",
              "name": "call_id",
              "value": "={{ $(\"Normalize Call\").item.json.call_id }}",
              "type": "string"
            },
            {
              "id": "s2",
              "name": "platform",
              "value": "={{ $(\"Normalize Call\").item.json.platform }}",
              "type": "string"
            },
            {
              "id": "s3",
              "name": "caller_phone",
              "value": "={{ $(\"Normalize Call\").item.json.caller_phone }}",
              "type": "string"
            },
            {
              "id": "s4",
              "name": "transcript",
              "value": "={{ $(\"Normalize Call\").item.json.transcript }}",
              "type": "string"
            },
            {
              "id": "s5",
              "name": "recording_url",
              "value": "={{ $(\"Normalize Call\").item.json.recording_url }}",
              "type": "string"
            },
            {
              "id": "s6",
              "name": "duration_seconds",
              "value": "={{ $(\"Normalize Call\").item.json.duration_seconds }}",
              "type": "number"
            },
            {
              "id": "s7",
              "name": "caller_name",
              "value": "={{ $json.output.caller_name || \"Unknown\" }}",
              "type": "string"
            },
            {
              "id": "s8",
              "name": "service",
              "value": "={{ $json.output.service || \"General enquiry\" }}",
              "type": "string"
            },
            {
              "id": "s9",
              "name": "issue",
              "value": "={{ $json.output.issue || \"\" }}",
              "type": "string"
            },
            {
              "id": "s10",
              "name": "address",
              "value": "={{ $json.output.address || \"\" }}",
              "type": "string"
            },
            {
              "id": "s11",
              "name": "urgency",
              "value": "={{ Math.min(5, Math.max(1, Number($json.output.urgency) || 1)) }}",
              "type": "number"
            },
            {
              "id": "s12",
              "name": "summary",
              "value": "={{ $json.output.summary || \"\" }}",
              "type": "string"
            },
            {
              "id": "s13",
              "name": "callback_needed",
              "value": "={{ $json.output.callback_needed === true }}",
              "type": "boolean"
            },
            {
              "id": "s14",
              "name": "booking_start",
              "value": "={{ $json.output.preferred_start || \"\" }}",
              "type": "string"
            },
            {
              "id": "s15",
              "name": "valid_booking",
              "value": "={{ $json.output.wants_booking === true && !!$json.output.preferred_start && DateTime.fromISO($json.output.preferred_start).isValid && DateTime.fromISO($json.output.preferred_start) > $now }}",
              "type": "boolean"
            },
            {
              "id": "s16",
              "name": "booking_display",
              "value": "={{ $json.output.preferred_start && DateTime.fromISO($json.output.preferred_start).isValid ? DateTime.fromISO($json.output.preferred_start).setZone($(\"DEMO CLIENT\").item.json.timezone).toFormat(\"ccc d LLL, h:mm a\") : \"\" }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "d2a03893-65e6-414f-85c9-6c0a00dda0ad",
      "name": "Shape Call Result",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1152,
        320
      ]
    },
    {
      "parameters": {
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_DATA_TABLE_ID",
          "cachedResultName": "receptionist_calls"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "business_name": "={{ $(\"DEMO CLIENT\").item.json.business_name }}",
            "call_id": "={{ $json.call_id }}",
            "platform": "={{ $json.platform }}",
            "caller_name": "={{ $json.caller_name }}",
            "caller_phone": "={{ $json.caller_phone }}",
            "service": "={{ $json.service }}",
            "address": "={{ $json.address }}",
            "urgency": "={{ $json.urgency }}",
            "summary": "={{ $json.summary }}",
            "wants_booking": "={{ $json.valid_booking }}",
            "booked_start": "={{ $json.valid_booking ? $json.booking_start : null }}",
            "recording_url": "={{ $json.recording_url }}",
            "duration_seconds": "={{ $json.duration_seconds }}",
            "transcript": "={{ $json.transcript }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "business_name",
              "displayName": "business_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "call_id",
              "displayName": "call_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "platform",
              "displayName": "platform",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "caller_name",
              "displayName": "caller_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "caller_phone",
              "displayName": "caller_phone",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "service",
              "displayName": "service",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "address",
              "displayName": "address",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "urgency",
              "displayName": "urgency",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "summary",
              "displayName": "summary",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "wants_booking",
              "displayName": "wants_booking",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "boolean",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "booked_start",
              "displayName": "booked_start",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "calendar_link",
              "displayName": "calendar_link",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "recording_url",
              "displayName": "recording_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "duration_seconds",
              "displayName": "duration_seconds",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "transcript",
              "displayName": "transcript",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "698bc40e-9690-42a8-bf3b-0007e4ea4fad",
      "name": "Log Call",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1328,
        128
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $(\"DEMO CLIENT\").item.json.owner_email }}",
        "subject": "={{ $json.urgency >= 4 ? \"🔴 URGENT \" : \"\" }}{{ $json.valid_booking ? \"Booked: \" : \"New call: \" }}{{ $json.service }} for {{ $json.caller_name }}{{ $json.valid_booking ? \" (\" + $json.booking_display + \")\" : \"\" }}",
        "message": "=<p><b>{{ $json.summary }}</b></p><p>Urgency: {{ \"●\".repeat($json.urgency) }}{{ \"○\".repeat(5 - $json.urgency) }} ({{ $json.urgency }}/5)<br>Caller: {{ $json.caller_name }}<br>Phone: <a href=\"tel:{{ $json.caller_phone }}\">{{ $json.caller_phone || \"unknown\" }}</a><br>Service: {{ $json.service }}<br>Address: {{ $json.address || \"not given\" }}<br>{{ $json.valid_booking ? \"Booked for: <b>\" + $json.booking_display + \"</b> (added to the calendar, caller texted a confirmation)\" : \"Not booked.\" }}{{ $json.callback_needed ? \"<br><b>Caller asked for a call back.</b>\" : \"\" }}</p><p><a href=\"tel:{{ $json.caller_phone }}\">Call them back</a>{{ $json.recording_url ? \" · <a href=\\\"\" + $json.recording_url + \"\\\">Listen to the call</a>\" : \"\" }} · {{ Math.round($json.duration_seconds / 60 * 10) / 10 }} min call</p>",
        "options": {
          "appendAttribution": false,
          "senderName": "AI Receptionist"
        }
      },
      "id": "076399e8-fa5a-43ef-b37a-38a88fbce90d",
      "name": "Send Owner Call Summary",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        1440,
        192
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 1
          },
          "conditions": [
            {
              "leftValue": "={{ $json.valid_booking }}",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "8378e4f0-ce29-4091-b152-379101c97259",
      "name": "Booking Agreed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1328,
        512
      ]
    },
    {
      "parameters": {
        "calendar": {
          "__rl": true,
          "value": "primary",
          "mode": "list",
          "cachedResultName": "primary"
        },
        "start": "={{ $json.booking_start }}",
        "end": "={{ DateTime.fromISO($json.booking_start).plus({ minutes: $(\"DEMO CLIENT\").item.json.job_length_minutes }).toISO() }}",
        "additionalFields": {
          "description": "={{ $json.summary }}\n\nPhone: {{ $json.caller_phone }}\nIssue: {{ $json.issue }}\nBooked by the AI receptionist (call {{ $json.call_id }}).",
          "location": "={{ $json.address }}",
          "summary": "={{ $json.urgency >= 4 ? \"🔴 \" : \"\" }}{{ $json.service }}: {{ $json.caller_name }}"
        }
      },
      "id": "478ae0cf-5551-4269-a7c9-716426976ba3",
      "name": "Add Job to Calendar",
      "type": "n8n-nodes-base.googleCalendar",
      "typeVersion": 1.4,
      "position": [
        1552,
        512
      ]
    },
    {
      "parameters": {
        "from": "={{ $(\"DEMO CLIENT\").item.json.twilio_from }}",
        "to": "={{ $(\"Shape Call Result\").item.json.caller_phone }}",
        "message": "=Hi {{ $(\"Shape Call Result\").item.json.caller_name.split(\" \")[0] }}, you are booked with {{ $(\"DEMO CLIENT\").item.json.business_name }} for {{ $(\"Shape Call Result\").item.json.service }} on {{ $(\"Shape Call Result\").item.json.booking_display }}. Reply C to confirm or R to reschedule. - {{ $(\"DEMO CLIENT\").item.json.owner_name }}",
        "options": {}
      },
      "id": "bd68da3f-2ba6-4d18-887c-e12be6d7b509",
      "name": "Text Caller Confirmation",
      "type": "n8n-nodes-base.twilio",
      "typeVersion": 1,
      "position": [
        1776,
        512
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_DATA_TABLE_ID",
          "cachedResultName": "receptionist_calls"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "call_id",
              "keyValue": "={{ $(\"Shape Call Result\").item.json.call_id }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "calendar_link": "={{ $(\"Add Job to Calendar\").item.json.htmlLink }}"
          },
          "schema": [
            {
              "id": "calendar_link",
              "displayName": "calendar_link",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "36a03f76-79e1-46ca-9b22-c759fb729c71",
      "name": "Save Calendar Link",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        2000,
        512
      ]
    },
    {
      "parameters": {
        "content": "## AI receptionist: post-call pipeline\n\n**When a call ends, the owner gets a 5-second summary with an urgency score, booked jobs go into Google Calendar, the caller gets a text confirmation, and every call is logged.**\n\n**Connect a voice agent:** in Vapi, set the assistant Server URL to the **Call Ended** webhook production URL (Server Messages: end-of-call-report). Retell works too: set the agent webhook to the same URL.\n\n**Before a Loom:** edit only **DEMO CLIENT** (name, city, time zone) and the voice agent prompt.\n\n**Twilio:** add the trial credential to **Text Caller Confirmation** and put the number in `twilio_from`.\n\nCalls are logged in the **receptionist_calls** data table.",
        "height": 400,
        "width": 952,
        "color": 4
      },
      "id": "5a08389e-63a4-4fba-bfdb-1d8227eb5487",
      "name": "Sticky Note 1382a449",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        96,
        656
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://openrouter.ai/api/v1/chat/completions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openRouterApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'deepseek/deepseek-v4-flash', temperature: 0.1, max_tokens: 800, reasoning: { effort: 'none' }, response_format: { type: 'json_object' }, messages: [ { role: 'system', content: 'You read phone call transcripts for ' + $('DEMO CLIENT').item.json.business_name + ', a ' + $('DEMO CLIENT').item.json.trade + ' company in ' + $('DEMO CLIENT').item.json.city + '.\\nCurrent date and time: ' + $now.setZone($('DEMO CLIENT').item.json.timezone).toFormat('cccc d LLLL yyyy, HH:mm ZZ') + ' (' + $('DEMO CLIENT').item.json.timezone + ').\\n\\nReturn ONLY a JSON object with exactly these keys:\\n- caller_name: as said on the call, or \"Unknown\".\\n- service: short label, e.g. \"Furnace repair\", \"AC repair\", \"New system quote\".\\n- issue: one sentence in plain words.\\n- address: as given, or \"\".\\n- urgency: integer 1 to 5. 5 = no heat or no cooling in extreme weather, gas smell, water leak, vulnerable people at home. 3 = broken but bearable. 1 = general question or quote.\\n- wants_booking: true only if the caller agreed to a specific visit time.\\n- preferred_start: that agreed time as ISO 8601 with the business time zone offset, resolved against the current date above, or \"\" if none.\\n- callback_needed: true if the caller asked for a person to call back or the assistant could not help.\\n- summary: max 3 short sentences an owner can read in 5 seconds. Include access notes like gate codes.' }, { role: 'user', content: 'Transcript:\\n' + $json.transcript } ] }) }}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "1d754149-9090-48cd-b880-1b8f9473bd1c",
      "name": "Extract Call Details",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.5,
      "position": [
        880,
        192
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "p1",
              "name": "output",
              "value": "={{ JSON.parse((($json.choices && $json.choices[0] && $json.choices[0].message && $json.choices[0].message.content) || '{}').replace(/^```(?:json)?\\s*/i, '').replace(/\\s*```$/, '').trim()) }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "id": "0fb05947-de2f-4392-b1d1-d1a7232e3d80",
      "name": "Parse Call Details",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1104,
        192
      ]
    }
  ],
  "connections": {
    "Call Ended (Vapi / Retell)": {
      "main": [
        [
          {
            "node": "Is Final Call Report?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Final Call Report?": {
      "main": [
        [
          {
            "node": "DEMO CLIENT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DEMO CLIENT": {
      "main": [
        [
          {
            "node": "Normalize Call",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shape Call Result": {
      "main": [
        [
          {
            "node": "Log Call",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Owner Call Summary",
            "type": "main",
            "index": 0
          },
          {
            "node": "Booking Agreed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Booking Agreed?": {
      "main": [
        [
          {
            "node": "Add Job to Calendar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Job to Calendar": {
      "main": [
        [
          {
            "node": "Text Caller Confirmation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Caller Confirmation": {
      "main": [
        [
          {
            "node": "Save Calendar Link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Call": {
      "main": [
        [
          {
            "node": "Extract Call Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Call Details": {
      "main": [
        [
          {
            "node": "Parse Call Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Call Details": {
      "main": [
        [
          {
            "node": "Shape Call Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": true
  },
  "pinData": {}
}
