Chatbots Tutorial menu

Chatbots Introduction

A chatbot is software that understands a user's message and sends back a reply, like a conversation.

Where Chatbots Are Used

PlaceExample
Websites"Ask us anything" bubble in the corner of a shop's site
WhatsApp and MessengerOrder tracking, booking appointments
Banks and telecomsBalance checks, package information, complaints
CollegesAdmission dates, fee structure questions, course details
Inside appsHelp assistants, AI writing helpers
General AI assistantsChatGPT, Gemini and Claude

Two Main Types

Rule-based chatbots

A rule-based bot follows rules written by a person: if the message contains certain words, send a certain reply. Many also use buttons ("Press 1 for timings").

Example

javascript
const rules = [
  { keywords: ["fee", "price"], answer: "The Python course fee details are on our courses page." },
  { keywords: ["address", "location"], answer: "We are in Orangi Town, Karachi." },
];

function ruleBot(message) {
  const text = message.toLowerCase();
  for (const rule of rules) {
    if (rule.keywords.some((k) => text.includes(k))) return rule.answer;
  }
  return "Sorry, I can only answer questions about fees and location.";
}

console.log(ruleBot("Where is your location?"));
console.log(ruleBot("Can you write me a poem?"));
Output
We are in Orangi Town, Karachi.
Sorry, I can only answer questions about fees and location.

AI chatbots

An AI chatbot sends the message to a language model, which understands the meaning and writes a fresh reply. It can handle spelling mistakes, Roman Urdu, follow-up questions and topics no one wrote a rule for.

Example

javascript
// The shape of what an AI chatbot sends to a language model
const request = {
  model: "your-model-name",
  messages: [
    { role: "system", content: "You are a helpful assistant for a Karachi computer institute." },
    { role: "user", content: "kya aap weekend classes karwate hain?" },
  ],
};
console.log(request.messages.length, "messages will be sent");
console.log("User asked:", request.messages[1].content);
Output
2 messages will be sent
User asked: kya aap weekend classes karwate hain?

A rule-based bot would need a rule for "weekend classes" in Roman Urdu. An AI model understands it directly.

Comparing the Two

Rule-basedAI chatbot
Understands new wordingNo, only its keywordsYes
Cost to runAlmost freePay per use of the AI model
Predictable answersFullyMostly, but can make mistakes
SetupWrite every ruleWrite a good system prompt and add knowledge
Best forMenus, simple FAQs, formsOpen questions, support, tutoring

Many real products are hybrids: fixed buttons and rules for common tasks (track order, opening hours), and AI for everything else.

Start simple. If ten fixed answers cover 90% of your customers' questions, a rule-based bot may be all you need.

Exercise

Exercise

What is the main advantage of an AI chatbot over a rule-based chatbot?

Learn Chatbots with a teacher

Join the AI & Prompt Engineering course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp