Building a Chatbot prototype with JavaScript

Nick Balderston
RE: Write
Published in
2 min readDec 8, 2017

For a group assignment, we were given the task of creating a chatbot prototype that would help a user discover the breed of dogs that would be best for them. We started by evaluating what information about the user might help determine the appropriate breed and how that information mapped to different attributes of dogs. We then developed a conversation tree that would be guided by a short list of general questions, imagined relevant keywords that the user might include in their answers, and constructed interjecting questions that we might include if their answers didn’t include any part of the information we were looking for.

Once we had defined the information we needed, the questions that would help us obtain that information, and the keywords that would be used in determining the right breed, we started exploring chatbot prototyping tools. We discovered a lot of prototyping tools, but in most cases, we found that they would limit us to a more linear and curated conversation than we were hoping to form. Our solution was to just build a prototype from scratch with JavaScript. In fact, it proved to be easier than expected.

For each question, we created an array to hold keywords that we expected to see in their answer. When we asked about their home, we included words like apartment, house, yard, small, large, etc. When the user submits their answer, we used a for loop to go through each keyword in our array, and JavaScript’s .search() function to check if their response included any of those words. We used integer variables to keep track of various dog attributes. For example, if the user said “I live in a small apartment”, the keywords small and apartment would subtract from the value of a variable tracking the appropriate dog size. Also if our loop didn’t discover a keyword we were specifically looking for (like children), we would trigger a question to ask if any children lived in their home.

For this prototype, we found that JavaScript allowed us to make the calculations necessary to most effectively test our chatbot. Through this exercise, I feel that I learned something valuable about prototyping. We don’t always have to exclude the real tools in favor of simpler ones. In the amount of time it might have taken to learn other prototyping tools and work around their deficiencies, we were able to produce a functional prototype while constructing what could be a foundation for the development of a full product.

--

--