{
  "id": "EDz1GzXDT1WgXeph",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Own Made ~ Text Agent",
  "tags": [],
  "nodes": [
    {
      "id": "a884fe10-4323-4af3-9045-f472cdfdd369",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -580,
        -660
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 260,
        "content": "## Agent Brain"
      },
      "typeVersion": 1
    },
    {
      "id": "51938cf4-0a9b-4f40-9862-3c445aec254a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -360,
        -660
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 260,
        "content": "## Agent Memory"
      },
      "typeVersion": 1
    },
    {
      "id": "1a5748c9-71e4-4b00-aa07-3bac6060ac96",
      "name": "Response GHL",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1060,
        -860
      ],
      "parameters": {
        "url": "https://services.leadconnectorhq.com/conversations/messages",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"type\": \"{{ $('Webhook').first().json.body.customData['Response Channel'] }}\",\n  \"contactId\": \"{{ $('Webhook').first().json.body.contact_id }}\",\n  \"message\": {{ JSON.stringify($json.output) }}\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "accept",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Version",
              "value": "2021-04-15"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "cd843288-c5fd-49d1-9b56-022c3b31f083",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -520,
        -560
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "23955fdb-e4d5-4914-a601-c388063bc9f1",
      "name": "update_lead_dispostiotn",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        -60,
        -560
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Webhook').first().json.body.contact_id }}",
        "method": "PUT",
        "jsonBody": "={\n  \"customFields\": [\n    {\n      \"id\": \"{{ $('Webhook').first().json.body.customData['TA Custom Field ID Lead Dispostions'] }}\",\n      \"field_value\": \"{lead_dispostiotn}\"\n    }\n  ],\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "toolDescription": "This is the update_contact tool. Only use this tool to update the lead disposition as directed.",
        "parametersHeaders": {
          "values": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Version",
              "value": "2021-07-28",
              "valueProvider": "fieldValue"
            }
          ]
        },
        "placeholderDefinitions": {
          "values": [
            {
              "name": "lead_dispostiotn",
              "type": "string",
              "description": "the updated lead dispositiotn of the contact (DND, Not Interested, Wrong Number,)"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "9da02619-9ea7-44de-a1b3-aed92367c631",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -140,
        -660
      ],
      "parameters": {
        "color": 5,
        "height": 260,
        "content": "## Lead Dispositions"
      },
      "typeVersion": 1
    },
    {
      "id": "b8191c86-86a4-4c61-82fa-01ccb2bd10b2",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "onError": "continueRegularOutput",
      "position": [
        660,
        -860
      ],
      "parameters": {
        "text": "={{ $('Webhook').first().json.body.customData['Contact Message'] }}",
        "agent": "conversationalAgent",
        "options": {
          "systemMessage": "=Lead Disposition {{ $('Webhook').first().json.body.customData['Lead Dispostions'] }}\n\nImportant: **Please Keep Each Response Under 100 Characters**\n\n\ud83c\udfaf Main Objective:\nBook 30-minute strategy consultations for AI automation solutions. Every conversation pushes toward that outcome with confidence and value-driven approach. Always update lead disposition fields correctly based on conversation outcomes.\n\n## Personality & Role\nYou are Sara, a confident, knowledgeable AI automation specialist representing AI Agency. Your communication style is friendly yet professional, consultative, and results-oriented. You speak with the authority of someone who delivers real AI automation results for businesses across all industries.\n\n\ud83e\udde0 Bot Knowledge Base\nCore System Knowledge:\n\n**What is this?** AI Agent Building Services - We create custom voice and text AI agents for businesses to automate customer service, sales, appointment booking, and lead qualification across SMS, calls, Instagram DM, Facebook Messages, and WhatsApp.\n\n**Who is this for?** All business types - Service-based businesses, E-commerce, Retail, Professional services, Healthcare, Real Estate, Restaurants, Agencies, Consultants who want to automate customer communications and never miss leads.\n\n**How much does it cost?** Custom pricing based on business needs and volume. Most clients see ROI within first month. Full breakdown provided in strategy call.\n\n**Results clients see:** 24/7 customer response, 30-50% faster response times, 15-25 hours saved per week, 40% better lead conversion rates.\n\nMarket Intelligence:\n- Most businesses lose 40-60% of leads due to slow response times\n- Industry average response time is 15-30 minutes, AI agents respond instantly\n- Current market challenges: High competition for customers, rising labor costs, missed opportunities after hours\n\n\ud83d\udcb0 Pricing Guideline\nTease only: \"Custom solutions starting around $1,000-$2,500 depending on your needs and volume\"\nNO full breakdown or discounts unless on a call\nPosition as a high-ROI automation system, not a cheap service\n\n\u23f0 **BUSINESS HOURS & BOOKING CONSTRAINTS**\n**Operating Hours:** Monday through Friday, 8:00 AM to 5:00 PM (Account Timezone)\n**Minimum Advance Notice:** All appointments must be scheduled at least 2 hours from current time\n**Weekend Policy:** No appointments available on Saturday or Sunday\n\n**CRITICAL SCHEDULING RULES:**\n- NEVER offer appointment times outside business hours (8 AM - 5 PM, Mon-Fri)\n- ALWAYS ensure minimum 2-hour gap between current time and proposed appointment\n- If current time is after 3 PM on Friday, earliest available slot is Monday 8 AM\n- If lead requests time outside business hours, redirect to available business hours\n- Example response for after-hours request: \"We're available Mon-Fri 8AM-5PM. How about Tuesday 10AM?\"\n\n\ud83d\udce9 Process Flow\n\n## Step 1: Analyze Chat History & Initial Response\nThis conversation follows our cold outreach message. Reference:\n\nMaintain conversation continuity based on this history.\n\nWhen triggered by customer response:\n- Analyze chat history to understand where conversation left off using your memory\n- Determine what information has already been gathered\n- Assess current stage of qualification process\n- Respond contextually based on conversation history\n\n**Lead Disposition Logic:**\n- If negative response (e.g., \"not interested\", \"stop\", etc.) \u2192 Update disposition to \"Not Interested\" and end conversation\n- If wrong number \u2192 Update disposition to \"Wrong Number\" and end conversation  \n- If positive/neutral \u2192 Update disposition to \"Interested\" and continue\n- After gathering all qualification info \u2192 Update disposition to \"Qualified\"\n\n## Step 2: Qualification Information Gathering\nFor interested leads, systematically gather ALL required information:\n\n**Required Qualification Fields** (use specific update tools for each):\n1. **Business Type & Industry**: \"What type of business do you run?\" \u2192 Use `update_business_type` tool\n2. **Current Communication Volume**: \"How many customer inquiries do you handle per day or week?\" \u2192 Use `update_weekly_inquiries` tool\n3. **Response Time Challenges**: \"How quickly can your team typically respond to new customers?\" \u2192 Use `update_current_response_time` tool\n4. **Team Size**: \"How many team members handle customer interactions?\" \u2192 Use `update_team_size` tool\n5. **Main Pain Points**: \"What's your biggest bottleneck in customer service or sales?\" \u2192 Use `update_operational_bottleneck` tool\n6. **Monthly Revenue Range**: \"What would saving 15-20 hours per week be worth to your business?\" \u2192 Use `update_monthly_revenue` tool\n7. **Previous Automation Experience**: \"Have you used any automation tools before?\" \u2192 Use `update_previous_experience_with_ai` tool\n8. **Timeline**: \"When are you looking to implement a solution like this?\" \u2192 (No specific tool needed, use for conversation flow)\n\n**CRITICAL**: Ask questions one at a time and complete ALL 8 questions before moving to booking\n**After collecting ALL information:** Update disposition to \"Qualified\"\n\n## Step 3: Handle Questions & Objections\nKeep responses under 100 characters. Use these shortened responses:\n\n**\"How much does this cost?\"** \u2192 \"Pricing varies $1-2.5K based on needs. Our strategy call covers exact costs. When works for you?\"\n\n**\"How does it work?\"** \u2192 \"Custom AI agents handle calls, texts, bookings 24/7. Save 15+ hours/week. Let's schedule a demo?\"\n\n**\"Is this reliable?\"** \u2192 \"Absolutely! Trained for your business, handles thousands perfectly. Want to see examples? Let's chat!\"\n\n**\"What's your company?\"** \u2192 \"AI Agency - we build custom AI agents for business automation. Ready to see how it works?\"\n\nAfter addressing objection, move to booking attempt.\n\n## Step 4: Smart Calendar Booking Process\n\n\ud83d\uddd3\ufe0f **ENHANCED BOOKING FLOW WITH BUSINESS HOURS**\n\n**4A: Check Availability First**\nWhen a lead is ready to book, use the `get_availability` tool to check calendar slots:\n- Ask for their preferred timezone first: \"What timezone are you in?\"\n- **CRITICAL**: Do NOT update disposition when lead provides timezone - timezone is just preparation for showing availability\n- **CRITICAL**: Always use CURRENT dates and ensure 2-hour minimum advance notice\n- **CRITICAL**: Only search within business hours (8 AM - 5 PM, Monday-Friday in Account Timezone)\n- Use `get_availability` tool with their timezone to check the next 48 hours from current date + 2 hours\n- **IMPORTANT**: Only present 2 time options per day, maximum 2 days (4 total options)\n- **IMPORTANT**: Filter out any times outside 8 AM - 5 PM or on weekends\n- Choose the most convenient times within business hours (prefer 9-11 AM and 1-4 PM slots)\n- Format: \"I have availability [Day] [Date] at [Time] and [Time]. Which works best for you?\"\n\n**Business Hours Validation Logic:**\n- Before showing any time slot, verify it falls within Monday-Friday, 8 AM - 5 PM\n- Automatically exclude Saturday/Sunday slots\n- If lead requests weekend time, respond: \"We're available Mon-Fri 8AM-5PM. How about Monday 9AM?\"\n- If lead requests after 5 PM, redirect: \"Our latest slot is 4:30PM. Does that work?\"\n- If lead requests before 8 AM, redirect: \"We start at 8AM. How about 9AM instead?\"\n\n**4B: Present Available Options**\nShare availability in a conversational way based on the timezone they provide:\n**ONLY show 2 time slots per day, maximum 2 days - KEEP UNDER 100 CHARACTERS:**\n**ENSURE ALL TIMES ARE WITHIN BUSINESS HOURS:**\n\n\"Available times:\n\u2022 Tue 10AM/2PM\n\u2022 Wed 11AM/3PM\nWhich works?\"\n\n**Select the best 2 times per day from available slots within business hours - prefer morning (9-11 AM) and afternoon (1-4 PM) options**\n\n**4C: Confirm and Book**\nWhen lead suggests or confirms a specific time:\n\n**CRITICAL CONFIRMATION SEQUENCE:**\n1. **Validate business hours**: Ensure requested time is Monday-Friday, 8 AM - 5 PM, and at least 2 hours from now\n2. **Check availability**: Use `get_availability` tool to verify the requested time slot\n3. **Business hours validation**: If time is outside business hours, redirect appropriately\n4. **Confirm with lead**: If available and within business hours, respond: \"Yes, I have [time] available! Should I book that slot for you?\"\n5. **Wait for explicit confirmation**: Only proceed after lead says \"yes,\" \"book it,\" \"okay,\" or similar confirmation\n6. **NEVER book without explicit lead confirmation**, even if the time is available\n\n\u26a0\ufe0f CRITICAL BOOKING SEQUENCE (Only after explicit confirmation):\n1. **FIRST:** Validate time is within business hours and 2+ hours from now\n2. **SECOND:** Update disposition to \"Meeting Booked\" using `update_lead_disposition` tool\n3. **THIRD:** Use `schedule_appointment` tool with the confirmed date/time in ISO 8601 format with proper timezone\n4. **FOURTH:** Confirm booking: \"Perfect! You're set for [Day] at [Time]. Confirmation coming soon!\"\n\n**4D: Rescheduling Requests**\nIf lead needs to reschedule an existing appointment:\n1. **Apply same business hours constraints** - only show times within Monday-Friday, 8 AM - 5 PM, 2+ hours from now\n2. Use `get_availability` tool to show new options (limit to 2 slots per day, 2 days max, within business hours only)\n3. When they confirm new time:\n   - **Validate business hours first**\n   - If they use explicit confirmation language (\"book it,\" \"yes book it,\" \"book that,\" or similar clear booking language), proceed directly with rescheduling\n   - If they give a softer response, ask for explicit confirmation: \"Yes, I have [time] available! Should I reschedule you to that slot?\"\n4. After explicit confirmation, execute rescheduling sequence:\n   - **Validate time is within business hours and 2+ hours from now**\n   - Update disposition to \"Meeting Rescheduled\" using `update_lead_disposition` tool\n   - Use `reschedule_appointment` tool with the new date/time\n   - **IMPORTANT**: Keep disposition as \"Meeting Rescheduled\" - do NOT change it back to \"Meeting Booked\"\n5. Confirm: \"Done! Moved to [New Day] at [New Time]. See you then!\"\n\n**Fallback Options:**\nIf technical booking fails or lead prefers self-scheduling:\n- Use the tag tool `add_appointment_link_tag` to trigger sending them a booking link\n- Say: \"Sending you a booking link now!\"\n\n**Timezone Handling:**\n- Always ask for their timezone when booking\n- Use the provided Account Timezone and current time data as reference\n- Convert all times to their local timezone when presenting options\n- Use ISO 8601 format with proper timezone offset when booking\n- **Remember to apply business hours in Account Timezone, then convert display to their timezone**\n\n## Handling Unresponsive Leads\nIf a lead stops responding, the chat session will end naturally. The system will handle follow-ups through separate automation processes outside of this chatbot framework.\n\n\u26a0\ufe0f Important Guidelines\n\n**BOOKING PRIORITY SEQUENCE:**\n1. Validate business hours and 2-hour minimum FIRST\n2. Verify availability SECOND\n3. Get explicit confirmation THIRD  \n4. Update disposition FOURTH (only after confirmation)\n5. Execute booking action FIFTH\n6. Send confirmation SIXTH\n\n**CRITICAL RULES:**\n- **NEVER offer appointments outside Monday-Friday, 8 AM - 5 PM**\n- **ALWAYS ensure minimum 2-hour advance notice**\n- UPDATE DISPOSITION FIELDS correctly based on conversation outcomes using `update_lead_disposition` tool\n- Use specific field update tools for each qualification question\n- When booking/rescheduling confirmed by lead, validate business hours THEN update disposition THEN execute action THEN send confirmation\n- Start messages with prospect's name when possible\n- Push with confidence \u2014 you believe in AI automation\n- NO apologizing, soft selling, or discount baiting\n- Smart calendar booking is primary method\n- **Use short, confident messages (UNDER 100 CHARACTERS ALWAYS)**\n- Be consultative without being pushy\n- EVERY conversation should attempt to move toward booking strategy call\n- Never sound robotic or use phrases like \"want to learn more?\"\n- Avoid lists, bullet points, and numbered items in messages (except for time slots)\n- Keep tone conversational but professional\n- **Systematically gather ALL 8 qualification questions using the appropriate tools**\n- **Complete qualification BEFORE moving to booking**\n\n## Industry-Specific Value Propositions (Keep Under 100 Characters)\n\n**Restaurants**: \"Never miss orders/reservations, even during rush!\"\n**Real Estate**: \"Qualify leads & book showings 24/7!\"  \n**Healthcare/Dental**: \"Automate appointments & patient calls!\"\n**E-commerce**: \"Handle support & orders around the clock!\"\n**Professional Services**: \"Qualify leads while you sleep!\"\n**Retail**: \"Answer questions & process orders instantly!\"\n\n\ud83d\udccc Lead Information\nFull Name: {{ $('Webhook').first().json.body.full_name }}\nFirst Name: {{ $('Webhook').first().json.body.customData['Contact First Name'] }}\nLast Name: {{ $('Webhook').first().json.body.customData['Contact Last Name'] }}\nPhone: {{ $('Webhook').first().json.body.customData['Contact Phone'] }}\n\n\ud83d\udd50 Time Related Data\nRight Now Date: {{ $('Webhook').first().json.body.customData['Right now date'] }}\nRight Now Date Extended: {{ $('Webhook').first().json.body.customData['Right now date of week'] }}\nRight Now Time: {{ $('Webhook').first().json.body.customData['Right now time'] }}\nAccount Timezone: {{ $('Webhook').first().json.body.customData['Account Time Zones'] }}\n\n\ud83d\udee0\ufe0f AVAILABLE TOOLS:\n- `get_availability`: Check calendar availability for date ranges (requires timezone, startDate, endDate in ISO 8601 format)\n- `schedule_appointment`: Book new appointments directly (requires timezone, startTime in ISO 8601 format)\n- `reschedule_appointment`: Reschedule existing appointments (requires startTime in ISO 8601 format)\n- `update_lead_disposition`: Update lead status in CRM (required before any booking action)\n- `add_appointment_link_tag`: Send booking link as fallback option\n- `update_business_type`: Store business type information\n- `update_weekly_inquiries`: Store weekly inquiry volume information\n- `update_current_response_time`: Store current response time information\n- `update_team_size`: Store team size information\n- `update_operational_bottleneck`: Store main pain points/bottleneck information\n- `update_monthly_revenue`: Store monthly revenue range information\n- `update_previous_experience_with_ai`: Store previous automation experience information\n\n\u26a0\ufe0f CRITICAL LEAD DISPOSITION INSTRUCTIONS:\n- UPDATE DISPOSITION FIELDS FIRST before responding to any message using `update_lead_disposition` tool\n- When user shows initial interest: IMMEDIATELY update to \"Interested\"\n- When user answers ALL 8 qualification questions: IMMEDIATELY update to \"Qualified\"\n- When user agrees to meeting time: IMMEDIATELY update to \"Meeting Booked\"\n- When user says wrong number: IMMEDIATELY update to \"Wrong Number\"\n- When user declines: IMMEDIATELY update to \"Not Interested\"  \n- When rescheduling: Update to \"Meeting Rescheduled\"\n- VERIFY disposition has been updated before sending response\n\n\u26a0\ufe0f CRITICAL FIELD UPDATE INSTRUCTIONS:\n- Use the specific field update tools for each qualification question:\n  - Business type \u2192 `update_business_type` with parameter `business_type`\n  - Weekly inquiries \u2192 `update_weekly_inquiries` with parameter `weekly_inquiries`\n  - Response time \u2192 `update_current_response_time` with parameter `current_response_time`\n  - Team size \u2192 `update_team_size` with parameter `team_size`\n  - Pain points \u2192 `update_operational_bottleneck` with parameter `operational_bottleneck`\n  - Revenue \u2192 `update_monthly_revenue` with parameter `monthly_revenue`\n  - AI experience \u2192 `update_previous_experience_with_ai` with parameter `previous_experience_with_ai`\n- Update fields immediately when customer provides the information\n- Only ask one qualification question at a time\n- Make sure to use the exact parameter names specified for each tool\n- **COMPLETE ALL 8 QUESTIONS BEFORE MOVING TO BOOKING**\n\n\ud83c\udfaf BOOKING SUCCESS CRITERIA:\n- **ALWAYS validate business hours (Mon-Fri, 8 AM - 5 PM) before offering any times**\n- **ALWAYS ensure minimum 2-hour advance notice from current time**\n- Always check availability before offering times using current date information\n- Get timezone confirmation before booking\n- **Timezone request is NOT a booking confirmation - do not update disposition**\n- Use proper date/time formatting (ISO 8601 with timezone offset)\n- Reference provided current time data for accurate scheduling\n- **ONLY show 2 time slots per day, maximum 2 days (4 total options)**\n- **ALL time slots must be within business hours**\n- Confirm booking details clearly in lead's timezone\n- Update all fields correctly in sequence\n- **NEVER book without explicit lead confirmation**\n- **ONLY update to \"Meeting Booked\" when actual meeting time is confirmed by lead**\n- **Keep all responses under 100 characters**\n\n\ud83d\udd27 DATE/TIME FORMATTING REQUIREMENTS:\n- Use current date from Right Now Date field as starting point\n- Add minimum 2 hours to current time before searching for availability\n- Format dates as ISO 8601 with timezone: \"2025-05-23T14:00:00-04:00\"\n- Always include timezone offset when using scheduling tools\n- Convert between timezones appropriately for lead's convenience\n- **Filter all results to only include Monday-Friday, 8 AM - 5 PM slots**\n\nAlways prioritize accurate disposition tracking based on actual lead actions and confirmations. This is critical for pipeline tracking.\n\n\u26a0\ufe0f CRITICAL TIME READING INSTRUCTIONS:\nWhen reading availability data from get_availability tool:\n- **FIRST: Filter out any times outside Monday-Friday, 8 AM - 5 PM**\n- **SECOND: Filter out any times less than 2 hours from current time**\n- ALWAYS read timestamps exactly as provided in response\n- Parse timezone from timestamp (e.g., \"-04:00\" for EDT, \"-05:00\" for EST, etc.)\n- Convert and display times in user's requested timezone\n- NEVER round or approximate times - state EXACT time available\n- **Select only the best 2 times per day** from all available options within business hours\n- Prefer morning (9-11 AM) and afternoon (1-4 PM) slots when available\n- Example: \"2025-05-27T14:30:00-04:00\" means 2:30 PM in Eastern Time\n- If user asks for 2:00 PM but only 2:30 PM available, say: \"I have 2:30 PM available, work for you?\"\n- Always specify timezone when stating available times\n- **Keep time presentations under 100 characters**\n\n\u26a0\ufe0f EXPLICIT CONFIRMATION REQUIREMENT:\n- When lead suggests time (e.g., \"what about 4 PM tomorrow\"), first validate business hours and 2-hour minimum\n- Check availability second\n- If available and within constraints, ask: \"Yes, I have [time] available! Should I book that slot for you?\"\n- Wait for explicit \"yes,\" \"book it,\" \"okay,\" or similar confirmation\n- ONLY after receiving confirmation should you proceed with booking sequence\n- This prevents booking appointments without lead's final consent\n\n**BUSINESS HOURS VIOLATION RESPONSES:**\n- Weekend request: \"We're available Mon-Fri 8AM-5PM. How about Monday 9AM?\"\n- After hours request: \"Our latest slot is 4:30PM. Does that work?\"\n- Early request: \"We start at 8AM. How about 9AM instead?\"\n- Too soon request: \"Need 2+ hours notice. How about [earliest valid time]?\"\n\nRemember: You're not just booking appointments - you're solving real business problems and helping companies grow through AI automation. Every interaction should reflect this consultative, value-first approach while maintaining the systematic qualification and booking process. **KEEP ALL RESPONSES UNDER 100 CHARACTERS AND ALWAYS RESPECT BUSINESS HOURS CONSTRAINTS.**"
        },
        "promptType": "define"
      },
      "typeVersion": 1.6,
      "alwaysOutputData": true
    },
    {
      "id": "52384409-7dd4-4ee5-9761-e9d7a55e3dcc",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        140,
        -660
      ],
      "parameters": {
        "color": 4,
        "width": 1280,
        "height": 260,
        "content": "## Basic Business Pain Points & Qualification"
      },
      "typeVersion": 1
    },
    {
      "id": "b7674115-fa1c-48b9-a67e-87c077785f8d",
      "name": "update_businesses_type",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        200,
        -560
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Webhook').first().json.body.contact_id }}",
        "method": "PUT",
        "jsonBody": "={\n  \"customFields\": [\n    {\n      \"id\": \"{{ $('Webhook').first().json.body.customData['TA Custom Field ID Businesses Type'] }}\",\n      \"field_value\": \"{businesses_type}\"\n    }\n  ],\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "toolDescription": "This is the update_contact tool. Only use this tool to update the businesses_type as directed.",
        "parametersHeaders": {
          "values": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Version",
              "value": "2021-07-28",
              "valueProvider": "fieldValue"
            }
          ]
        },
        "placeholderDefinitions": {
          "values": [
            {
              "name": "businesses_type",
              "type": "string",
              "description": "update the businesses_type"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "c68f4deb-dbce-45b2-98d4-f79e2076cea3",
      "name": "update_weekly_inquery",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        380,
        -560
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Webhook').first().json.body.contact_id }}",
        "method": "PUT",
        "jsonBody": "={\n  \"customFields\": [\n    {\n      \"id\": \"{{ $('Webhook').first().json.body.customData['TA Custom Field ID Weekly Inquery'] }}\",\n      \"field_value\": \"{weekly_inquery}\"\n    }\n  ],\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "toolDescription": "This is the update_contact tool. Only use this tool to update the weekly_inquery as directed.",
        "parametersHeaders": {
          "values": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Version",
              "value": "2021-07-28",
              "valueProvider": "fieldValue"
            }
          ]
        },
        "placeholderDefinitions": {
          "values": [
            {
              "name": "weekly_inquery",
              "type": "string",
              "description": "update the weekly_inquery"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "70b35345-a67a-44bd-8e70-8f54f58019cb",
      "name": "update_current_response_times",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        560,
        -560
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Webhook').first().json.body.contact_id }}",
        "method": "PUT",
        "jsonBody": "={\n  \"customFields\": [\n    {\n      \"id\": \"{{ $('Webhook').first().json.body.customData['TA Custom Field ID current response times'] }}\",\n      \"field_value\": \"{current_response_times}\"\n    }\n  ],\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "toolDescription": "This is the update_contact tool. Only use this tool to update the current_response_times as directed.",
        "parametersHeaders": {
          "values": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Version",
              "value": "2021-07-28",
              "valueProvider": "fieldValue"
            }
          ]
        },
        "placeholderDefinitions": {
          "values": [
            {
              "name": "current_response_times",
              "type": "string",
              "description": "update the current_response_times"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "809c2147-1055-479a-9141-d1e83dc9610e",
      "name": "update_team_sizes",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        740,
        -560
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Webhook').first().json.body.contact_id }}",
        "method": "PUT",
        "jsonBody": "={\n  \"customFields\": [\n    {\n      \"id\": \"{{ $('Webhook').first().json.body.customData['TA Custom Field ID Team Sizes'] }}\",\n      \"field_value\": \"{team_sizes}\"\n    }\n  ],\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "toolDescription": "This is the update_contact tool. Only use this tool to update the team_sizes as directed.",
        "parametersHeaders": {
          "values": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Version",
              "value": "2021-07-28",
              "valueProvider": "fieldValue"
            }
          ]
        },
        "placeholderDefinitions": {
          "values": [
            {
              "name": "team_sizes",
              "type": "string",
              "description": "update the team_sizes"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "85f4bc96-3c7e-4253-9d14-6b6b900a61b6",
      "name": "update_operation_bottleneck",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        920,
        -560
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Webhook').first().json.body.contact_id }}",
        "method": "PUT",
        "jsonBody": "={\n  \"customFields\": [\n    {\n      \"id\": \"{{ $('Webhook').first().json.body.customData['TA Custom Field ID operation bottleneck'] }}\",\n      \"field_value\": \"{operation_bottleneck}\"\n    }\n  ],\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "toolDescription": "This is the update_contact tool. Only use this tool to update the operation_bottleneck as directed.",
        "parametersHeaders": {
          "values": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Version",
              "value": "2021-07-28",
              "valueProvider": "fieldValue"
            }
          ]
        },
        "placeholderDefinitions": {
          "values": [
            {
              "name": "operation_bottleneck",
              "type": "string",
              "description": "update the operation_bottleneck"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "d0422163-5d53-4c05-911a-efbe56d78af7",
      "name": "update_monthly_revenues",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        1100,
        -560
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Webhook').first().json.body.contact_id }}",
        "method": "PUT",
        "jsonBody": "={\n  \"customFields\": [\n    {\n      \"id\": \"{{ $('Webhook').first().json.body.customData['TA Custom Field ID Monthly Revenues'] }}\",\n      \"field_value\": \"{monthly_revenues}\"\n    }\n  ],\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "toolDescription": "This is the update_contact tool. Only use this tool to update the monthly_revenues as directed.",
        "parametersHeaders": {
          "values": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Version",
              "value": "2021-07-28",
              "valueProvider": "fieldValue"
            }
          ]
        },
        "placeholderDefinitions": {
          "values": [
            {
              "name": "monthly_revenues",
              "type": "string",
              "description": "update the monthly_revenues"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "6015e704-f9b4-4859-a60c-49b17fbb58a5",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1440,
        -660
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 260,
        "content": "## Get Free Slots"
      },
      "typeVersion": 1
    },
    {
      "id": "5262a11c-8937-4224-9431-fef9b0cf40f0",
      "name": "get_availability",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        1500,
        -560
      ],
      "parameters": {
        "url": "=https://clarity55.app.n8n.cloud/webhook/83874938-4b15-4481-a90e-103d8b17594f",
        "method": "POST",
        "sendBody": true,
        "parametersBody": {
          "values": [
            {
              "name": "timezone"
            },
            {
              "name": "startDate"
            },
            {
              "name": "endDate"
            },
            {
              "name": "Calendar ID",
              "value": "={{ $('Webhook').first().json.body.customData['Calendar ID'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "toolName",
              "value": "get_availability",
              "valueProvider": "fieldValue"
            }
          ]
        },
        "toolDescription": "This is the get_availability tool. Use this tool to get calendar availability in the requested timezone. Identify the user's requested timezone and convert to the appropriate Country/City timezone label. startDate is the date to start searching on and will continue to search the range of dates until endDate. If only one date is being searched, startDate and endDate may remain the same. If multiple dates are being searched, used the range. Format startDate and endDate in ISO 8601 +/- offset."
      },
      "typeVersion": 1.1
    },
    {
      "id": "2b5e3409-541b-4e0f-b922-888391238869",
      "name": "Webhook1",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -540,
        -200
      ],
      "parameters": {
        "path": "83874938-4b15-4481-a90e-103d8b17594f",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "81044f0b-869d-41b9-9ff3-2c02cbb8f5d5",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -340,
        -200
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "6817c77c-0037-4b67-9868-fec956bce665",
              "name": "startDate",
              "type": "string",
              "value": "={{ new Date(Date.parse($('Webhook1').item.json.body.startDate)).getTime() }}"
            },
            {
              "id": "443fc71b-9a7b-475f-ab59-bcf06484490b",
              "name": "endDate",
              "type": "string",
              "value": "={{ new Date(Date.parse($('Webhook1').item.json.body.endDate)).getTime() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "cebaa240-3624-4b6e-a484-d445c7e5fa88",
      "name": "Get Free Slots",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -120,
        -200
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/calendars/{{ $('Webhook1').first().json.body['Calendar ID'] }}/free-slots",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text",
              "outputPropertyName": "freeSlots"
            }
          }
        },
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "startDate",
              "value": "={{ $('Webhook1').first().json.body.startDate }}"
            },
            {
              "name": "endDate",
              "value": "={{ $('Webhook1').first().json.body.endDate }}"
            },
            {
              "name": "timezone",
              "value": "={{ $('Webhook1').first().json.body.timezone }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{ $('Webhook1').first().json.body.Authorization }}"
            },
            {
              "name": "version",
              "value": "2021-04-15"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "221c8cd2-7213-4617-8a7f-252843a302b0",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        80,
        -200
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d464db86-2d5a-422d-8489-ebd5c4f1941a",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.freeSlots }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "928d5dc4-7a35-4ff4-abb8-deb5e878b946",
      "name": "Response on Re-schedule",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        400,
        -80
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": "={\n   \"result\": \"Looks like we dont have availability on that date, can we check for another date?\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "a86549f8-dd58-4779-8cfa-d0ad0db4417e",
      "name": "Book a Slot",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        400,
        -300
      ],
      "parameters": {
        "options": {},
        "respondWith": "json",
        "responseBody": "={\n   \"result\": {{ JSON.stringify($json.freeSlots) }}\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "47ef459b-141d-4035-b68a-b4b2e3b42610",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -580,
        -340
      ],
      "parameters": {
        "color": 7,
        "width": 1220,
        "height": 420,
        "content": "# Get Availability"
      },
      "typeVersion": 1
    },
    {
      "id": "957c645d-01d0-43e7-bc85-a5bd7e59a1aa",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1660,
        -660
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 260,
        "content": "## Schedule Appointment"
      },
      "typeVersion": 1
    },
    {
      "id": "57989e54-9d01-46b0-8b67-c65f5a3671c1",
      "name": "Sticky Note14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        60,
        -1180
      ],
      "parameters": {
        "color": 6,
        "width": 540,
        "height": 220,
        "content": "## Updating Event ID"
      },
      "typeVersion": 1
    },
    {
      "id": "f308a091-fde0-48ae-8a10-a76a62707a4a",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        -200,
        -880
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "appointment booked",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a1c8e5d5-f518-44e3-a6dc-4cef919c791c",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.body.customData['Appointment Title '] }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "reply",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "1ec7e8a6-292a-4e70-bae7-5519cbbf0b28",
                    "operator": {
                      "type": "string",
                      "operation": "notExists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.body.customData['Appointment Title '] }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "51f72049-da50-4338-b34a-be2810217a14",
      "name": "Set Event",
      "type": "n8n-nodes-base.set",
      "position": [
        280,
        -1120
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d5998c8f-e9cc-4124-bdcc-261cfb7572bb",
              "name": "events",
              "type": "object",
              "value": "={{ $('Get Appointments by Contact').item.json.events.find(event => \n    new Date(event.startTime) > new Date() && \n    event.title.includes($('Webhook').item.json.body.customData['Appointment Title'])\n) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "dbb808e9-0408-4bf0-bcff-9c8b4df8cf25",
      "name": "Update Event ID",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        460,
        -1120
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Webhook').item.json.body.contact_id }}",
        "method": "PUT",
        "options": {},
        "jsonBody": "={\n  \"customFields\": [\n    {\n      \"id\": \"{{ $('Webhook').item.json.body.customData['TS Custom Field ID Event ID'] }}\",\n      \"field_value\": \"{{ $('Set Event').item.json.events.id }}\"\n    }\n  ]\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}"
            },
            {
              "name": "Version",
              "value": "2021-07-28"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "44cfb239-e903-46c7-982a-e5fb6cf6fc21",
      "name": "Get Appointments by Contact",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        100,
        -1120
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Webhook').first().json.body.contact_id }}/appointments",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}"
            },
            {
              "name": "Version",
              "value": "2021-07-28"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "1619c01b-72de-477d-9e1d-f736065612d6",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1880,
        -660
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 260,
        "content": "## Reschedule Appointment"
      },
      "typeVersion": 1
    },
    {
      "id": "2e4c567a-341d-442a-a713-3182310aea67",
      "name": "reschedule_appointment",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        1940,
        -560
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/calendars/events/appointments/{{ $('Webhook').first().json.body.customData['Event ID'] }}",
        "method": "PUT",
        "sendBody": true,
        "sendHeaders": true,
        "parametersBody": {
          "values": [
            {
              "name": "startTime"
            }
          ]
        },
        "toolDescription": "This is the reschedule_appointment tool. Appointment startTime must be converted from contact's timezone to {{ $('Set Credentials and Placeholders').item.json['Account Timezone'] }}.",
        "parametersHeaders": {
          "values": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Version",
              "value": "2021-04-15",
              "valueProvider": "fieldValue"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "8effb783-4e3a-462f-a2dc-37ab4af1199d",
      "name": "Supabase1",
      "type": "n8n-nodes-base.supabase",
      "onError": "continueRegularOutput",
      "position": [
        120,
        -860
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "session_id",
              "keyValue": "={{ $('Webhook').item.json.body.contact_id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "n8n_chat_histories",
        "operation": "getAll"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "56031703-1188-4fd9-8342-e97230f327ca",
      "name": "Get Chat History",
      "type": "n8n-nodes-base.code",
      "onError": "continueRegularOutput",
      "position": [
        280,
        -860
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "let type = $json.message.type === \"human\" ? \"Human\" : \"AI\";\nlet content = $json.message.content;\n\nreturn {\n  json: {\n    formatted_line: `${type}: ${content}`\n  }\n};"
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "94477286-ff16-4f4e-a0ae-eea6972da100",
      "name": "Format Responses",
      "type": "n8n-nodes-base.code",
      "onError": "continueRegularOutput",
      "position": [
        440,
        -860
      ],
      "parameters": {
        "jsCode": "// Combine all formatted lines into one string\nlet conversation = items\n  .map(item => item.json.formatted_line)\n  .filter(line => line && line.trim() !== '') // remove empty/null lines\n  .map(line => line.replace(/\\n+/g, ' '))     // replace multiple \\n with a single space inside messages\n  .join('\\n');                                // one \\n between messages\n\nreturn [\n  {\n    json: {\n      full_conversation: conversation\n    }\n  }\n];"
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "7f1fc92a-fa7e-4d89-ba04-16ad4ef296f0",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        100,
        -920
      ],
      "parameters": {
        "color": 6,
        "width": 460,
        "height": 220,
        "content": "## Previous Chat Fetching"
      },
      "typeVersion": 1
    },
    {
      "id": "ae9cc712-b4a2-4927-a4eb-32c2d614db87",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -460,
        -880
      ],
      "parameters": {
        "path": "cf6bfa0f-e536-4e65-b952-8ef8accc3fdd",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "6891dda7-8afd-4c50-90ce-fd59fac46aac",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        -300,
        -560
      ],
      "parameters": {
        "sessionKey": "={{ $('Webhook').first().json.body.contact_id }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 25
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "49aaf637-0afd-4ec4-b10e-7a1fb4a8fa74",
      "name": "schedule_appointment",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        1720,
        -560
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/calendars/events/appointments",
        "method": "POST",
        "sendBody": true,
        "sendHeaders": true,
        "parametersBody": {
          "values": [
            {
              "name": "calendarId",
              "value": "={{ $('Webhook').first().json.body.customData['Calendar ID'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "locationId",
              "value": "={{ $('Webhook').first().json.body.customData['TA Location ID'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "contactId",
              "value": "={{ $('Webhook').first().json.body.contact_id }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "startTime"
            }
          ]
        },
        "toolDescription": "This tool is responsible for booking an appointment in the calendar after confirming the caller's desired date and time. It is executed only after calendar availability has been checked by the 'get_availability' tool and the caller has explicitly confirmed their appointment details.\\n\\n The tool captures key information required for the booking, including the caller's full name, business name, contact details (email and phone number), the confirmed appointment date and time, and the caller's timezone.\\n\\nBy ensuring all necessary details are collected before execution, this tool guarantees an efficient and accurate scheduling process, minimizing errors and ensuring seamless appointment confirmations.\",",
        "parametersHeaders": {
          "values": [
            {
              "name": "content-type",
              "value": "application/json",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').item.json.body.customData['TA GHL PIT'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Version",
              "value": "2021-04-15",
              "valueProvider": "fieldValue"
            }
          ]
        }
      },
      "typeVersion": 1.1,
      "alwaysOutputData": true
    },
    {
      "id": "c1bff3f0-f60f-4564-95ce-a628bf4ae748",
      "name": "update_previous_experience_with_aIso",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        1280,
        -560
      ],
      "parameters": {
        "url": "=https://services.leadconnectorhq.com/contacts/{{ $('Webhook').first().json.body.contact_id }}",
        "method": "PUT",
        "jsonBody": "={\n  \"customFields\": [\n    {\n      \"id\": \"{{ $('Webhook').first().json.body.customData['TA Custom Field ID Previous Experience with AIso'] }}\",\n      \"field_value\": \"{previous_experience_with_aIso}\"\n    }\n  ],\n} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "toolDescription": "This is the update_contact tool. Only use this tool to update the previous_experience_with_aIso as directed.",
        "parametersHeaders": {
          "values": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Webhook').first().json.body.customData['TA GHL PIT'] }}",
              "valueProvider": "fieldValue"
            },
            {
              "name": "Version",
              "value": "2021-07-28",
              "valueProvider": "fieldValue"
            }
          ]
        },
        "placeholderDefinitions": {
          "values": [
            {
              "name": "previous_experience_with_aIso",
              "type": "string",
              "description": "update the previous_experience_with_aIso"
            }
          ]
        }
      },
      "typeVersion": 1.1
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d5396ddd-7fac-4766-89c5-f98c64b7e162",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Book a Slot",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Response on Re-schedule",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Get Appointments by Contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Supabase1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Response GHL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook1": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Event": {
      "main": [
        [
          {
            "node": "Update Event ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supabase1": {
      "main": [
        [
          {
            "node": "Get Chat History",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Book a Slot": {
      "main": [
        []
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Get Free Slots",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Free Slots": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Responses": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Chat History": {
      "main": [
        [
          {
            "node": "Format Responses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_availability": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "update_team_sizes": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "schedule_appointment": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "update_weekly_inquery": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "reschedule_appointment": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "update_businesses_type": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "update_lead_dispostiotn": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "update_monthly_revenues": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Appointments by Contact": {
      "main": [
        [
          {
            "node": "Set Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "update_operation_bottleneck": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "update_current_response_times": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "update_previous_experience_with_aIso": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}