Chatbot#

Problem#

https://upload.wikimedia.org/wikipedia/commons/7/79/ELIZA_conversation.png

Fig. 14 A conversation with the ELIZA chatbot, a program developed in late sixties
Public domain. By Unknown authorUnknown author. Source: Wikimedia Commons
#

You will implement a chatbot which can have a conversation with the user. Requirements:

  1. Ask the user for input on the console and respond to the input.

    The program does not have to respond immediately after every input – it can keep asking questions, just as long as it responds eventually.

  2. Access stored data.

    The program should access data stored in a text file during its runtime, so that data from previous runs is accessible in future runs.

Be creative! Here are two examples:

The Doors of Destiny#

This is a simple user authentication chatbot which acts like a gatekeeper before the Doors of Destiny. The gatekeeper stops all travelers attempting to pass through, and ask them for their name and passphrase. If the provided data are contained in the Book of Records, the traveler may proceed.

Each traveler has two options. They may

  1. provide valid credentials, or

  2. bribe the guard, which allows them to add their credentials to the Book of Records – for a small fee.

Example conversation follows. User input is bold.


Halt! Welcome to the Doors of Destiny. 
Should you wish to proceed, you must identify yourself within the Book of Records. 

Is your name present in our book? yes
What is your name, traveller? Sissel
What is your passphrase? henrikmoller12345
Welcome through, peaceful soul!

Halt! Welcome to the Doors of Destiny. 
Should you wish to proceed, you must identify yourself within the Book of Records. 

Is your name present in our book? no
Psst! I'm... not supposed to tell you this, but for a small... compensation... I might be able to add you to the Book of Records without the Warden noticing. 

Would you like to be added to the Book of Records? yes
Perfect! I've added you - but I don't come cheap! I charge 100 coins for my services. 
Can you make the deposit? yes
Deposit successful! (You have 5532 coins remaining in your account).

What is your name, then, traveller? Sissel
What is your passphrase? henrikmoller12345
Welcome through the Doors of Destiny! And it's been a pleasure doing business with you.

Halt! Welcome to the Doors of Destiny. 
Should you wish to proceed, you must identify yourself within the Book of Records. 

Is your name present in our book? yes
What is your name, traveller? Sissel
What is your passphrase? 62236sucks
The passphrase you presented does not match our records! Guards - arrest this intruder!

Scheduler assistant#

This chatbot is like a virtual assistant like Siri, Alexa etc, which allows users to schedule events and see their calendar.

Example conversation follows. It uses ddmmyyyy as date format, and hours are represented as floating point numbers, so 15.5 means 15:30.


Hello there, it's Hal, your friendly scheduling assistant! 

Would you like to add a new event, or check an existing time slot? add
What is the name of the event? 62236 Lecture
On which day would you like to schedule the event? 08092025
What is the start time? 13
What is the end time? 17

Successfully added the event to your day!

Would you like to add a new event, or check an existing time slot? check
On which day would you like to check for scheduled events? 08092025
What time would you like to check for availability? 14.5
At that time, you'll be busy with 62236 Lecture

Would you like to add a new event, or check an existing time slot? open the pod bay doors
I'm sorry Dave, I'm afraid I can't let you do that.

For the curious: Hal is a fictional AI character from Space Odyssey. The Dave line is from this film.

Data formatting in files#

How you store data in the files is up to you. For example Book of Records could use the following two files:

coins.txt:

5632

book-of-records.txt:

Sissel:henrikmoller12345
Gökçe:62236rocks
Frederik:merhaba1337

The scheduling assistant could use in turn:

schedule.txt:

event_name: 62236 Lecture
date: 08092025
start_time: 13
end_time: 17

event_name: Tango
date: 10092025
start_time: 18
end_time: 19.5

Activity 22

We will have a short brainstorming session to find a chatbot idea.

Steps:

  • 2 min come up with a chatbot idea.

  • 2 min x 2 discuss your ideas with your partner and try to improve each others ideas by making it more funny, meaningful etc.

  • repeat the last step with someone else.