I don't remember when I first read about Eliza, but it must have been around 1983, probably in an article in Your Computer magazine. Eliza, a program written in 1965, talks to you. Well sort of - it emulates a Rogerian psychotherapist. Rogerian psychotherapy is non-directive, that is the therapist attempts to get the client to do most of the talking, without offering advice or opinion. Obviously it's more subtle than that, but that's the gist.
The idea of being able hold a conversation with a computer seemed incredible. How vast and complex a program it must be. Eliza was, for a while, like a programming holy grail. It was simple enough to describe in a sentence, yet, to my 14 year old brain, seemed impossible to achieve.
In actual fact it turns out to be really rather straightforward and can be written in a just a few lines of code. Here's a version of Eliza written in Python that I bundled up from someone else's initial work shortly after the turn of the millenium. It's all smoke and mirrors; the program doesn't have a clue what it is saying and it's not difficult to catch it out, but it's amusing and, in this modern age, it means your chatbot always has something to say.
The eliza.py module includes an interactive mode, so you can get a feel for how it behaves. Just grab the code and
python eliza.py. To use the it from with in your own code do something like
import eliza therapist = eliza.eliza() while some_condition: #get input from somewhere reply = therapist.respond(input) #send reply somewhere
I'd let this drop of the internet when I rejigged this website, but it turns out it's referenced all over the place including on Wikipedia, so I've resurrected it, updated for Python 3, and popped it up on GitHub.