Introduction to conversational software
1. Introduction to conversational software:
Hello, and welcome to this course on chatbots and conversational software.
2. A short history
Conversational software is a familiar idea! In fact, the invention of the keyboard+video screen terminal brought on the first wave of command line apps in the 1960s. To use a command line app, you have to type instructions using a language that's very strict, but already much closer to human language than the underlying machine instructions. Around the same time, the ELIZA program was created. This now-famous program was able to hold a conversation by using a rule-matching engine. Despite the relatively simple code behind ELIZA, it's a compelling conversationalist. In this chapter, you will build up your own, minimal version of the ELIZA chatbot.

3. Course content:
In the following chapters, you will learn how to use regular expressions and machine learning to extract meaning from free-form text. You will build chatbots that can query a database for you, plan a trip, and help you order coffee. You will see that often, the tricky part of building more complicated bots is to keep track of the _state_ of the conversation. You'll first learn techniques for avoiding this statefulness, which is usually the easiest solution. Later, you'll learn how to handle state in the cases where you really have to.
4. EchoBot I
In this first set of exercises, you'll start with the basics. The first bot you'll build is called EchoBot because it simply echoes back to you whatever you say to it. For simplicity, all the bots you build in this course will receive messages in python code and print their responses to the screen. At the end of the course, we will provide you with some python code for connecting your bots to various messaging apps.
5. EchoBot II
To build an echo bot you need to define a `respond` function, which takes a message as an argument and returns an appropriate response. Here we define a function using the keyword `def`, then the name of the function, then its arguments in parentheses, and then a colon. The body of the function is indented by one level. We specify the output generated by the function using the `return` keyword. If a function doesn't have a `return` statement, it returns a `NoneType`. One way we can insert variables into a string in python is by using the string's `format` method. Inside the response, the function is a string containing curly brackets. These act as placeholders, and will get replaced by the value of the argument we pass when we call `format`. To keep track of everything that's being said, we'll define another function called `send_message` which prints what the user just said, gets the response by calling the respond function, and then prints the response of the bot as well.
6. EchoBot III
Even when we know we're talking to a bot, it can feel strange to see a response come back immediately. It just doesn't feel natural. We can create an artificial delay by importing the `time` module, and running time dot sleep, passing the number of seconds to wait as an argument. In this example, we've created a half-second delay.

References