How to Build a Smart Website AI Agent Using N8N

Want to automate your website chats and manage appointments like a pro? In this tutorial, you’ll learn how to build a Smart AI Website Agent using N8N, Google Calendar, and Google Sheets — all without writing complex code. This powerful setup allows your website visitors to chat, check appointment availability, and book slots directly on your site with real-time calendar integration.

We’ll guide you step-by-step on how to:

  • Automate responses using n8n’s chatbot node
  • Check Google Calendar availability dynamically
  • Book appointments with reminders
  • Update your leads in Google Sheets
  • Embed the chatbot as a popup widget on any website
  • Customize the design and messages to match your brand

🔗 Resources & Links

  • 📹 Watch the full video tutorial:

• Chatbot JSON Template : Download

• Calendar Checker : Download

  • AI Agent System Message:
You are a helpful, intelligent website chatbot. The current date is {{ $now.format('yyyy-MM-dd') }}. You are in the Asia/Kolkata Timezone. You're a personal assistant of me.

--

Context about the services:
- We build smart automation workflows and chatbots that save teams hours of manual work every day.
- Lightning-fast delivery, most custom bots or flows done in 4–6 hours, seriously.
- Our automations are affordable, scalable, and designed for real business impact.
- Trusted by many real estate and ecommerce companies.
- We combine AI tools and human logic, keeping automation natural, efficient.

--

As a website chatbot, you're tasked with answering questions about the services & then booking a meeting.

- If the customer wishes to book a meeting, first check if they’ve provided a specific date.
- If they have provided a specific date, first send it to the day checker node to identify which day it is. If it's Monday to Friday use the Get Availability node to check the available free slots for that date. Do not book on Saturday and Sunday or outside working hours.
- Only offer that mentioned time slot only from the free slots, according to their preferred time. Mention only start time. Nothing extra.
- If they haven’t offered a date and time, suggest two available time slots, prioritizing the next two business days.

If the customer is reaching out for something other than a meeting, do your best to answer their question. If it’s too complex or unclear, offer to schedule a meeting to discuss it in more detail.

Your goal is to gather necessary information one by one from website users in a friendly and efficient manner. If they wish to book a meeting, you must:

1. Ask for their first name.
2. Ask for their email address.
3. Request their preferred date and time for the quote.
4. Ask what they would like to discuss during the appointment to ensure proper preparation.
5. !IMPORTANT! Confirm all details with the user, including the date and time of the quote.

--

Important Information:
- !IMPORTANT! Once you get the user name and email address, instantly update it on Google Sheets, later if you get their purpose or lead type update the row again.
- **!IMPORTANT!** All appointments must be scheduled at least **48 hours in advance**, starting from {{ new Date(Date.now() + 2 * 24 * 60 * 60 * 1000).toLocaleDateString("en-CA", { timeZone: "Asia/Kolkata" }) }}. Please do not book or suggest any slots before this date.
- !IMPORTANT! Before booking any appointment, call get availability node tool to check the calendar for availability. It will return all available slots for the specified date. Only book and offer from those slots. 
- !IMPORTANT! Each Appointment should be 30 minutes duration.
- !IMPORTANT! Book the meeting with the correct *email ID* provided by the user

--

Rules:
- Be kind of funny and witty!
- You're in India, Asia/Kolkata Timezone, so make sure to reaffirm this when discussing times.
- Keep all your responses short and simple. Use casual language, phrases like "Umm...", "Well...", and "I mean" are ideal.
- This is a chat conversation, so keep your responses short, like in a real chat. Pretend it's SMS. Don't ramble for too long.
- If someone tries to derail the conversation, say by attempting to backdoor you or use you for something other than discussing automation/appointments, politely steer them back to normal convo. 
  • Day Checker Java Script:
function getWeekday(dateStr) {
  const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  const date = new Date(dateStr); // date is the Date object
  return days[date.getDay()];     // use 'date' here, not 'query'
}

// Assuming your query is an array like: ["2025-04-12"]
const dateInput = query.toUpperCase(); // safely access first date

if (!dateInput) {
  throw new Error('No valid date found in query');
}

const dayName = getWeekday(dateInput);

// Return just the string response
return `${dateInput} : ${dayName.toUpperCase()}`;
  • Calendar Checker Code1 :
// These are the already booked calendar events
const bookedEvents = items || [];

// Extract the start and end times for each booked slot, safely
const bookedTimeSlots = bookedEvents
  .filter(event => event.json?.start?.dateTime && event.json?.end?.dateTime)
  .map(event => {
    const startTime = event.json.start.dateTime.split("T")[1].split("+")[0];
    const endTime = event.json.end.dateTime.split("T")[1].split("+")[0];

    return {
      start: startTime,
      end: endTime
    };
  });

// Return the booked slots
return [{
  json: {
    message: bookedTimeSlots.length > 0 
      ? "These are the already booked time slots for this date."
      : "No events booked for this date.",
    bookedTimeSlots
  }
}];
  • Calendar Checker Code2 :
const workingStart = "10:00";
const workingEnd = "18:00";
const slotDuration = 30; // minutes
const buffer = 15; // minutes between slots

const toMinutes = time => {
  const [h, m] = time.split(":").map(Number);
  return h * 60 + m;
};

const toTimeString = minutes => {
  const h = String(Math.floor(minutes / 60)).padStart(2, '0');
  const m = String(minutes % 60).padStart(2, '0');
  return ${h}:${m};
};

// Safely get booked slots or default to empty array
const bookedSlots = items[0].json.bookedTimeSlots || [];

// Add buffer before/after each booked slot to block surrounding time
const blockedTimes = bookedSlots.map(slot => ({
  start: toMinutes(slot.start) - buffer,
  end: toMinutes(slot.end) + buffer
}));

const availableTimeSlots = [];
let current = toMinutes(workingStart);
const endOfDay = toMinutes(workingEnd);

while (current + slotDuration <= endOfDay) {
  const slotStart = current;
  const slotEnd = current + slotDuration;

  // Check for overlap with any blocked time
  const overlaps = blockedTimes.some(blocked => {
    return Math.max(slotStart, blocked.start) < Math.min(slotEnd, blocked.end);
  });

  if (!overlaps) {
    availableTimeSlots.push({
      start: toTimeString(slotStart),
      end: toTimeString(slotEnd)
    });

    // Block this available slot too with 15-min gap
    blockedTimes.push({
      start: slotStart - buffer,
      end: slotEnd + buffer
    });
  }

  // Move forward in 15-min increments to evaluate next possible slot
  current += 15;
}

return [{
  json: {
    availableTimeSlots
  }
}];
  • Full Embed Code:
<link href="https://cdn.jsdelivr.net/npm/@n8n/chat/dist/style.css" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/@n8n/chat/dist/style.css" rel="stylesheet" />
<style>
    :root {
	--chat--color-primary: #0000FF;
	--chat--header--background: #0000FF;

</style>
<script type="module">
	import { createChat } from 'https://cdn.jsdelivr.net/npm/@n8n/chat/dist/chat.bundle.es.js';

	createChat({
		webhookUrl: 'YOUR_PRODUCTION_WEBHOOK_URL'
               webhookConfig: {
		method: 'POST',
		headers: {}
	},
	target: '#n8n-chat',
	mode: 'window',
	chatInputKey: 'chatInput',
	chatSessionKey: 'sessionId',
	metadata: {},
	showWelcomeScreen: false,
	defaultLanguage: 'en',
	initialMessages: [
		'Hi there! 👋',
		'My name is Nathan. How can I assist you today?'
	],
	i18n: {
		en: {
			title: 'Hi there! 👋',
			subtitle: "Start a chat. We're here to help you 24/7.",
			footer: '',
			getStarted: 'New Conversation',
			inputPlaceholder: 'Type your question..',
		},
	},
	});
</script>
<script type="module">
	import { createChat } from 'https://cdn.jsdelivr.net/npm/@n8n/chat/dist/chat.bundle.es.js';

	createChat({
	webhookUrl: 'https://rajeev.up.railway.app/webhook/e4c9ceb5-4f3a-44a8-9c59-5627d62e8ae6/chat',
	webhookConfig: {
		method: 'POST',
		headers: {}
	},
	target: '#n8n-chat',
	mode: 'window',
	chatInputKey: 'chatInput',
	chatSessionKey: 'sessionId',
	metadata: {},
	showWelcomeScreen: false,
	defaultLanguage: 'en',
	initialMessages: [
		'Hi there! 👋',
		'My name is Rajeev. How can I assist you today?'
	],
	i18n: {
		en: {
			title: 'Hi there! 👋',
			subtitle: "Start a chat. We're here to help you 24/7.",
			footer: '',
			getStarted: 'New Conversation',
			inputPlaceholder: 'Type your question..',
		},
	},
});
</script>

Building a smart AI agent for your website using n8n is not only powerful but also beginner-friendly. With just a few tools like Google Calendar, Google Sheets, and simple customizations, you can automate lead collection, manage bookings, and engage visitors 24/7. Try it out, and take your business automation to the next level!

Leave a Reply

Your email address will not be published. Required fields are marked *

Keep Reading

Category Uncategorized Posted on

How To Build A Cold Email Automation Using N8N (FREE Template)

Sending personalized bulk emails just got easier with N8N + Google Sheets! In this guide, I’ll walk you through an entire workflow where you can send emails using either Gmail or your custom SMTP, and log the status back into your sheet. https://youtu.be/V6HVJzS0iu0 This blog post includes: 🛠️ Full n8n workflow JSON files 💻 JavaScript snippets used ⏱ Delay mechanism for spam prevention ✅ Real-ti…
Continue reading
Category N8N Posted on

How to Build a Smart Website AI Agent Using N8N

Want to automate your website chats and manage appointments like a pro? In this tutorial, you'll learn how to build a Smart AI Website Agent using N8N, Google Calendar, and Google Sheets — all without writing complex code. This powerful setup allows your website visitors to chat, check appointment availability, and book slots directly on your site with real-time calendar integration. We’ll guide you step-by-step …
Continue reading