FB Messenger Platform Setup
development
environment
Steps for 1. Create a Facebook App and Page
Create a new Facebook App and Page or use existing ones. Go to the App Dashboard and under Product Settings click Add Product
and select Messenger.
2. Token Generation
In the Token Generation section, select your Page. A Page Access Token will be generated for you. Copy this Page Access Token. Note: The generated token will NOT be saved in this UI. Each time you select that Page a new token will be generated. However, any previous tokens created will continue to function.
3. Webhook
Find Webhook
section then click on Setup Webhooks
Enter a URL for a webhook, enter a Verify Token and select messages
and messaging_postbacks
under Subscription Fields
.
Callback URL
should be your server https://myserver.com/webhook
or you can also use ngrok that tunnel your node from your machine.
When verify FB request will enter line app.get('/webhook'
in app.js
Verify Token
can be anything unique, this will be used in default.json
validationToken
in Setup your bot
section below
production
environment
Steps for 4. App Review for Messenger
To use Messenger platform in publicly
, your app needs to be approved for Send/Receive API (pages_messaging). The Send/Receive API should only be used to send organic content and should not be used to send marketing or other promotional communications.
Setup your bot
config/default.json
1. Modify your {
"appSecret": "From your App dashboard",
"pageAccessToken": "Generated from step #2",
"validationToken": "someuniquetext that will be used in step #3",
"serverURL": "your server url"
}
APP_ID
and PAGE_ID
in public/index.html
.
2. Replace values for APP_ID
you can get from developers.facebook.com dashboard
PAGE_ID
you can get from the URL of your page,
example https://www.facebook.com/DigithunDev-407027276326992/
this means the PAGE_ID
is 407027276326992
3. Run the bot server !
Legacy server
$ npm i
$ npm start
Docker
docker build -t fbmsgrbot .
docker run -it -d -p 5000:5000 --name fbmsgrbot fbmsgrbot
Or just use:
. run.sh
Testing when FB has not yet approved
Assumed that you already added your Webhook
at developers dashboard
and Setup your bot
You must add a Tester FB account as Admin to the FB Page used for generate pageAccessToken
, so that the bot will have permission to send messages.
Message types such as images must be added in section 3. Webhook
to allow bot to send images.
To hotlink chat with your bot. You can type in your server url in the browser which will go to public/index.html
this page has message-us
button, which will enter FB page chat window.