This is a sample project used for HackMerced Workshop.
In deployment, our server will be on Heroku. However, since we will spend most of our time in development, we will use ngrok to tunnel our localhost instead.
- Config our Node server
- Get the App Secret in Settings tab on
developers.facebook.com - Get
pageAccessTokenfrom Messenger -> Settings - For
validationToken, you can put be whatever you want - For
serverURL, you have to tunnel your localhost. If you have installed ngrok on your computer, typengrok http 3333in the terminal.3333is the default port that you specify in your server. - You can ignore the last field for now.
- Set up webhook
- Go to Product -> Messenger -> Webhooks
- Fill in your ngrok url with the
\webhookroute. Example:https://d9d7d46e.ngrok.io/webhook - Fill in your
validationTokenspecified in step 1 - Subscripe the webhook with a page
Open file basic-receiver.js and start exploring. This is a mini server I created with the code from app.js. Look down to app.post and follow the workshop.
Format of the data Facebook send us
Open file basic-sender.js and copy all the code over basic-receiver.js. The code is from FB and it gives us a really good black box to use. If you want to explore more about sending messages to the bot, check out here.
Adding an AI is complicated because wit.ai and Messenger, although from the same company, their code are a bit different. So, you have to marge them together. For this section, please open basic-ai.js.
More documentation here
- Install heroku and then login
heroku login cdto your git andheroku create- Go on to heroku website, get the url, and change it inside your config file,
default.json - Heroku will use
npm start, so set to script in yourpackage.jsonfile accordingly - Deploy to the server with
git push heroku master
Note: If you want a newer version of Node on Heroku, edit your package.json file
"engines": {
"node": "~4.1.2"
}
Getting Started on Heroku with Node.js
Your messenger bot is still in development. That means, other people other than yourself cannot talk to it. It will not response to anyone other than the admins. You can add more contributors to the App in Settings or you can get it approved for the public here.
If you need help, find me on Facebook or on Slack.
