Home

Awesome

fb-vision-bot

Facebook Messenger Bot that consumes Google Cloud Vision API and provides insights on images.

You can try it out on the following Facebook Page, and start by saying Hi to it.

@TODO: This bot will integrate the NLP platform Api.ai with Facebook Messenger to provide a richer and smarter user experience.

Features of Google Cloud Vision API are the following:

First, check out the Quickstart Guide provided by Facebook.

Second, mkdir config and add a default.json inside config with the following contents:

{
  "herokuBaseUrl": "YOUR HEROKU URL WITH TRAILING SLASH (Leave it as empty string if not used)",
  "ngrokBaseUrl": "YOUR NGROK URL WITH TRAILING SLASH (Leave it as empty string if not used)",
  "projectID": "YOUR GOOGLE CLOUD PROJECT ID",
  "pageID": "YOUR PAGE ID",
  "validationToken": "YOUR OWN TOKEN" (by default, "just_do_it")
  "appSecret": "YOUR APP SECRET",
  "pageAccessToken": "YOUR PAGEACCESS TOKEN",
  "validationToken": "YOUR VALIDATION TOKEN"
}

Third, since you have to install node-canvas for image processing, follow the instructions from here: Node-canvas

Fourth, then enable Google Cloud Vision and get your API credentials by following their guide. Name the credentials file as 'fb-vision-bot-credentials.json' and place it in the project file.

Finally, if you are on Windows, JPEG support doesn't work correctly with node-canvas. Therefore you have to use ImageMagick to manually convert .jpg to .png. Follow the instructions of this: EasyImage

Running Locally or on AWS

  1. Install Node.js, NPM, and ngrok (or localtunnel)
  2. Run "sudo npm install" command to install external modules locally
  3. Run "node app.js" to run the app
  4. Enter localhost:8080 on the web url to check (All static files are served in the 'public' folder)
  5. Enter ngrok http 8080 to tunnel a connection from https://foo.ngrok.io to localhost
  6. Give https://foo.ngrok.io/webhook for your webhook verificaiton URL in the Messenger App settings
  7. Now for every message, you can check the response and request through your console.
  8. In order to add the persistent menu function for your messenger, please run the following command:
INIT=true node threads.js

Running on Heroku

  1. Do steps 0~1 from above and install Heroku toolbelt from the Heroku website
  2. Run "heroku login"
  3. If existing repository, simply add a remote to heroku with this command: heroku git:remote -a YOUR_HEROKU_APP
  4. Else, run the following codes
  1. Give https://yourheroku.herokuapp.com/webhook for your webhook verificaiton URL in the Messenger App settings
  2. Voila :)
  3. Alternatively, you can connect your herokuapp to GitHub, and set it to automatically deploy whenever a commit is made. p.s. Add the following url to the buildpack lists on heroku : https://github.com/mojodna/heroku-buildpack-cairo.git

Or you can simply click

@TODO: (Will add deploy to heroku button here later)