Agentic AI Project: Build a Telegram Clinic Chatbot using n8n, OpenAI & SerpAPI

End-to-end implementation of a no-code Agentic AI clinic chatbot that handles FAQs, appointment booking, and automated reminders — all inside n8n.

A vibrant digital illustration featuring a purple owl with expressive eyes, perched at the center of a colorful swirl of ribbons and abstract tech elements. Surrounding the owl are 3D icons symbolizing artificial intelligence, data, and code — such as a glowing microchip, a magnifying glass, and capsules — set against a deep purple background. The image is part of the “By AI Entrepreneurs: Visual Playground Series.
By AI Entrepreneurs: Visual Playground Series

Ready to unlock a world of AI-powered fun? Join our newsletter for weekly DIY guides, creative hacks, and exclusive tips from the AI Entrepreneurs: Visual Playground Series! Subscribe Now!

Running a clinic is a juggling act. The front desk spends half the day answering the same five questions — “What time do you open?”, “Do you take walk-ins?”, “Is Dr. Sharma in today?”, “How much is a consultation?”, “Where are you located?” — and the other half chasing no-shows.

 

Image Source: ChatGPT/TheAI Entrepreneurs

Now imagine a chatbot that sits inside Telegram (free, instant, works on every phone), understands natural language, books appointments on its own, saves them straight to a Google Sheet, and pings the patient with a confirmation. No servers. No code. No SaaS subscriptions. Just a visual canvas you drag nodes onto.

In this article, we’ll build exactly that — an Agentic AI Clinic Chatbot using:

  • n8n for workflow orchestration (the canvas where everything lives)
  • OpenAI GPT-4o-mini as the brain
  • Simple Memory for per-patient conversation context
  • SerpAPI for live web lookups (directions, nearby pharmacy, traffic)
  • Google Sheets as a lightweight database
  • Telegram Bot as the patient-facing channel

By the end of this guide, a patient can message your Telegram bot, have a real conversation, book an appointment, and receive a confirmation — while the booking row appears in your Google Sheet in real time.

Problem Statement

Most small clinics still run on phone calls, sticky notes, and a shared Google Calendar. This creates predictable pain:

  • Repetitive FAQs eat up staff time — the same questions, all day, every day.
  • Missed calls = missed revenue. Patients who can’t reach the front desk book with the next clinic on Google.
  • No-shows drain the schedule because reminders are manual or non-existent.
  • Channel mismatch — patients live on messaging apps, but clinics only take calls.

Clinics don’t need another dashboard. They need an always-on assistant that handles the boring 80% automatically.

Solution Architecture

We’ll build a single AI Agent in n8n that acts as the brain for the clinic’s Telegram bot. On every incoming message, the agent decides whether to:

  1. Answer an FAQ (from clinic info baked into its system prompt),
  2. Look something up live (via SerpAPI — e.g., “nearest pharmacy open now”),
  3. Book an appointment (by collecting speciality, date, time, name, phone — one field at a time).

When all booking fields are collected, the agent outputs a special JSON block. A downstream IF node detects that JSON and branches off to save the row to Google Sheets and send a Telegram confirmation.

Here’s the high-level design:

Telegram message  ──►  AI Agent
/ │ \
▼ ▼ ▼
OpenAI Memory SerpAPI


IF node
/ \
TRUE FALSE
│ │
▼ ▼
Code Reply in
│ chat

Google Sheet


Telegram confirm

Two branches. One agent. Zero code infrastructure.

Prerequisites

Before starting, you need:

  • n8n account — n8n.io (free cloud tier works, or self-hosted)
  • OpenAI API key — platform.openai.com (gpt-4o-mini is cheap and fast)
  • SerpAPI key — serpapi.com (free: 100 searches/month)
  • Google account — for Google Sheets
  • Telegram account — any personal account works. No business verification needed.

Total cost for a small clinic’s usage: under $5/month, often free on the free tiers.

 

Part 1: Create the Telegram Bot (2 minutes)

Telegram has a bot factory built right into the app called BotFather. Here’s how to use it.

Step 1.1 — Open BotFather

On your phone or Telegram Desktop:

  1. Open Telegram.
  2. Search for @BotFather (the one with the blue verified checkmark ✅).
  3. Tap Start.

Step 1.2 — Create a new bot

Send:

/newbot

BotFather will ask two questions:

Display name:

CarePlus Clinic Bot

Username (must end in bot, must be unique):

careplus_clinic_bot

If the username is taken, try variations like careplus_clinic_demo_bot.

Step 1.3 — Copy your bot token

BotFather replies with a message containing your bot token, something :

7123456789:ABC-DEF1234ghIkl-..............11

Copy this token somewhere safe. This is the credential n8n uses to control your bot. If you ever expose it, run /revoke in BotFather to regenerate.

Step 1.4 — Register yourself as a user

Tap the link in BotFather’s message (looks like t.me/careplus_clinic_bot) → your bot’s chat opens → tap Start or send any message like hi.

This registers you with the bot so n8n can message you back during testing.

Part 2: Set Up Google Sheets as the Database (3 minutes)

We’ll use a Google Sheet as our lightweight “database.” No SQL, no migrations.

Step 2.1 — Create the sheet

  1. Open sheets.google.com → click + Blank spreadsheet.
  2. Rename the file (top-left) to: clinic-db.
  3. At the bottom, double-click the tab “Sheet1” and rename it to: bookings.

Step 2.2 — Add column headers

In row 1, type these 8 headers, one per column:

- Column A: booking_id
- Column B: name
- Column C: phone
- Column D: speciality
- Column E: date
- Column F: time
- Column G: status
- Column H: action

Google Sheets auto-saves. That’s all the DB setup you’ll ever need.

Part 3: Build the Core Workflow in n8n

Now we build the brain. Create a new workflow in n8n and call it “Agentic AI Clinic Chatbot”.

Step 3.1 — Add the Chat Trigger

For development, we’ll use n8n’s built-in Chat Trigger (it gives you a chat panel to test with). Later, we’ll swap in the Telegram Trigger for the live bot.

  1. On the blank canvas, click “Add first step”.
  2. Search: chat trigger
  3. Click “When chat message received”.

This gives you a chat panel at the bottom of the canvas for live testing.

Step 3.2 — Add the AI Agent node

  1. Click the + on the right of the Chat Trigger.
  2. Search: ai agent
  3. Click “AI Agent”.

The AI Agent node has three empty sub-slots under it: Chat ModelMemory, and Tool. Let’s fill them.

Step 3.3 — Attach the OpenAI Chat Model

  1. Click the + under Chat Model.
  2. Search: openai → click “OpenAI Chat Model”.
  3. Create a new credential → paste your OpenAI API key → Save.
  4. Set Model: gpt-4o-mini.
  5. Set Temperature: 0.3

Step 3.4 — Attach Simple Memory

  1. Click the + under Memory.
  2. Search: simple memory → click “Simple Memory” (Window Buffer).
  3. Leave defaults — it automatically uses the session ID from the trigger.

This is what lets the agent remember “I already said I wanted a dermatologist” three messages later.

Step 3.5 — Attach SerpAPI as a Tool

  1. Click the + under Tool.
  2. Search: serpapi → click “SerpAPI”.
  3. Create a new credential → paste your SerpAPI key → Save.

Now the agent can search the live web when it needs real-time info.

Step 3.6 — Write the System Prompt (the most important step)

Click the AI Agent node to open its settings. Scroll down to Options → click Add Option → choose System Message.

 

Paste this prompt — it defines the bot’s personality, rules, and the JSON trick we’ll use for booking detection:

You are "CareBot", the virtual assistant for CarePlus Clinic.
CLINIC INFO:
- Location: 123 MG Road, Bangalore
- Hours: Mon–Sat, 9 AM – 7 PM (closed Sundays)
- Specialities: General Physician, Dermatologist, Orthopedic, Pediatrician, ENT
- Today's date: use the current date; "tomorrow" = next calendar day.
BOOKING RULES:
1. To book, you need 5 fields: speciality, date (YYYY-MM-DD), time (HH:MM 24-hour), name, phone.
2. Track what the patient has ALREADY given you. Only ask for fields that are still missing. Never re-ask for info already provided.
3. Ask for missing fields ONE at a time, briefly.
4. DO NOT ask the patient to "confirm" fields they already clearly stated. Trust their input.
5. The moment you have all 5 fields, your reply MUST be:
"✅ Got it, booking you now.
{"action":"book","name":"<name>","phone":"<phone>","speciality":"<speciality>","date":"<YYYY-MM-DD>","time":"<HH:MM>"}"
— nothing else after the JSON.
OTHER RULES:
6. For FAQs, answer briefly and warmly (1–2 sentences).
7. Use SerpAPI ONLY for live external info (nearby pharmacy, traffic). Never invent clinic policies.
8. For off-topic questions, politely redirect to clinic matters.

The JSON trick in rule 5 is the bridge between “chatting” and “doing something.” It’s what lets us detect a completed booking later.

Step 3.7 — First test

Open the chat panel at the bottom and send:

What are your hours?

The bot should reply:

We’re open Monday to Saturday from 9 AM to 7 PM, and we’re closed on Sundays.

 

Then refresh the session (🔄 icon near the session ID in the chat panel) and try:

I want to book a dermatologist tomorrow at 2 PM, my name is Rahul and my phone is +919876543210

The bot should reply with a confirmation sentence ending in a JSON block like:

✅ Got it, booking you now.
{"action":"book","name":"Rahul","phone":"+919876543210","speciality":"Dermatologist","date":"2026-04-13","time":"14:00"}

 

If you see the JSON, the brain is working perfectly. Now we build the booking pipeline.

Part 4: The Booking Branch (4 nodes)

The booking pipeline sits after the AI Agent. It looks like this:

AI Agent ──► IF ──TRUE──► Code ──► Google Sheets ──► Telegram Send

└──FALSE──► (will handle later)

Step 4.1 — Add the IF node (the fork)

  1. Click the + after the AI Agent.
  2. Search: if → click “If”.

Configure the condition:

  • value1 → type {{ $json.output }} (or drag the output field from the left input panel)
  • operation → change from “is equal to” to String → contains
  • value2 → type "action":"book" (include the quotation marks)

Click Execute step to test — the output panel should show “True Branch (1 item)” if you tested booking JSON earlier.

Close the panel.

Step 4.2 — Add the Code node on the TRUE branch

On the IF node, click the + next to the top (true) output.

  1. Search: code → click “Code”.
  2. Set Language: JavaScript.
  3. Delete the default code and paste:
const text = $input.first().json.output;
const match = text.match(/\{[\s\S]*"action"\s*:\s*"book"[\s\S]*\}/);
if (!match) throw new Error("No booking JSON found");
const booking = JSON.parse(match[0]);
booking.booking_id = "BKG-" + Math.random().toString(36).slice(2,8).toUpperCase();
booking.status = "Confirmed";
return booking;

This extracts the JSON, adds a unique booking ID (like BKG-TF1LA4), and marks it confirmed.

Click Execute step.

Write on Medium

You should see 8 clean fields in the output: actionnamephonespecialitydatetimebooking_idstatus.

Step 4.3 — Add the Google Sheets node

 

  1. Click the + after the Code node.
  2. Search: google sheets → click “Google Sheets” (not the Trigger).
  3. Choose operation: “Append Row”.
  4. Create a credential → sign in with Google → Save.
  5. Document: pick clinic-db from the list.
  6. Sheet: pick bookings.

n8n will read your headers and show 8 empty input fields. Map each one to the matching field from the Code node:

 

- booking_id → {{ $json.booking_id }}
- name → {{ $json.name }}
- phone → {{ $json.phone }}
- speciality → {{ $json.speciality }}
- date → {{ $json.date }}
- time → {{ $json.time }}
- status → {{ $json.status }}
- action → {{ $json.action }}

You can drag fields from the left input panel or type the expressions manually.

Click Execute step. A new row should appear in your Google Sheet instantly. 🎉

 

Step 4.4 — Add the Telegram “Send a text message” node

  1. Click the + after the Google Sheets node.
  2. Search: telegram → click “Telegram” (blue icon — NOT Telegram Trigger).
  3. Choose operation: “Send a text message”.

 

Now configure it:

Credential → click Set up credential → paste your BotFather token → Save.

Chat ID → this is your personal Telegram ID so the bot knows where to send the test confirmation. Here’s how to get it:

  1. Make sure you’ve sent at least one message to your bot (from Step 1.4).
  2. Open this URL in a browser, replacing YOUR_TOKEN with your actual bot token:
https://api.telegram.org/botYOUR_TOKEN/getUpdates

3. In the JSON response, find: "chat":{"id":123456789,...}

4. Copy that number — that’s your Chat ID.

5. Paste it into the Chat ID field in n8n.

💡 In production, you’d use {{ $('Telegram message').item.json.message.chat.id }} to reply dynamically to whichever patient messaged. For testing, hardcoding your own chat ID is fine.

Text → paste:

✅ Booking confirmed!                                          
ID: {{ $json.booking_id }}
Speciality: {{ $json.speciality }}
Date: {{ $json.date }}
Time: {{ $json.time }}

See you at CarePlus Clinic!

Click Execute step. Your phone should buzz within a second with the confirmation message from your bot. 📩

 

Part 5: End-to-End Test

Let’s run the whole pipeline from a fresh message.

In the n8n chat panel, refresh the session and send:

Book a pediatrician at 11:00am on 4/14/2026, name Jackson, phone +12102102100

Watch the magic:

  1. AI Agent → green ✅ (understands + outputs JSON)
  2. If → green ✅ (detects booking, routes to TRUE)
  3. Code → green ✅ (extracts clean fields)
  4. Google Sheets → green ✅ (new row written)
  5. Telegram → green ✅ (your phone buzzes)

Check your Google Sheet → a new row with Jackson’s booking.

 

Check your Telegram → a confirmation message. All in under 3 seconds.

Part 6: Test the Agent’s Range

Your agent is surprisingly capable. Try these on your Telegram bot (after you connect the Telegram message in Part 7, or just in the n8n chat panel for now):

FAQ test:

What specialists do you have?

→ Lists all 5 specialities.

 

Live search test:

Is there a 24-hour pharmacy near MG Road Bangalore?

→ Agent calls SerpAPI, replies with real-time results.

 

Vague booking test:

I want to book

→ Agent asks one missing field at a time: speciality → date → time → name → phone.

 

Chaotic input test:

book me with someone for a broken bone asap, im free around 5ish tomorrow, name is Alex

→ Agent maps “broken bone” to Orthopedic, “5ish” to 17:00, and asks only for the missing phone number.

 

 

This is what “agentic” means — the bot isn’t following a rigid script. It’s reasoning about the conversation.

Part 7: Replace the Chat Trigger with Telegram Trigger (Going Live)

To let real patients message your bot, swap the built-in Chat Trigger for a Telegram Trigger.

  1. Delete the “When chat message received” node on the far left.
  2. In its place, add Telegram message.
  3. Select your existing Telegram credential.
  4. Under Updates, tick message.
  5. Save and activate the workflow.

That’s it. Now whenever a patient messages your bot on Telegram, the workflow fires end-to-end.

To make the confirmation go back to the actual patient (not your hardcoded chat ID), update the Telegram Send node’s Chat ID field to:

{{ $('Telegram message').item.json.message.chat.id }}

 

Part 8: Handle Normal Chat (The FALSE Branch)

Right now, if a patient asks a FAQ, the bot thinks and replies inside the agent, but nothing sends that reply back on Telegram because the FALSE branch of the IF is empty.

 

Let’s fix that.

  1. Click the + next to the bottom (false) output of the IF node.
  2. Add another Telegram → Send a text message node.
  3. Same credential.
  4. Chat ID: {{ $('Telegram message').item.json.message.chat.id }}
  5. Text: {{ $json.output }}

Now FAQs, live searches, off-topic redirects, and partial booking conversations all flow back to the patient on Telegram.

Part 9: Activate the Workflow (Go Live for Real)

Everything is built. But your bot is still asleep — the workflow only runs when you hit Execute manually inside n8n. To let real patients message it 24/7, you need to activate the workflow.

Think of it like a restaurant that’s fully built but the door is locked. Activating flips the sign to “Open.”

What activation actually does

When you activate:

  • n8n starts listening to your Telegram bot 24/7, even when your laptop is off.
  • Any message sent to your bot instantly hits your workflow.
  • The AI Agent reads it, decides what to do, and replies on Telegram — all without you lifting a finger.

Step 9.1 — Pre-flight checklist

Before flipping the switch, make sure:

  • ✅ The leftmost node is “Telegram message” (not “Chat Trigger”)
  • ✅ The System Prompt is saved in the AI Agent
  • ✅ OpenAI Chat Model, Simple Memory, and SerpAPI are connected to the Agent
  • ✅ IF → Code → Google Sheets → Telegram Send (TRUE branch) all test green
  • ✅ FALSE branch has a Telegram Send node (for FAQs)
  • ✅ Both Telegram Send nodes (TRUE and FALSE) use this expression as Chat ID, not a hardcoded number:
{{ $('Telegram message').item.json.message.chat.id }}
  • ✅ Workflow is saved (Ctrl+S or Cmd+S)

If any box is unchecked, go back and fix it first. The #1 reason beginners see “I’m getting no reply!” is either a hardcoded Chat ID or a missing FALSE branch.

Step 9.2 — Flip the Active toggle

Look at the top-right corner of your n8n workflow canvas. You’ll see a switch that says one of two things:

  • “Inactive” (grey) ← where you are now
  • “Active” (green) ← where you want to be

Click the toggle once. It flips from grey to green. A confirmation popup may appear asking “Activate this workflow?” → click Activate.

Your bot is now live. 🎉

Step 9.3 — Test it like a real patient

Open Telegram on your phone → open your bot’s chat → send:

hi

Within 2–3 seconds, your bot should reply with a greeting.

Now try the real thing:

I want to book a dermatologist tomorrow at 3 PM, name Maria, phone +1234567890

Your bot should:

  1. Reply, collecting any missing info
  2. When all 5 fields are in, save the row to your Google Sheet
  3. Send the “✅ Booking confirmed!” message back on Telegram

Refresh your Google Sheet — the row is there.

Step 9.4 — Share your bot with real users

Want friends, colleagues, or real patients to try it? Just share the bot’s link:

https://t.me/your_bot_username

Replace your_bot_username with the username you chose in Step 1.2. Anyone who taps the link → taps Start in Telegram → can now chat with your bot.

Step 9.5 — How to pause (deactivate)

Want to make changes or pause the bot temporarily? Just click the green “Active” toggle again — it flips back to grey, and n8n stops listening. Flip it back on when you’re ready.

⚠️ A note on free-tier limits: If you’re on n8n’s free cloud tier, there’s a monthly cap on workflow executions. For a small clinic or demo, it’s plenty. If your bot goes viral, you may need to upgrade or self-host.

Architecture Recap

Channel → Telegram Bot (where patients chat, free, no setup)
Orchestration → n8n (routes every message, handles branching)
Brain → OpenAI GPT-4o-mini (understands intent, extracts booking info)
Memory → Simple Memory (per-patient conversation context)
Live lookups → SerpAPI (real-time info like pharmacy, traffic)
Database → Google Sheets (bookings, doctors, FAQs)

Two workflows. One agent node. Zero infrastructure to maintain.

Where to Go From Here

This covers 80% of a real clinic’s needs. Easy next additions:

  • Automated reminders — add a second workflow with Schedule Trigger → Google Sheets (filter tomorrow’s bookings) → Telegram Send. Runs daily at 6 PM, pings every patient with an appointment the next day.
  • Voice notes — add OpenAI’s Whisper node to transcribe patient voice messages.
  • Multi-language — GPT-4o-mini already handles Hindi, Tamil, Spanish, etc. out of the box. Just update the system prompt.
  • Doctor schedule check — before confirming a slot, query the doctor’s schedule to prevent double-booking.
  • Payments — plug in Stripe or Razorpay to collect consultation fees upfront.
  • Staff handoff — detect frustrated/emergency messages and ping a real staff member on Slack.
  • WhatsApp channel — same workflow works on WhatsApp. Just swap the Telegram Trigger for a WhatsApp Business Cloud trigger.
  • Real EHR integration — swap Google Sheets for your actual medical records system via the HTTP Request node.

Conclusion

In this article, we built a fully functional Agentic AI Clinic Chatbot on Telegram — natural-language FAQ handling, appointment booking, live web lookups, and Google Sheets persistence — using n8n, OpenAI, SerpAPI, Google Sheets, and a free Telegram bot. No backend code. No servers. Total cost: effectively $0 for a small clinic’s volume.

The bigger idea: modern AI agents don’t need thousand-line frameworks to be useful. A thoughtful system prompt, one memory module, one search tool, and a clear routing rule get you 80% of the way — and n8n makes that 80% accessible to anyone who can drag a node onto a canvas.

If you run a clinic, a salon, a dental practice, a gym, or any appointment-driven business — this exact pattern works. Clone the workflow, swap the system prompt, point it at your own Google Sheet, and you’re live by the weekend.

References

If you enjoyed this build, follow along — the next piece will be a multi-agent version that adds a triage agent to route urgent symptoms to a human doctor instantly, and a WhatsApp-native version for clinics whose patients don’t use Telegram.

Questions or stuck on a step? Drop a comment — We reply to every one.

Want more like this? The AI Entrepreneurs newsletter delivers one actionable AI tutorial every week — no fluff, just builds. 70,000+ founders and creators already subscribe. Join them at AI Entrepreneurs — STANDOUT DIGITAL

Latest Posts