This is a simple example of how to get a bot running on a Facebook page.
git clone https://github.com/fczuardi/fbbotexample.git
cd fbbotexample
npm install
Click the link to create a Facebook Page, choose a page type and click "Get Started".
Click a bunch of "Skip"s.
Click the link to create a Facebook App, then click "Skip and Create App", and fill the form to get an App ID and procede to the dashboard page:
On the Dashboard page of your FB App, add the "Messenger" product:
Click Settings, select the page and generate a page token
Edit the sample code file: paste your page token and type a random string as the verification token.
const myPageToken = 'PASTE_YOUR_PAGE_TOKEN_HERE';
const myVerifyToken = 'TYPE_ANY_RANDOM_STRING_HERE';
const myCallbackPath = '/webhook';
const myPort = 9091;
You can generate a random string in the command line with:
openssl rand -base64 36
Launch your server:
node index.js
If you dont have it, download ngrok.
On a different terminal launch ngrok to tunnel the port your bot is running to a public HTTPS url:
ngrok http 9091
(your ngrok syntax may vary, this example uses version 2.0.25)
This will give you an https URL, to be used in the next step.
On the dashboard page of you facebook app click "Setup Webhooks":
Use the https url from ngrok with the callback path and the random string verify token to fill the form. Check all checkboxes:
Open your page and send a message to it. If you follow all steps you should have an echo bot running.