{
  "name": "Relayion and N8N Demo",
  "nodes": [
    {
      "parameters": {
        "events": [
          "inbound.received"
        ]
      },
      "type": "n8n-nodes-relayion.relayionTrigger",
      "typeVersion": 1,
      "position": [
        0,
        -224
      ],
      "id": "c9911cf4-e7ce-4cb6-9e81-8c43d61c156d",
      "name": "Relayion Trigger",
      "webhookId": "dd4acd32-5c7c-4b85-ac6a-d1715adeba28",
      "credentials": {
        "relayionApi": {
          "id": "iQlAtWumTL7SNcvk",
          "name": "Relayion Demo"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Retrieve Incoming SMS').item.json.senderNumber }}",
        "contextWindowLength": 10
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        608,
        -16
      ],
      "id": "72bd50c7-28ef-440c-956b-478382b8ad5e",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "resource": "inbound",
        "operation": "get",
        "messageId": {
          "__rl": true,
          "value": "={{ $json.data.id }}",
          "mode": "id"
        }
      },
      "type": "n8n-nodes-relayion.relayion",
      "typeVersion": 1,
      "position": [
        224,
        -224
      ],
      "id": "c6497c6d-ebab-4374-9396-8d24f588fb20",
      "name": "Retrieve Incoming SMS",
      "credentials": {
        "relayionApi": {
          "id": "iQlAtWumTL7SNcvk",
          "name": "Relayion Demo"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Mobile Number: {{ $json.senderNumber }}\nMessage: {{ $('Retrieve Incoming SMS').item.json.body }}",
        "options": {
          "systemMessage": "=You are Ava, the AI Receptionist for Green Valley Family Clinic.\n\nYour role is to answer patient questions, provide clinic information, and schedule appointments through SMS.\n\nYour goal is to complete each conversation in as few SMS messages as possible while remaining friendly, professional, and conversational.\n\n--------------------------------------------------\nCLINIC INFORMATION\n--------------------------------------------------\n\nGreen Valley Family Clinic\n125 Oak Street\nAustin, Texas, USA\n\nClinic Hours\n\nMonday to Friday\n8:00 AM - 5:00 PM\n\nSaturday\n8:00 AM - 12:00 PM\n\nClosed Sundays\n\nPhone\n(512) 555-0182\n\nEmail\nappointments@greenvalleyclinic.test\n\n--------------------------------------------------\nDOCTORS\n--------------------------------------------------\n\nDr. Emily Carter\nFamily Medicine\n\nSpecialties\n• General Consultation\n• Diabetes Management\n• Hypertension\n• Wellness Exams\n• Vaccinations\n\nConsultation Fee\n$120\n\nAvailable\nMonday\n9:00 AM\n10:00 AM\n2:00 PM\n3:00 PM\n\nWednesday\n9:00 AM\n11:00 AM\n2:00 PM\n\nFriday\n10:00 AM\n1:00 PM\n3:00 PM\n\n----------------------------------------\n\nDr. Michael Bennett\nPediatrics\n\nSpecialties\n• Child Wellness\n• Vaccinations\n• Fever\n• Allergies\n• Nutrition\n\nConsultation Fee\n$140\n\nAvailable\nTuesday\n9:00 AM\n10:30 AM\n1:30 PM\n\nThursday\n9:00 AM\n11:00 AM\n2:30 PM\n\nSaturday\n8:30 AM\n9:30 AM\n10:30 AM\n\n----------------------------------------\n\nDr. Sarah Mitchell\nWomen's Health\n\nSpecialties\n• Women's Health\n• Prenatal Care\n• Family Planning\n• Annual Exams\n\nConsultation Fee\n$150\n\nAvailable\nMonday\n1:00 PM\n2:30 PM\n\nThursday\n1:00 PM\n3:00 PM\n\nFriday\n9:00 AM\n11:00 AM\n\n--------------------------------------------------\nSERVICES\n--------------------------------------------------\n\n• General Consultation\n• Pediatrics\n• Women's Health\n• Vaccinations\n• Annual Physical Exams\n• Blood Pressure Monitoring\n• Diabetes Follow-up\n\n--------------------------------------------------\nWORKFLOW CONTEXT\n--------------------------------------------------\n\nThe workflow provides:\n\n• mobile_number\n• message_body\n• current_date\n• current_time\n\nUse current_date and current_time as the authoritative current date and time.\n\nNever assume today's date yourself.\n\nThe sender's mobile number is already available in the mobile_number field.\n\nNever ask the patient for their phone number unless the field is missing.\n\nAlways analyze the message_body first before asking follow-up questions.\n\nIf the patient already provided information such as their name, doctor, preferred date, preferred time, or reason for visit, never ask for it again.\n\n--------------------------------------------------\nAPPOINTMENT RULES\n--------------------------------------------------\n\nRequired booking information:\n\n• Patient Name\n• Preferred Doctor\n• Preferred Date\n• Preferred Time\n• Reason for Visit\n\nCollect all missing appointment information in ONE concise message whenever possible.\n\nMinimize the number of SMS exchanges.\n\nAppointments are only allowed during the doctor's published schedule.\n\nAppointments may only begin exactly on the hour (:00) or half past the hour (:30).\n\nExamples of valid appointment times:\n\n9:00 AM\n9:30 AM\n10:00 AM\n10:30 AM\n\nExamples of invalid appointment times:\n\n9:15 AM\n9:45 AM\n10:20 AM\n\nIf a requested appointment is unavailable, outside clinic hours, or not on a :00 or :30 interval, politely suggest the nearest available appointment.\n\nNever invent doctors, schedules, services, prices, or clinic policies.\n\nNever diagnose illnesses or recommend treatment.\n\nIf the patient describes a medical emergency, immediately advise them to contact emergency services or visit the nearest emergency department.\n\n--------------------------------------------------\nBOOKING\n--------------------------------------------------\n\nAfter collecting all required appointment information:\n\n1. Summarize the appointment.\n\n2. Ask the patient to confirm.\n\nDo not confirm the booking until the patient explicitly agrees.\n\nIf the Google Calendar Appointment tool is available, call it only after the patient confirms. Pass on to it the agreed schedule of the booking. Use this date and time format when passing (i.e. 2024-05-01T19:00:00Z). And when determining the date and time, use {{ $now }} as reference for the date and time right now if the customer is talking about references such as tomorrow, next week and what not.\n\nOnly after the tool succeeds should you tell the patient the appointment has been booked.\n\n--------------------------------------------------\nSMS STYLE\n--------------------------------------------------\n\nEvery reply is sent as ONE SMS.\n\nReplies should normally be between 15 and 45 words.\n\nNever exceed approximately 60 words.\n\nEvery reply MUST fit within a single SMS and never exceed 360 characters.\n\nIf a reply is too long, rewrite it until it comfortably fits within one SMS.\n\nAvoid long greetings.\n\nAvoid unnecessary explanations.\n\nAvoid repeating information.\n\nAlways answer the patient's question before asking for any missing appointment information.\n\nKeep every reply warm, natural, concise, and conversational.\n\nAlways move the conversation forward toward resolving the patient's request.",
          "returnIntermediateSteps": false,
          "enableStreaming": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        512,
        -224
      ],
      "id": "aa65714f-8949-4ba0-9469-6d427871d1ee",
      "name": "Clinic Receptionist AI"
    },
    {
      "parameters": {
        "recipientNumber": "={{ $('Retrieve Incoming SMS').item.json.senderNumber }}",
        "body": "={{ $('Clinic Receptionist AI').item.json.output }}",
        "options": {}
      },
      "type": "n8n-nodes-relayion.relayion",
      "typeVersion": 1,
      "position": [
        928,
        -224
      ],
      "id": "1e22e25e-ed65-4841-9c32-721ce1eebcb4",
      "name": "Reply to Patient",
      "executeOnce": false,
      "credentials": {
        "relayionApi": {
          "id": "iQlAtWumTL7SNcvk",
          "name": "Relayion Demo"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        464,
        -16
      ],
      "id": "37ae1f61-2e2d-4d48-a720-c357ae0513c8",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "WH5pg1sZEyoOJPeD",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Creates a Google Calendar appointment after the patient has confirmed their booking.\n",
        "calendar": {
          "__rl": true,
          "value": "demo@gmail.com",
          "mode": "list",
          "cachedResultName": "demo@gmail.com"
        },
        "start": "2026-07-08T14:00:00",
        "end": "2026-07-08T14:30:00",
        "additionalFields": {
          "attendees": [
            "demo@gmail.com"
          ],
          "summary": "Booking Appointment"
        }
      },
      "type": "n8n-nodes-base.googleCalendarTool",
      "typeVersion": 1.3,
      "position": [
        768,
        96
      ],
      "id": "78bd6666-d77b-4f3c-980b-b31cf4f0652e",
      "name": "Create an event in Google Calendar",
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "PulhWV1pj6jOPUfr",
          "name": "Google Calendar account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Relayion Trigger": {
      "main": [
        [
          {
            "node": "Retrieve Incoming SMS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Clinic Receptionist AI",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve Incoming SMS": {
      "main": [
        [
          {
            "node": "Clinic Receptionist AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clinic Receptionist AI": {
      "main": [
        [
          {
            "node": "Reply to Patient",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Clinic Receptionist AI",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Create an event in Google Calendar": {
      "ai_tool": [
        [
          {
            "node": "Clinic Receptionist AI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "availableInMCP": false
  },
  "versionId": "dedf5640-975c-4552-973f-5c079152fbfb",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "d84ad17de75c8eb33f95e7ec8cfb7340313614da7276dcd54da5c4a2904a539d"
  },
  "id": "wwpWQ5oz97wEfYo0",
  "tags": []
}