Robots in Disguise, Part 1: Building a ChatBot as a product development learning experience

Dave Huynh
5 min readApr 23, 2016

--

There is a lot of hype about chat bots right now, especially after Facebook announced their new chat APIs for Messenger at F8. They’re not the first and won’t be the last to support them, but when a big player like Facebook says bots are the future, people listen.

As a product manager, I’m curious about whether this really is a game changing way to build products and solve problems for people. What makes a good bot experience? What makes a bad experience? In what ways are bots better than apps? In what ways are they worse? To figure it out, I decided to build one named RockyBot and learn on both the user side and developer side by building something for myself. I’m going to document the process and my key takeaways here on Medium as I progress.

Disclaimer: I am not even close to being a good engineer. I do enough (read: hack) to get by and I wouldn’t use what I’m doing as a technical template on building a bot. There are infinitely smarter people who can help you there.

RockyBot

Rocky Apollo is my dog (yes, I like boxing films). RockyBot is built on Rocky’s Facebook page because he gets fewer messages than I do, which allows me to test. Also, once you see the use case, the name Rocky kind of makes sense.

The Use Case

My biggest hobby is olympic weightlifting. I am a USA Weightlifting certified Performance Sports Coach and I compete on the USAW circuit. Training involves following long, complex programs where you perform the lifts, but also do accessory work like squats and deadlifts. Here’s a sample from this past Monday:

TWO SNATCH GRIP DEADLIFTS TO THE POWER POSITION + HANG SNATCH
Work at 65% of your 1Rep Max Snatch for 5 sets. Target 5kg increase / week if work sets are above 100kg. Target 2.5kg increase / week if work sets are below 100kg.

FRONT SQUAT
Work to 75% of your 1RM Front Squat for 1 set of 3. Then decrease for 3x3. For Drop Sets 3x3, decrease weight by 15kg down if heavy triple is above 120kg. For Drop Sets 3x3, decrease weight by 10kg down if heavy triple is below 120kg. Target 5kg increase / week if work sets are above 120kg. Target 2.5kg increase / week if work sets are below 120kg.

The (first world) problem I need to solve, is before I lift a single thing, I need to know how much weight to put on the bar for each part of the program. In the gym I have to know what my 1 rep max weights are or have them written down either on paper or on my phone. Then I have to use my phone calculator or one of the gym’s calculators to calculate the percentages for the rep scheme. The question is whether a bot can do this more efficiently for me and be my virtual training assistant.

Why did I pick this Problem?

  1. This is a real, albeit trivial problem for me. I understand the needs and goals, I can forego the PM exercise of writing a user story for myself.
  2. Weight training has a very specific language and terminology. This (at least at first) frees me from the need to use some kind of NLP library to process commands I give to Rocky.

Mini Roadmap and Requirements for Part 1

  • Store my weight data for my max a.k.a. best a.k.a. personal record (PR) lifts (snatch, clean & jerk, back squat, front squat, deadlift, etc…)
  • Allow me to recall that weight data for any given lift
  • Allow me to recall a percentage of a weight as dictated by any given day’s training program.
  • Handle pounds (lb) to kilogram (kg) conversions because there are two kinds of weight plates at the gym.

The Bot in Action

Here is a real video of Rocky in action. For the curious, he’s built in Node using the Schmavery/Facebook-chat-API

Key Takeaways

  • My decision to use a narrow use case of weight training with specific jargon was a good one. In the video, I’m being polite and using whole sentences, but Rocky is really just looking for fuzzy matches on trigger words and characters like the names of the lifts, “pct” or “%”, and “kilos” or “kg”. I can see this getting really hard in broader settings, and a NLP engine would definitely be needed.
  • No visual views and interactions needed and as the developer, I love it. I have always been really bad with front-end development. It likely got worse when I worked at Flipboard and had world class designers and engineers doing all the visuals. As the user, it’s great. All I care about is the information. I don’t care about what it looks like, just give me the numbers to put on the barbell. Bots are strong when dealing with chunks of digestible information.
  • Conversational logic is a pain to write and think through. Rocky defaults to returning weights in lbs. You can override by asking “my max clean in kg” and he’ll tell you in kilograms. But if you forget, it’s a poor user experience to have the user repeat the whole thing and tack on the “in kg” or “in kilos”. The relatively hardest thing to implement so far was the part of the conversation where Rocky defaulted to giving me the weight in pounds and I asked him for a conversion by casually saying “in kilos”. All of a sudden, I had to keep track of what was said, what state it was in, and make adjustments as needed based on subsequent, even more ambiguous commands. Too bad for me, I did all this before I read Andrew Konoff’s piece on tools for building bots and had to figure it out in the code editor.
  • Natural conversations require work. If you don’t do the work, then all you have is a command prompt, not a chat bot. We humans do a lot of things naturally when conversing with one another in person or online.
    One example is pausing to think, formulate responses, and type. The first time, Rocky responded to everything with lightning speed. It was frankly, very creepy. I then added a 900 millisecond delay where he would show the ‘typing’ indicator before responding as well as show the Messenger “has been read” indicator. Not that you could tell, but later on I expanded the delay to be proportional to the length of the string Rocky sends back. Another thing we humans do, is randomize our vocabulary. After a few tests I got really annoyed with the bot saying the same thing in the same format. So I introduced synonyms for ‘max’ such as ‘best’ and ‘PR’ and randomized between them to break up the monotony. In the future, I also want to randomize sentence structure when possible.

Next Time

The bot works like a dream for me and I’ve used it all week in the gym. Several CrossFit and weightlifting friends saw it in action and want to use it as well. There should be more lessons for me as I adapt him to work for multiple users. Other things I’ll be looking at include writing data to the db using chat prompts, and maybe a first time user flow.

--

--