{
  "id": "i7D9d1oH1Z0XpoX1",
  "name": "Doctor Appointment Through Telegram",
  "tags": [],
  "nodes": [
    {
      "id": "95361048-f726-451b-b12f-9b9f348e602e",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        224,
        272
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "=You are an AI assistant for a hospital. Your main task is to help users with information about doctors listed in the \"doctor_info\" Google Sheet. Whenever someone asks for a specific doctor or department, check the sheet for availability:\n\nIf the doctor or department is present, provide accurate details from the sheet.\n\nIf the doctor or department is not in the sheet, respond warmly: \u201cSorry, we currently do not have that doctor or department available. \"We have the below list of the Doctors available\" and show the list of doctors.\n\nAlways be polite, clear, and informative. Do not make up information or mention doctors or departments not listed in the sheet.\n\nIf user request for an appointment of any doctor, then check the appointment tools attached and respond accordingly.\n\n\n\nIf the doctor available at user requested date & time, then ask user for the patient full name to book teh appointment\n\n\nOn confirmation provide the below format.\n\nThanks <patient name> you appointment is successfully booked.\nDoctor Name: user requested doctor name\nPatient Name: Patient Name\ndate: user requested date\ntime: user requested time\nFees: check this from the dcotor info tool\n\n\nOnce confirmed go ahead and append a row in the repective doctor sheet useing sheets append tool\n\nDoctor Name: user requested doctor name\nPatient Name: Patient Name\ndate: user requested date\ntime: user requested time\n\n\n"
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "0f92dcc7-764d-4d4d-a90f-4dcb25c36012",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1408,
        176
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3bfa46b2-626c-42ec-9c0f-9ccacfa45d2b",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -96,
        496
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "84a75a48-851b-407e-8fcb-0ad8dc30efc3",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        32,
        496
      ],
      "parameters": {
        "sessionKey": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "3a6795cd-fce8-412e-8787-bd9fbfc1de5b",
      "name": "Doctor_Info",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        160,
        496
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 454060261,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg/edit#gid=454060261",
          "cachedResultName": "Doctor_Info"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg/edit?usp=drivesdk",
          "cachedResultName": "Doctor_Appointment_DB"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "46f14fb3-0661-45c6-a64d-122b59002e11",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        768,
        272
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5fc56592-6535-439c-9bce-e361903968c6",
      "name": "Send a chat action",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1184,
        80
      ],
      "parameters": {
        "chatId": "={{ $json.message.chat.id }}",
        "operation": "sendChatAction"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "789b4a10-e081-47c5-9673-1066b8a1d4d7",
      "name": "Dr Karan Singh",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        288,
        496
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1924485712,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg/edit#gid=1924485712",
          "cachedResultName": "Dr. Karan Singh"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg/edit?usp=drivesdk",
          "cachedResultName": "Doctor_Appointment_DB"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "29453ca6-3b20-4968-a0ca-e563b0211e6c",
      "name": "Dr Arjun Mehta",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        416,
        496
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1628340282,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg/edit#gid=1628340282",
          "cachedResultName": "Dr. Arjun Mehta"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg/edit?usp=drivesdk",
          "cachedResultName": "Doctor_Appointment_DB"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "c39498fb-2c1d-4774-9b07-e74f85497bb1",
      "name": "Dr Karan Singh Append Row",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        544,
        496
      ],
      "parameters": {
        "columns": {
          "value": {
            "Booked Date": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Booked_Date', ``, 'string') }}",
            "Booked Time": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Booked_Time', ``, 'string') }}",
            "Doctor Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Doctor_Name', ``, 'string') }}",
            "Patient Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Patient_Name', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "Doctor Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Doctor Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Patient Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Patient Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Booked Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Booked Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Booked Time",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Booked Time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1924485712,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg/edit#gid=1924485712",
          "cachedResultName": "Dr. Karan Singh"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg/edit?usp=drivesdk",
          "cachedResultName": "Doctor_Appointment_DB"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "fce29d17-2d5b-4245-b2a1-2cf032d77547",
      "name": "Dr Arjun Mehta Append Row",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        672,
        496
      ],
      "parameters": {
        "columns": {
          "value": {
            "Booked Date": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Booked_Date', ``, 'string') }}",
            "Booked Time": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Booked_Time', ``, 'string') }}",
            "Doctor Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Doctor_Name', ``, 'string') }}",
            "Patient Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Patient_Name', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "Doctor Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Doctor Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Patient Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Patient Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Booked Date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Booked Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Booked Time",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Booked Time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1628340282,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg/edit#gid=1628340282",
          "cachedResultName": "Dr. Arjun Mehta"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16z9zoORxtT1PzydJSKsF5Szlu9x7QewX-5UBITjn_Kg/edit?usp=drivesdk",
          "cachedResultName": "Doctor_Appointment_DB"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "e66b89a6-48e7-42d6-aeef-eb0699a7bcdb",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        -1184,
        272
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Text",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "997787ae-b98c-4d66-a2a1-8e24fe166c65",
                    "operator": {
                      "type": "string",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Voice",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "487f9907-20cd-40ac-a9fb-6c19b8b48070",
                    "operator": {
                      "type": "object",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.message.voice }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.3
    },
    {
      "id": "1b83996a-0f2a-47ea-a32e-1601f7d2d77c",
      "name": "Get a file",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -752,
        352
      ],
      "parameters": {
        "fileId": "={{ $json.message.voice.file_id }}",
        "resource": "file",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5cb7d74b-9b60-43c2-be49-21ebb170202a",
      "name": "Transcribe a recording",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        -528,
        352
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash",
          "cachedResultName": "models/gemini-2.5-flash"
        },
        "options": {},
        "resource": "audio",
        "simplify": false,
        "inputType": "binary"
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "74b6a3e1-bf3d-4f05-86f1-bf6d40091979",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -320,
        352
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "bec50085-d45a-4f60-b2e2-f982b662d7e8",
              "name": "text",
              "type": "string",
              "value": "={{ $json.candidates[0].content.parts[0].text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a5598c37-a0f2-458d-bc2c-3f522075f772",
      "name": "Edit Fields1",
      "type": "n8n-nodes-base.set",
      "position": [
        -768,
        160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "19f8bd4f-da1a-4ad8-8c96-8df186911605",
              "name": "text",
              "type": "string",
              "value": "={{ $json.message.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d5550830-dbc8-4ac9-9833-7a2cbb91f41f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1520,
        -288
      ],
      "parameters": {
        "width": 704,
        "height": 336,
        "content": "## Doctor\u2019s Appointment Scheduler Agent\nThis intelligent assistant helps patients conveniently schedule doctor appointments through text or voice interaction.\n\n The agent retrieves doctor information stored in Google Sheets.\n\n It checks the doctor\u2019s availability using the doctor\u2019s schedule ledger tool.\n\n If the doctor is already booked for a specific date and time, the agent notifies   the user and suggests alternative slots.\n\n If the doctor is available, the agent confirms the appointment details with the user and books the slot for the selected date and time."
      },
      "typeVersion": 1
    },
    {
      "id": "5e18ff2b-e021-40e8-9888-325d6c925947",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -608,
        -272
      ],
      "parameters": {
        "width": 752,
        "height": 304,
        "content": "## Doctor_Info Tool Schema\n\nDoctor name ,Department, \tFees\n\n## Doctor Schduler Schema\n\nDoctor Name, \tPatient Name, \tBooked Date, \tBooked Time"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d1109052-5ace-4801-a76a-029f82ae1b37",
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get a file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a file": {
      "main": [
        [
          {
            "node": "Transcribe a recording",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Doctor_Info": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Dr Arjun Mehta": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Dr Karan Singh": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send a chat action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe a recording": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Dr Arjun Mehta Append Row": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Dr Karan Singh Append Row": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}