Unit 6: Building a Custom AI Chatbot
Unit 6 of the Avarix AI Website Program shows students how to bring their ideas to life. You'll learn how to add new pages, build reusable components, and create multiple chatbot experiences.
Lesson 6.1: Exploring a Next.js Project
Get an overview of a full-featured Next.js app.
Project Initialization
Follow these steps to launch the starter project:
- Visit the GitHub repository: https://github.com/aman-singh14/AvarixStarterCode
- Click the green "Code" button
- Choose the "Codespaces" tab at the top
- Click "Create a codespace on main"
Running Your Next.js Project
- Wait a few moments while Codespaces finishes setting up
- When setup is complete, run
npm run dev
- Open
http://localhost:3000
in the browser to view your project
Setting Up Your API Key
- Locate the .env file in your project
- Assign your API Key to the OPENAI_API_KEY variable
- Enclose your API Key in double quotes ""
Layout and Folder Structure
App Directory
- Houses all user-accessible pages
- The examplePage folder represents a page accessible through the navbar
- To add a new page, create a new folder inside the App directory
Components Folder
- Contains reusable UI pieces
- All components should be stored here
- Helps organize your site with modular elements
Public Assets
- Place images, icons, or any static files here
- For instance, the homepage logo is stored here
No need to worry about the next, node_modules, or lib folders for now
Lesson 6.2: Building and Using Components
Discover how to build and reuse components in your Next.js app.
Making a Component
- Duplicate the starter component
- Find starterCode.tsx under the components directory
- Copy and paste the file into the same folder
- Rename the copy to "contactMe"
Modifying the Contact Component
- Change the function name from EditMyName to ContactMe
- Paste the form code below inside the section tag:
<div className="max-w-screen-md bg-white p-8 rounded shadow-lg mx-auto">
<h2 className="text-2xl font-bold mb-4">Contact Me</h2>
<form>
<div className="mb-4">
<label htmlFor="name" className="block text-gray-700 font-semibold mb-2">Name</label>
<input type="text" id="name" name="name" className="border border-gray-400 p-2 w-full rounded" />
</div>
<div className="mb-4">
<label htmlFor="email" className="block text-gray-700 font-semibold mb-2">Email</label>
<input type="email" id="email" name="email" className="border border-gray-400 p-2 w-full rounded" />
</div>
<div className="mb-4">
<label htmlFor="message" className="block text-gray-700 font-semibold mb-2">Message</label>
<textarea id="message" name="message" className="border border-gray-400 p-2 w-full rounded"></textarea>
</div>
<button type="submit" className="bg-blue-500 text-white font-semibold py-2 px-4 rounded hover:bg-blue-600">Send Message</button>
</form>
</div>
Linking ContactMe to Home
- Open page.tsx located in the App folder
- Add this import:
import Contact from '@/components/contactMe'
- Ensure the path after components/ matches the file name (contactMe.tsx)
- Place
<Contact/>
among the component tags - Check that the contact form appears on the page
Lesson 6.3: Adding Pages and Navigation
Learn how to create additional pages and set up navigation links in your app.
Making a New Page
- To create a page, make a new folder and add a page.tsx inside it
- Copy the examplePage folder and rename the copy to newPage
- Add components to your new page as needed
Accessing Your Page
- To visit your new page, update your browser’s URL to include /newPage
- Example: https://app.github.dev/newPage
- This logic applies to any page: just add its name after your base URL
Linking Pages in the Navbar
- Open header.tsx in your components directory
- Add this to the links array:
{name: 'New Page', path: '/newPage'}
- Run
npm run dev
and click the new navbar link to confirm it works
Linking Pages via Buttons
- At the top of the file, add:
import Link from 'next/link';
- Wrap your button with a Link tag
- Example:
<Link href="/newPage">
<button> Go to the new page </button>
</Link>
Homework: Project Outline
Prepare a basic plan for your final website project.
Tasks To Complete
- Follow the steps in Lessons 6.1–6.3 to structure your website
- Start building the components you’ll use—don’t worry about styling just yet
- Create all pages you’ll need in your final site
- Update the navigation bar to reflect your new pages
- Edit the chatbot welcome message in route.ts
- Commit your work and upload to a new GitHub repository
- Submit the project via Schoology
Was this page helpful?