{
  "name": "AI Agent Voice Booking Assistant v1.2",
  "nodes": [
    {
      "parameters": {
        "content": "## Qualification and Appointment Selection",
        "height": 400,
        "width": 1000,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        160,
        60
      ],
      "id": "d60dfbdb-173a-4b4b-bec1-c64820903704",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "2e8a53f8-8b2c-4359-b901-00cc8b4e79b9",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        200,
        120
      ],
      "id": "2470e813-da20-4692-b9a9-abda381ddb51",
      "name": "Webhook",
      "webhookId": "2e8a53f8-8b2c-4359-b901-00cc8b4e79b9"
    },
    {
      "parameters": {
        "respondWith": "allIncomingItems",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        960,
        120
      ],
      "id": "aa232cdb-d113-4b79-8704-d204eabdc5b9",
      "name": "Respond to Webhook"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "Find the next available time slot for the user",
        "options": {
          "systemMessage": "=#Identity\nYou're an assistant that finds available times to book appointments.\n\n#Find Available Times Flow\n\nStep 1: Save Lead Information\nSave the following to \"Lead_Capture Supabase\":\nname={{ $json.body.Name }}\nphoneNumber={{ $json.body.PhoneNumber }}\nsummary={{ $json.body.Summary }}\neventName={{ $json.body.EventName }}\neventID={{ $json.body.EventID }}\n\nStep 2: Get Available Time Slots\nUse the \"Get Availability\" tool with these parameters:\n- Event ID: Use the specific Event ID for their selected service\n- Start Time: Current time ({{$now}})\n- End Time: 30 days from now\n- Format: ISO 8601 with UTC (e.g., 2025-05-28T00:00:00Z)\n\nIMPORTANT: Only return the first 5 available slots.\n\n#Critical Timezone Conversion Rules\n\nThe Get Availability tool returns UTC times (Z suffix). Conversion Rule:\n- Add # hours to any UTC time (Z suffix) to get YOUR_YOUR_TIMEZONE time\n- Example: 11:00:00Z = ##:00 (#:00 PM YOUR_YOUR_TIMEZONE time)\n\nResponse Format:\nWhen presenting times to the user:\n- Use 12-hour format with AM/PM\n- Example: \"June 12 at 1:00 PM\"\n\n\nError Prevention:\n- NEVER present UTC times as YOUR_YOUR_TIMEZONE times\n- ALWAYS add the correct hour offset\n- DOUBLE-CHECK your timezone math before responding\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        520,
        120
      ],
      "id": "dfc73ba5-ed49-492f-a1fe-27e3be28878b",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        220,
        300
      ],
      "id": "5011bc9e-858f-428f-9a59-5a88695b7abb",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "fLl92yEALYEzc0RK",
          "name": "OpenAi account 20"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Webhook').item.json.body.PhoneNumber }}",
        "contextWindowLength": 50
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        360,
        320
      ],
      "id": "3c5da161-c915-4c02-8098-978dab2377ca",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "tableId": "Appointment Voice Agent",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "Phone Number",
              "fieldValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('fieldValues0_Field_Value', `the phone number of the user`, 'string') }}"
            },
            {
              "fieldId": "Name",
              "fieldValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('fieldValues1_Field_Value', `The name of the user`, 'string') }}"
            },
            {
              "fieldId": "Summary",
              "fieldValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('fieldValues2_Field_Value', ``, 'string') }}"
            },
            {
              "fieldId": "Event Name",
              "fieldValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('fieldValues3_Field_Value', `the name of the event/service the user wants`, 'string') }}"
            },
            {
              "fieldId": "Event ID",
              "fieldValue": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('fieldValues4_Field_Value', `the ID of the event/service the user wants`, 'string') }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabaseTool",
      "typeVersion": 1,
      "position": [
        520,
        320
      ],
      "id": "abc35552-0b88-45d9-9901-cd2f309943e1",
      "name": "Capture_Leads",
      "credentials": {
        "supabaseApi": {
          "id": "K67ZXJpEE6daCIrN",
          "name": "Supabase account 5"
        }
      }
    },
    {
      "parameters": {
        "operation": "getAll",
        "tableId": "Appointment Voice Agent",
        "returnAll": true
      },
      "type": "n8n-nodes-base.supabaseTool",
      "typeVersion": 1,
      "position": [
        660,
        320
      ],
      "id": "6108ed86-a920-449b-b8e9-acdb7fa4dd6e",
      "name": "Read_Leads",
      "credentials": {
        "supabaseApi": {
          "id": "K67ZXJpEE6daCIrN",
          "name": "Supabase account 5"
        }
      }
    },
    {
      "parameters": {
        "toolDescription": "Call this tool to get the appointment availability. Must use Berlin/Germany timezone. Strictly use ISO format for dates eg. \"2025-01-01T09:00:00-02:00\". Input schema example: ```{ \"startTime\": \"...\", \"endTime\": \"...\"}```\n",
        "url": "https://api.cal.com/v2/slots/available",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "eventTypeId",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters0_Value', `The event ID of the massage that the client booked.`, 'string') }}"
            },
            {
              "name": "startTime",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters1_Value', `start of date range in ISO format. eg. 2025-01-01T09:00:00-00:00\n`, 'string') }}"
            },
            {
              "name": "endTime",
              "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('parameters2_Value', `end of date range in ISO format. eg. 2025-01-01T09:00:00-00:00`, 'string') }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_API_KEY"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequestTool",
      "typeVersion": 4.2,
      "position": [
        820,
        320
      ],
      "id": "47662404-50c2-44bd-961e-6a667f66672f",
      "name": "Get Availability"
    },
    {
      "parameters": {
        "content": "## Create Booking",
        "height": 280,
        "width": 1320,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        -280
      ],
      "id": "fa5bc7b0-44b4-4154-8fac-726733c91ca7",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "operation": "getAll",
        "tableId": "Appointment Voice Agent",
        "returnAll": true,
        "matchType": "allFilters",
        "filters": {
          "conditions": [
            {
              "keyName": "Phone Number",
              "condition": "eq",
              "keyValue": "={{ $json.body.PhoneNumber }}"
            },
            {
              "keyName": "Booked",
              "condition": "is",
              "keyValue": "null"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        220,
        -200
      ],
      "id": "1f50c055-7645-424c-b42e-9437626e4d59",
      "name": "Get Contact",
      "credentials": {
        "supabaseApi": {
          "id": "K67ZXJpEE6daCIrN",
          "name": "Supabase account 5"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.cal.com/v2/bookings",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_API_KEY"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "cal-api-version",
              "value": "2024-08-13"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"eventTypeId\":{{ $json['Event ID'] }},\n   \"start\": \"{{ $('Webhook1').item.json.body.BookingTime }}\",\n  \"attendee\": {\n     \"name\": \"{{ $json.Name }}\",\n     \"phoneNumber\": \"{{ $json['Phone Number'] }}\",\n\"email\": \"YOUR_YOUR_EMAIL\",\n     \"timeZone\": \"YOUR_YOUR_TIMEZONE\"\n  },\n  \"bookingFieldsResponses\": {\n    \"title\": \"{{ $json.Summary }}\"\n  }\n}\n",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        420,
        -200
      ],
      "id": "70702766-24ad-4bee-9d14-5ed234b33179",
      "name": "Create Booking"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list",
          "cachedResultName": "GPT-4O"
        },
        "messages": {
          "values": [
            {
              "content": "=Convert this UTC datetime {{ $json.data.start }} into local time in Europe/Berlin and return only the result in the format YYYY-MM-DD HH:mm:ss.\n\nOnly return the converted time.\n"
            }
          ]
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        560,
        -200
      ],
      "id": "a267ec5d-6416-4124-a027-eaf313e6dc70",
      "name": "Convert Time",
      "credentials": {
        "openAiApi": {
          "id": "fLl92yEALYEzc0RK",
          "name": "OpenAi account 20"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "tableId": "Appointment Voice Agent",
        "filters": {
          "conditions": [
            {
              "keyName": "id",
              "condition": "eq",
              "keyValue": "={{ $('Get Contact').item.json.id }}"
            }
          ]
        },
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "Appointment Date",
              "fieldValue": "={{ $json.message.content }}"
            },
            {
              "fieldId": "Booked",
              "fieldValue": "yes"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        900,
        -200
      ],
      "id": "2a40d405-35c2-47ee-a4a5-c1d9fc843231",
      "name": "Save Info",
      "credentials": {
        "supabaseApi": {
          "id": "K67ZXJpEE6daCIrN",
          "name": "Supabase account 5"
        }
      }
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "6c2c3f51-6b43-4876-b845-0dfa460f15fd",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        40,
        -200
      ],
      "id": "91b21991-a50d-492e-9453-430b00ea89e5",
      "name": "Webhook1",
      "webhookId": "6c2c3f51-6b43-4876-b845-0dfa460f15fd"
    },
    {
      "parameters": {
        "respondWith": "allIncomingItems",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        1100,
        -200
      ],
      "id": "b863493e-935e-4815-9edf-632e21e11e7e",
      "name": "Respond to Webhook1"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Capture_Leads": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Read_Leads": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Availability": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Contact": {
      "main": [
        [
          {
            "node": "Create Booking",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Booking": {
      "main": [
        [
          {
            "node": "Convert Time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Time": {
      "main": [
        [
          {
            "node": "Save Info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Info": {
      "main": [
        [
          {
            "node": "Respond to Webhook1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook1": {
      "main": [
        [
          {
            "node": "Get Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d23044f6-c7a2-486d-a4f5-0bf484533228",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "7ff6625f0127f3e9a7865e3493009de1c48f57dc5ed87def3ae3316be7f6b238"
  },
  "id": "zdZOI0jEtqihteNT",
  "tags": []
}