-
-
Notifications
You must be signed in to change notification settings - Fork 193
Facebook Receiver node
Facebook API talks to Red-Bot via a https callback (a self signed certificate is not enough). We'll use ngrok to create a https tunnel for our local Node-RED instance. Install it, then open a shell window and run
ngrok http 127.0.0.1:1880
You should get something like
Grab the https address you get, something like https://123123.ngrok.io, this is the base url that points back to your Node-RED instance.
The callback is
http://youraddress.ngrok.io/redbot/facebook
Replace the hostname (youraddress.ngrok.io) with what you got above. Start here to create a new Facebook app
Then click on "get started with Messenger". Your Facebook app must be connected to a Facebook page, select one from the drop down menu (or create one if you don’t have any) and confirm, that will create a new access token
Copy this value as well as the app secret that you find in the "dashboard" section. Don’t close this page yet and open Node-Red.
Add a new Facebook Receiver Node
, then open the configuration of the node and fill up form with the access token and app secret you got before, then give a name to this configuration for your convenience and specify the verify token: this is an arbitrary string, you can put here whatever you like, just remember it you'll need in the next step.
Save your node and switch back to the Facebook App configuration page, click on "Setup webhooks"
Copy the callback url you got before and the arbitrary verify token you put in Node-RED, don't forget to check "messages" or your chat bot will not be notified of new messages. Click on "Verify and Save", if you don't get any error means Facebook is able to contact your Node-RED instance and everything is ok (you should also be able to see a GET call in ngrok).
If you get an error means that you have used wrong parameters (access token, app secret, etc) or, for some reason, Facebook APIs cannot reach the your callback url.
To exclude the second option and be sure that your Node-RED instance works correctly, grab your ngrok url and open this address
http://youraddress.ngrok.io/redbot/facebook/test
If you get an "ok" then Node-RED is up and running.
In order test if it works: connect a Debug Node
to the Facebook Receiver Node
, then open the Facebook page selected before (when the access token was generated), click on the "Message" button and type something, then check the console.
Facebook Receiver
and Facebook Sender
have a double bot configuration for development and production. By default is used the development configuration. To use production configuration, edit Node-RED settings file (settings.js) and set the environment global variable to "production". See here for more details.