In this lab, we're going to work with faraday to make some API calls and create a Facebook Messenger bot!

Getting started

This lab has a few different parts. Start out by cloning our starter project with the command below:

whales new bot rails-decal/messenger-bot

This app has no visual interface and, frankly, no functionality! But it has the Faraday gem installed to help us make requests and it has the routes ready for us to create our messenger bot!

Some context

Briefly, let's review how the Facebook Messenger bot works. When someone sends a message to the bot, Facebook will send our server a POST request with the message they sent! The POST request will have a lot of parameters, but the ones we care about are the message itself as well as the conversationID.

Our Rails server starts by receiving a webhook (which is just a request) from Facebook, and then sends an API call to reply with a message.

Our Rails server starts by receiving a webhook (which is just a request) from Facebook, and then sends an API call to reply with a message.

If we want to respond to the user, we send a POST request to a Facebook API URL with the message we want to send back and the conversationID of the conversation we wanted to respond to.

Aside: Why have a conversationID? Remember that this messenger bot could have multiple conversations going on!

Now you

Great! Now once you've started up your whales server with whales server check out the guides below in order.

Getting started with your Facebook bot

Sending messages from your bot

Making your bot do something useful