Javascript Chatbot Workshop

Home | The Bot Shell | Programming Your Bot

The Do It Yourself Chatbot Project

Here is a Javascript shell that you can use to build your own verbally responsive software engine. This system is intentionally minimalist - it is hoped that anyone with a beginner's understanding of Javascript and HTML, and enough interest to study the example and read the documentation, would be able to start programming Chatbots right away.


The system presented here is often referred to as an "ELIZA" type Chatbot, in reference to the famous computer program by Joseph Weizenbaum.

Although a lot has happened in the world of artificial intelligence and natural language processing since Weizenbaum created ELIZA in 1966, the core techniques in that work can be seen in many of the most successful Chatbot implementations of today. The flagship of these conversation simulating techniques is that of reformulating statements made by the user and echoing them back as questions. If a user says "Nobody likes me." an ELIZA type system might respond with "Why do you say that nobody likes you?" or "How does it make you feel that nobody likes you?" It is easy to see how a large number of such phrases could be devised that would create appropriate responses to many inputs. One particular aspect of this method to note is that before turning the statement into a question, the program swaps the word "me" entered by the user, for the word "you."

In addition to the direct echoing described above, Chatbots are frequently programmed to respond to certain key words as triggers. If the user input contains the term "science fiction" the program might respond "Who is your favorite science fiction author?" In such a trigger mode, the program does not take into consideration any context, but takes a calculated risk that a well constructed response will be at least somewhat appropriate.

As a last ditch effort, or what I refer to as a graceful fail, a proper Chatbot will have an arsenal of generic responses and subject changers that keep the conversation going. Examples might be "I see, please tell me more." or "Do you have any hobbies?"

To setup (or program) your Chatbot you will arrange a list of user statements and systems responses. The statements and responses are coded using a pattern matching technique known as regular expressions which facilitate quite handily the ELIZA type transformations described above.

The basic functioning of the shell program goes like this:

  1. The user enters a statement or question.
  2. The system cycles through the list of input patterns you provided until it finds a match.
  3. When a match is found a reply is generated based on the response pattern you provided.

Although this system is very simple, and intended primarily as a jumping-off point for developing your own systems, it is possible to build quite a substantial verbal response robot using only the shell as presented here.

Click here to get the JS-Bot shell and read a description of its various sections.

Click here to go to a tutorial on how to program your bot.

Click here for articles on programming and artificial intelligence.