Jumping on the Chatbot Train

How I learned to code a Facebook Messenger chatbot in under a month.

Nick Braver
Decisions Among Friends

--

In the beginning, there was a dream. This dream included the future of design, and Jerry Wang’s 15 Minute Bot Tutorial.

Hannah and I started with an idea for a bot that would help you decide where to eat. To read about the rest of our journey, check it out in our publication, Decisions among Friends.

Once we had an idea to work from, I decided it was a good time to take a break from designing and try actually building a product. I am currently a product designer, but I’ve never shipped something outside of my 9-to-5. So this was a step in the right direction.

I began by doing research on how to get started building a chatbot. This research included finding Jerry Wang’s tutorial. This was a great starting point for us to get familiar with how chatbots are set up to talk to Facebook Messenger. Next, we needed to find a processor to tell the bot what was being said from a human.

The Wit Experience.

Hannah had us using Wit.ai for our Natural-Language Processor (NLP). Which was fine, at first. After quite a few failed attempts, though, all I was getting our chatbot to say was an echo of whatever our user had said before.

To be fair, the bot was doing alright in Wit’s testing environment. But getting it integrated with Facebook Messenger just wasn’t working. It was like I had hit a wall with this echo thing.

So, we both went off and did some research. We were looking primarily at Facebook Messenger integration and what to do about form-based bots when we discovered Api.ai. We decided to try it out.

To learn more about why we switched from Wit.ai to Api.ai, check out Hannah’s article: ‘When Beta is Just Too Beta.’

That Api.ai Life.

Once we switched, I discovered Api.ai’s weather tutorial and things were fairly uphill from there.

Not only does Api.ai practically automate the entire Facebook Messenger integration process, but they also show you step-by-step how to get another API to talk to Messenger. Great for me, because we needed to hook into the Google Places API. It was like the training wheels I needed all along, as a designer trying to develop a product.

I started with Node.js because Wit.ai had an integration with Node. That was fine, but Api.ai’s webhook tutorial for Python was better.

So, part of this meant switching to Python.

Why? Well, I realized that I could use it in tandem with Slimkrazy’s Google Places API Framework developed with Python. After skimming through his git documentation, I knew that this would be the fastest way to get up and running.

All I had to do was install the Python wrapper into the Heroku server and the party had officially started!

‘The Party’

I did have to make my own variables for calling the data we needed from Google… but that’s just part of frankensteining things together.

I looked at a lot of random Python tutorials for that. But the biggest problem I faced was just because I’m not a developer by trade…

Looking for Problems in All the Wrong Places

We got pretty far. The bot seemed to be working. But then, it wasn’t. And we had no idea why. I went through the code backwards and forwards. We started blaming Api.ai and Heroku. But I had forgotten.

With Python?
Tabbing counts. A lot.

Honestly, I was just looking for the problem in all the wrong places.

Do you see it?

Hint: It’s the ‘if’ statement on line 36.

I didn’t see it either — at first.

In desperation, I had my code up next to the code from Api.ai’s weather tutorial. And then I saw it. One single tab was off. Sounds crazy, but there it was. Staring me down, and laughing.

Problem solved, though, for now?

I have to say — props to all of the developers out there. I always respected programmers, but now that respect has grown to a whole new level. Coding is harder than I thought. It takes patience, dedication, and the power of looking in all of the right places.

--

--