enterprise-fbm
An example Messenger bot using Condé Nast's launch-vehicle-fbm
. The enterprise-fbm
name is a nod to the first orbiter of the Space Shuttle system. Got to keep the
A fully baked how to blog post can be found on the Condé Nast Engineering Blog and Chatbots Magazine.
Using this example
This is not going to cover setting up a Facebook page and application with the necessary identifiers and secrets. I would recommend reading through the Messenger Platform Quick Start Guide provided by Facebook.
This also assumes that nodemon is installed globally. Feel free to edit the dev scripts in packages.json
to your liking if nodemon is not a part of your preferred development setup.
Clone this repo, enterprise-fbm
, and install the dependencies:
git clone git@github.com:stripethree/enterprise-fbm.git
cd enterprise-fbm
npm i
Copy example.env
to .env
and replace it with the identifiers and secrets for your Facebook page and application. Then export these values into the environment:
export $(cat .env | xargs)
Start up localtunnel, I'd recommend using the subdomain argument:
lt --port 3000 --subdomain <pick a subdomain>
This URL is what will also populate the Callback URL field when configuring the Page Subscription for the application's webhook.
Start up the bot!
npm run dev
Off you go! The example supports responding to greetings (try saying hello) and requests for assistance (try saying help). It will also echo back any other text sent as well as images sent.
Deploying to Heroku
The default configuration set for launch-vehicle-fbm
pulls the application port from process.env.NODE_PORT
. Heroku uses process.env.PORT
and thus, a small change needs to be made to ./config/custom-environment-variables
.
- "port": "NODE_PORT"
+ "port": "PORT"
The default.json
file could also be removed from ./config
if desired.
Here are the necessary commands to get the application created, configured, and started in Heroku. This assumes that the necessary configuration items have been exported to the environment.
heroku create <optional project name>
heroku config:set FACEBOOK_APP_ID=${FACEBOOK_APP_ID} FACEBOOK_PAGE_ID=${FACEBOOK_PAGE_ID} MESSENGER_APP_SECRET=${MESSENGER_APP_SECRET} MESSENGER_PAGE_ACCESS_TOKEN=${MESSENGER_PAGE_ACCESS_TOKEN} MESSENGER_VALIDATION_TOKEN=${MESSENGER_VALIDATION_TOKEN}
git push heroku master