Chatbots Introduction
A chatbot is software that understands a user's message and sends back a reply, like a conversation.
Where Chatbots Are Used
| Place | Example |
|---|---|
| Websites | "Ask us anything" bubble in the corner of a shop's site |
| WhatsApp and Messenger | Order tracking, booking appointments |
| Banks and telecoms | Balance checks, package information, complaints |
| Colleges | Admission dates, fee structure questions, course details |
| Inside apps | Help assistants, AI writing helpers |
| General AI assistants | ChatGPT, 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
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?"));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
// 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);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-based | AI chatbot | |
|---|---|---|
| Understands new wording | No, only its keywords | Yes |
| Cost to run | Almost free | Pay per use of the AI model |
| Predictable answers | Fully | Mostly, but can make mistakes |
| Setup | Write every rule | Write a good system prompt and add knowledge |
| Best for | Menus, simple FAQs, forms | Open 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?
