Unit 12.4 · Term 4

Introduction to Chatbots & API Configuration

A chatbot (from "chat" + "robot") is a computer program that imitates human conversation using artificial intelligence (AI) and natural language processing (NLP) to understand user queries and respond automatically[cite: 7]. This lesson covers chatbot classifications, their business value, and the foundational role of APIs in connecting software.

Learning Objectives

  • 12.6.4.1 Define the types of chatbots
  • 12.6.4.2 Argue for the use of chatbots
  • 12.6.4.3 Explain the meaning of the API

Lesson Presentation

12.4-intro-chatbots.pdf · Slides for classroom use

1. The Evolution of Chatbots

Chatbots have evolved significantly from simple rule-based scripts to advanced conversational AI.

  • 1965: Eliza[cite: 203, 210].
  • 1972: Parry[cite: 204, 211].
  • 1988: Jabberwacky[cite: 205, 212].
  • 1992: Dr. Sbaitso[cite: 206, 213].
  • 1995: A.L.I.C.E[cite: 207, 214].
  • 2001: SmarterChild[cite: 208, 216].
  • 2010+: The Smartphone Age introduces Siri, Google Assistant, Alexa, and Cortana[cite: 209, 217, 218, 219, 220].

2. Classification of Chatbots

Chatbots are classified by their logic, interaction methods, and application areas.

Flowchart comparing rule-based decision trees with AI-based NLP processing.
Difference in logic between Rule-based (Decision Tree) and AI-based (NLP) chatbots.

By Logic and Architecture

Type Description Characteristics & Examples
Menu-based Based on structured, clickable menu navigation[cite: 34]. Operate on fixed decision trees. Suitable for simple, predictable tasks like pizza ordering[cite: 35, 36, 37].
Keyword-based Respond based on user-entered keywords and natural language processing[cite: 44]. More flexible than menus, enabling free-form user input and recognizing triggers[cite: 45, 46].
Skills Chatbots Built around predefined software "skills"[cite: 39]. Easily integrated with various platforms, like payment systems or booking services[cite: 41, 42].
Hybrid Chatbots Combines rule-based logic with AI elements[cite: 31]. Handles standard queries via menus/rules, but can process complex text using AI.

By Application Area

  • Messaging apps: Telegram, Viber, WhatsApp[cite: 26].
  • Websites: Embedded chat windows[cite: 27].
  • Telephone: Call centers, especially banks[cite: 28].
  • Devices: Smart speakers like Amazon Echo[cite: 30].

3. Arguing for the Use of Chatbots

Human vs. Bot Efficiency

A customer service employee needs to focus on one customer at a time to work well and meet the needs of their customers[cite: 233]. This does not apply to a chatbot that can answer hundreds of questions from different clients at the same time[cite: 234].

  • 24/7 Availability: Ensures constant communication between business and customers throughout the day[cite: 238, 239].
  • Budget Savings: The cost is much lower than the amount needed to pay, train, and maintain infrastructure for customer support staff[cite: 241, 242].
  • Consistency in Communication: Customers can expect to receive the same services from the chatbot every time they contact[cite: 236, 237].
  • Programmability: Chatbots can be programmed to automate common tasks (scheduling meetings, sending emails), allowing employees to focus on more important tasks[cite: 247, 248].
  • Ease of Deployment: Bots are a lot easier to install and distribute than mobile apps. Quality mobile apps are expensive to build, maintain, and deploy[cite: 222].
Diagram showing a chatbot handling multiple user requests simultaneously compared to a human agent.
Scalability: Chatbots can process hundreds of concurrent requests.

4. Understanding the API

API (Application Programming Interface) is a set of predefined tools and protocols used for software interaction between different programs and applications[cite: 48].

API Code Concept
API acts as a language translator that helps different software tools understand each other[cite: 177].

Key Features of an API

Feature Description
Ready-made tools Allows quick creation of complex logic, e.g., using TensorFlow for neural networks[cite: 50]. Using API is like borrowing tools instead of buying them[cite: 180].
Enhanced security Isolates sensitive functionality from misuse[cite: 51]. API acts as a guard, allowing only authorized programs to access sensitive information[cite: 178].
System integration Connects various systems (payments, logins)[cite: 52]. Works like a remote control, allowing different systems to work together smoothly[cite: 179].
Cost reduction Cheaper than developing functionality from scratch[cite: 53].

5. Technical Setup: PyCharm & Telegram API

To create chatbots, we use Python and API[cite: 174]. Follow these steps to configure your environment.

Step I: Obtain the API Token

  • Open Telegram and find @BotFather[cite: 56].
  • Enter command: /newbot[cite: 57].
  • Create bot name and copy API token[cite: 58].

Step II: Configure PyCharm

  • Open PyCharm and create a new Python project.
  • Open the command prompt and install the library: pip install pyTelegramBotAPI[cite: 59, 60, 61].

Step III: Write the Echo Bot Script

import telebot # Replace with your actual token API_TOKEN = "your_API_token" bot = telebot.TeleBot(API_TOKEN) # Decorator to handle incoming text messages @bot.message_handler(content_types=['text']) def echo(message): bot.send_message(message.chat.id, text=f"{message.text}") # Starts the chatbot bot.polling(none_stop=True)

Common Pitfalls

Hardcoding API Tokens

Never share your API Token publicly. The API acts as a security guard; if someone copies your token, they gain full control over your bot.

Non-Standard Wording in Rule-Based Bots

If you use a non-standard wording, a rule-based chatbot will most likely "get confused" and will not respond[cite: 226]. Always design fallback messages for unexpected inputs.

Independent Practice

Apply

Polite echo bot: Modify the basic echo bot so that it responds with the message: "I received the message <original message>.".

Analyze

Compare menu-based chatbots with keyword-based chatbots. In what specific business scenario would a fixed decision tree be more effective than NLP?

Evaluate

Discuss the ethical implications of using Voice Bots that perfectly imitate human speech. Should systems be required to announce they are AI before interaction?

Create

Bot is a foreigner: Modify the bot so that it responds with "Hello!" if the user enters "Hello" in any case, otherwise print "I don't understand you".

Plenary / Self-Check

Q1: What is the primary difference between a menu-based bot and an AI-based bot?

Menu-based operates on fixed decision trees and clicks [cite: 34, 35], while AI-based uses natural language processing to understand complex language constructions[cite: 227].

Q2: Name three arguments for implementing a chatbot in a business.

24/7 availability [cite: 238], budget savings [cite: 241], and consistency in communication[cite: 236].

Q3: How do you obtain an API token for a Telegram bot?

By finding @BotFather in Telegram and sending the /newbot command[cite: 56, 57].