Building an FB Messenger Bot

Alexander Green
Student Voices
Published in
6 min readJan 8, 2017

--

Hi — I’m Alex. I’m going to build some things this year. This month was an FB messenger bot named Patron that would send you NYC bars based on what you wanted: by borough (brooklyn, queens, manhattan), price range( 1 -5 ), or vibe (college bar, chill, date spot, good food). It’s not perfect and a little buggy, but like the awkward middle child it’s mine so I love it anyway.

Here’s how that went.

When the Messenger platform was first announced during the ‘chatbots are the future’ maelstrom last year, I succumbed and built something. Somehow, I hoped, I could be the chosen one in a sea of hodgepodge products and make something that could get me paid.

Build something people want!

Solve a problem that no one else recognizes is a huge deal!

In the end, I created a bot that echoed whatever you sent it and told you the weather. Not exactly the revolution that girdled the people’s loins, but it turns out the whole industry felt the same way. The bot movement dwindled down as people realized they didn’t need to interact with something that a simple Google search could do. As for me, I barely use Facebook and bots wouldn’t give me a reason to start. Plus I couldn’t imagine how often consumers would really be interacting with a bot. The only functionality I thought would be cool is in-message purchasing, and while you can buy products through Messenger, I can’t imagine very many people that would.

On the other hand, at my previous company(@countit) we built a Slack bot that worked with our B2B SaaS, and I could immediately see the use of it there. Instead of having people interact with our UI, we could have them just ping the bot to get the same information boiled down to the essentials. If you needed more just hit the link in each attachment and jump over to the main site. Functionality boiled down to the essentials. As the Slack Fund and the new waves of Slack Apps coming up now goes to show, there’s a little more power in building services that teams can utilize.

But I still thought about building some kind of bot.

Working in Product Marketing these days means that my amateur hour coding skills have diminished, so I decided to jump back in and build some things. The three ideas that jumped to my mind were a Slack bot, an FB Messenger Bot, an Alexa Skill. Last, and most important for me because I thought it’d be cool— a collaboration, approval, request tool for video/photo/design similar to Slope.

To start with the low hanging fruit, I wanted to make an FB Messenger bot that did one thing. My first idea was a music recommendation bot through Soundcloud’s API, but I discovered you couldn’t play songs in Messenger unless they were hosted in a directory. So I looked at other options. I really loved Goldbot, the chatbot twin of LA Times food critic Jonathan Gold. Ask it food recommendations (by price, flavor, neighborhood, etc.), and it would send you food recommendations. Awesome.

So I decided to do bar recommendations in the NYC area. Sounds similar to Goldbot, maybe? Well the keyword here is inspiration.

Here’s the finished product in action:

Neat, right?

This was built with Botkit by Howdy.ai, a framework for building bots that makes building out a Slack or Messenger bot a little bit simpler.

Here, it takes care of subscribing to webhooks and handling responses to messages sent from Facebook (specifically the text of the message, ID of the user, timestamps, etc.). Inside the facebook_handler it does a little magic like creating unique users for your database, so all you need to worry about is how to process that message.

Don’t call me a poser yet — like most frameworks, it just streamlines the boilerplate work you would’ve needed to do. Shout out to the boys and girls at Howdy for making this happen.

Here’s a peek under the hood on the Conversations side.

So when a user says a borough, we take it and search for a random bar in the database that is attached to that borough. Then we attach that to a message as an attachment and send it back out. In the future I’d want to specify this to neighborhoods so it’s a little bit tighter, but we’re just doing concepts here.

Here’s what the schema looks like:

Like I said, nothing too fancy. Direction URLs I got from Google Maps, and image urls were placed into a S3 bucket. Inside the Developer console on Facebook, you get your App ID and link it with a Facebook Page ID. So you can use this Messenger application on as many Pages as you’d like.

And that’s that.

So building this bot with a concentrated purpose made me realize something — while these types of bots may never be extremely successful until/if Facebook hits a WeChat level of complete global saturation, it’s a cool concept that can be truly useful with voice assistants like Alexa. Having one in my house over the last month I see the power that a voice UI can accomplish. The future is definitely voice assistants that can use other ‘bots’ as microservices that don’t live in Amazon’s services or easily accessible through a Google Search.

At CES there was another voice assistant announced — Aristotle, a voice assistant geared for young children, built into a physical unit. Part teacher, part watch dog, and part baby monitor, with enough access guard rails around it that parents feel safe. While the battle for the home and the car may have been lost in the big picture, smaller, target market voice assistants that use Alexa software may be the future we can attain. How about a voice assistant that lives in a physical office, or a voice assistant in a box delivered to members of a distributed team, keeping everyone on track?

This ties into the next project I wanted to work on — an Alexa skill that does one interesting thing. Maybe it’ll be bars again because it’s simple, or maybe it’ll be reporting on stock prices. I’m excited to give it a go.

Peep the Github below. And here’s to all the better developers out there to make this better. For any bar review sites/restaurant review sites that want to build a serious version of this, feel free to hit me up at adgreen93@gmail.com.

--

--