Chatbots
Chatbots are AI systems that can converse with humans using natural language. They range from simple rule-based systems to sophisticated LLM-powered assistants.
12 min•By Priygop Team•Updated 2026
Types of Chatbots
Rule-based chatbots: follow a script of predefined responses. If the user says X, respond with Y. Simple, predictable, but cannot handle questions outside the script.
Retrieval-based chatbots: search a database of pre-written answers and pick the best match for the user's question.
Generative chatbots: use a language model to generate responses from scratch. ChatGPT is a generative chatbot. More flexible but can make mistakes.
Diagram
Loading diagram…
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
Simple Rule-Based Chatbot
Simple Rule-Based Chatbot
# Simple rule-based customer support chatbot
class SimpleChatbot:
def __init__(self, name="Assistant"):
self.name = name
self.rules = {
# keywords: response
"hello|hi|hey": f"Hello! I am {name}. How can I help you today?",
"order|track|shipping": "To track your order, visit our website and click 'My Orders'. Enter your order number to see the status.",
"return|refund": "We offer free returns within 30 days. Please go to our website and click 'Start a Return' to begin the process.",
"hours|open|close": "Our customer service team is available Monday to Friday, 9am to 6pm.",
"price|cost|how much": "You can find current prices on our website. Use code SAVE10 for 10% off your first order.",
"bye|goodbye|thanks|thank": "Thank you for contacting us! Have a great day.",
}
self.default = "I am not sure I understand. Could you rephrase that, or would you like to speak with a human agent?"
def respond(self, user_input):
user_lower = user_input.lower()
for pattern, response in self.rules.items():
keywords = pattern.split("|")
if any(kw in user_lower for kw in keywords):
return response
return self.default
# Simulate a conversation
bot = SimpleChatbot("ShopBot")
conversation = [
"Hi there!",
"I want to know about returning a product",
"What are your opening hours?",
"How much does shipping cost?",
"Thanks, goodbye",
]
print("Chatbot Conversation:")
print()
for user_msg in conversation:
print(f" You: {user_msg}")
response = bot.respond(user_msg)
print(f" {bot.name}: {response}")
print()Try It Yourself
Try It YourselfHTML
HTML Editor
✓ ValidTab = 2 spaces
HTML|25 lines|939 chars|✓ Valid syntax
UTF-8